예제 #1
0
 //удаление взаимосвязи совпадение
 public void RemoveCoincident()
 {
     swDoc.Extension.SelectByID2("Неизвестный", "MANIPULATOR", 0.00086662543327636898, -0.0046220023108073105, 0, false, 0, null, 0);
     swDoc.EditDelete();
     swDoc.SketchConstraintsDel(1, "sgCOINCIDENT");
     swDoc.Extension.SelectByID2("Неизвестный", "MANIPULATOR", 0.00086662543327636898, -0.0046220023108073105, 0, false, 0, null, 0);
     swDoc.EditDelete();
     swDoc.SketchConstraintsDel(1, "sgCOINCIDENT");
 }
 public void DeleteTable()
 {
     try
     {
         _swModel.Extension.SelectByID2("", "ANNOTATIONTABLES", 0, 0, 0, false, 0, null, 0);
         _swModel.EditDelete();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #3
0
        public void DeleteBom()
        {
            SldWorks  swapp   = default(SldWorks);
            ModelDoc2 swmodel = default(ModelDoc2);

            swapp   = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            swmodel = swapp.ActiveDoc;
            Feature swFeat = swmodel.FirstFeature();

            while ((swFeat != null))
            {
                if (swFeat.GetTypeName() == "BomFeat")
                {
                    swFeat.Select(true);
                    swmodel.EditDelete();
                    swFeat = swmodel.FirstFeature();
                }
                swFeat = swFeat.GetNextFeature();
            }
        }
예제 #4
0
        /// <summary>
        /// Returns Lists of Custom_parts and Standard_Parts
        /// </summary>
        /// <param name="swModel"></param>
        /// <param name="swTableAnn"></param>
        /// <param name="ConfigName"></param>
        /// <param name="Standard_Parts"></param>
        /// <param name="Custom_Parts"></param>
        public static void Get_Sorted_Part_Data(ModelDoc2 swModel, BomFeature swBomFeat, List <BOM_Part_Informations> Standard_Parts, List <BOM_Part_Informations> Custom_Parts, string projectpath)
        {
            try
            {
                int nNumRow              = 0;
                int J                    = 0;
                int I                    = 0;
                int numStandard_Part     = 1;
                int numCustom_Part       = 1;
                int quantity             = 0;
                int index_description    = 0;
                int index_article_number = 0;
                int index_supplier       = 0;


                BOM_Part_Informations part_informations;



                string ItemNumber = null;
                string PartNumber = null;

                // Debug.Print("   Table Title        " + swTableAnn.Title);
                Feature  swFeat       = default(Feature);
                object[] vTableArr    = null;
                object   vTable       = null;
                string[] vConfigArray = null;
                object   vConfig      = null;
                string   ConfigName   = null;
                string   partconfig   = null;

                TableAnnotation swTable      = default(TableAnnotation);
                Annotation      swAnnotation = default(Annotation);
                object          visibility   = null;


                swFeat    = swBomFeat.GetFeature();
                vTableArr = (object[])swBomFeat.GetTableAnnotations();

                foreach (TableAnnotation vTable_loopVariable in vTableArr)
                {
                    vTable       = vTable_loopVariable;
                    swTable      = (TableAnnotation)vTable;
                    vConfigArray = (string[])swBomFeat.GetConfigurations(true, ref visibility);

                    foreach (object vConfig_loopVariable in vConfigArray)
                    {
                        vConfig    = vConfig_loopVariable;
                        ConfigName = (string)vConfig;



                        //    MessageBox.Show(ConfigName);


                        // swTable.SaveAsPDF(@"C:\Users\alex\Desktop\test.pdf");



                        nNumRow = swTable.RowCount;

                        BomTableAnnotation swBOMTableAnn = default(BomTableAnnotation);
                        swBOMTableAnn = (BomTableAnnotation)swTable;
                        //swTable.GetColumnTitle
                        for (int h = 0; h < swTable.ColumnCount; h++)
                        {
                            switch (swTable.GetColumnTitle(h))
                            {
                            case "Benennung":
                                index_description = h;
                                break;

                            case "Artikelnummer":
                                index_article_number = h;
                                break;

                            case "Lieferant":
                                index_supplier = h;
                                break;

                            default:
                                break;
                            }
                        }
                        if (index_supplier != 0 || index_supplier != 0 || index_article_number != 0) //Standard BOM Template
                        {
                            for (int n = 0; n <= nNumRow - 1; n++)
                            {
                                // Debug.Print("   Row Number " + J + " Component Count  : " + swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber));
                                //  Debug.Print("       Item Number  : " + ItemNumber);
                                // Debug.Print("       Part Number  : " + PartNumber);
                                // MessageBox.Show("bubu");
                                object[]   vPtArr = null;
                                Component2 swComp = null;
                                object     pt     = null;
                                quantity = swBOMTableAnn.GetComponentsCount2(n, ConfigName, out ItemNumber, out PartNumber);

                                vPtArr = (object[])swBOMTableAnn.GetComponents2(n, ConfigName);

                                if (((vPtArr != null)))
                                {
                                    for (I = 0; I <= vPtArr.GetUpperBound(0); I++)
                                    {
                                        pt     = vPtArr[I];
                                        swComp = (Component2)pt;
                                        if ((swComp != null))
                                        {
                                            part_informations = new BOM_Part_Informations();

                                            part_informations.manufacturer = swTable.get_Text(n, index_supplier);
                                            part_informations.order_number = swTable.get_Text(n, index_article_number);
                                            part_informations.IsAssembly   = false;

                                            part_informations.part_number = PartNumber.TrimStart();
                                            part_informations.quantity    = quantity.ToString();

                                            //Custom part
                                            if (swComp.GetPathName().Contains(projectpath))
                                            {
                                                if (swComp.GetPathName().Contains(".sldasm") || swComp.GetPathName().Contains(".SLDASM"))
                                                {
                                                    // MessageBox.Show(swComp.GetPathName());
                                                    part_informations.IsAssembly = true;
                                                }

                                                part_informations.description = swComp.ReferencedConfiguration;
                                                part_informations.item_number = numCustom_Part.ToString();
                                                numCustom_Part++;

                                                Custom_Parts.Add(part_informations);
                                                break;
                                            }

                                            part_informations.description = swTable.get_Text(n, index_description);
                                            part_informations.item_number = numStandard_Part.ToString();
                                            numStandard_Part++;
                                            Standard_Parts.Add(part_informations);
                                            break;
                                        }
                                        else
                                        {
                                            Debug.Print("  Could not get component.");
                                        }
                                    }
                                }
                            }
                        }
                        else //No Standard BOM Template
                        {
                            for (J = 0; J <= nNumRow - 1; J++)
                            {
                                // Debug.Print("   Row Number " + J + " Component Count  : " + swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber));
                                //  Debug.Print("       Item Number  : " + ItemNumber);
                                // Debug.Print("       Part Number  : " + PartNumber);

                                object[]   vPtArr = null;
                                Component2 swComp = null;
                                object     pt     = null;
                                quantity = swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber);

                                vPtArr = (object[])swBOMTableAnn.GetComponents2(J, ConfigName);

                                if (((vPtArr != null)))
                                {
                                    for (I = 0; I <= vPtArr.GetUpperBound(0); I++)
                                    {
                                        pt     = vPtArr[I];
                                        swComp = (Component2)pt;
                                        if ((swComp != null))
                                        {
                                            part_informations = new BOM_Part_Informations();

                                            part_informations.description = swComp.ReferencedConfiguration;
                                            part_informations.part_number = PartNumber;
                                            part_informations.quantity    = quantity.ToString();
                                            //Custom part
                                            if (swComp.GetPathName().Contains(projectpath))
                                            {
                                                if (swComp.GetPathName().Contains(".sldasm") || swComp.GetPathName().Contains(".SLDASM"))
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    part_informations.item_number = numCustom_Part.ToString();
                                                    numCustom_Part++;

                                                    Custom_Parts.Add(part_informations);
                                                    break;
                                                }
                                            }

                                            part_informations.item_number = numStandard_Part.ToString();
                                            numStandard_Part++;
                                            Standard_Parts.Add(part_informations);
                                            break;
                                        }
                                        else
                                        {
                                            Debug.Print("  Could not get component.");
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                swAnnotation = swTable.GetAnnotation();
                swAnnotation.Select3(false, null);
                swModel.EditDelete();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
예제 #5
0
        public void Build(Vector3 frameSize, int profileType, ServiceSide serviceSide)
        {
            string caseAssemblyPath = Path.Combine(RootFolder, SourceFolder, modelName);

            Patterns.Observer.MessageObserver.Instance.SetMessage("\n" + caseAssemblyPath + "\n");
            ModelDoc2 SolidWorksDocument = SolidWorksAdapter.OpenDocument(caseAssemblyPath, swDocumentTypes_e.swDocASSEMBLY);// SolidWorksDocumentumentTypes_e.SolidWorksDocumentASSEMBLY);

            Patterns.Observer.MessageObserver.Instance.SetMessage("открылась сборка");
            //AssemblyDocument = SolidWorksAdapter.ToAssemblyDocument( SolidWorksDocument);
            double rivetL;
            string newName     = "01-P150-45-" + (frameSize.Z - 140);
            string newPartPath = GetFrameCasePath(newName);


            if (File.Exists(new FileInfo(newPartPath).FullName))
            {
                SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(modelName);
                SolidWorksDocument.Extension.SelectByID2("01-P150-45-1640-27@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                AssemblyDocument.ReplaceComponents(newPartPath, "", true, true);
                SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("01-P150-45-1640.SLDPRT");
            }
            else if (File.Exists(newPartPath) != true) // TO DO delegate
            {
                rivetL = (Math.Truncate((frameSize.Z - 170) / step) + 1) * 1000;
                parameters.Add("D1@Вытянуть1", frameSize.Z - 140);
                parameters.Add("D1@Кривая1", rivetL);
                EditPartParameters("01-P150-45-1640", newPartPath, 0);

                //frameSize.X

                newName     = "01-P150-45-" + (frameSize.X - 140);
                newPartPath = GetFrameCasePath(newName);
                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(modelName);
                    SolidWorksDocument.Extension.SelectByID2("01-003-50-22@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    AssemblyDocument.ReplaceComponents(newPartPath, "", true, true);
                    SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("01-003-50.SLDPRT");
                }
                else
                {
                    rivetL = (Math.Truncate((frameSize.X - 170) / step) + 1) * 1000;
                    parameters.Add("D1@Вытянуть1", frameSize.X - 140);
                    parameters.Add("D1@Кривая1", rivetL);
                    EditPartParameters("01-P150-45-1640", newPartPath, 0);
                }

                //01-P252-45-770
                newName     = "01-P252-45-" + (frameSize.X - 100);
                newPartPath = newPartPath = GetFrameCasePath(newName);
                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(modelName);
                    SolidWorksDocument.Extension.SelectByID2("01-P252-45-770-6@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    AssemblyDocument.ReplaceComponents(newPartPath, "", true, true);
                    SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("01-P252-45-770.SLDPRT");
                }
                else
                {
                    parameters.Add("D1@Вытянуть1", frameSize.X - 100);
                    EditPartParameters("01-P150-45-1640", newPartPath, 0);
                }

                //frameSize.Y

                newName     = "01-P150-45-" + (frameSize.Y - 140);
                newPartPath = newPartPath = GetFrameCasePath(newName);
                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(modelName);
                    SolidWorksDocument.Extension.SelectByID2("01-P150-45-510-23@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    AssemblyDocument.ReplaceComponents(newPartPath, "", true, true);
                    SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("01-P150-45-510.SLDPRT");
                }
                else
                {
                    rivetL = (Math.Truncate((frameSize.Y - 170) / step) + 1) * 1000;

                    parameters.Add("D1@Вытянуть1", (frameSize.Y - 140));
                    parameters.Add("D1@Кривая1", rivetL);
                    EditPartParameters("01-P150-45-1640", newPartPath, 0);
                }

                //  01-P252-45-550
                newName     = "01-P252-45-" + (frameSize.Y - 100);
                newPartPath = newPartPath = GetFrameCasePath(newName);
                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(modelName);
                    SolidWorksDocument.Extension.SelectByID2("01-P252-45-550-10@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    AssemblyDocument.ReplaceComponents(newPartPath, "", true, true);
                    SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("01-P252-45-550.SLDPRT");
                }
                else
                {
                    parameters.Add("D1@Вытянуть1", frameSize.Y - 100);
                    EditPartParameters("01-P252-45-550", newPartPath, 0);
                }

                SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(modelName);
                SolidWorksDocument.EditRebuild3();
                SolidWorksDocument.ForceRebuild3(true);
                //   AssemblyDocument = (AssemblyDoc)SolidWorksDocument;

                if (serviceSide == ServiceSide.Left)
                {
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-1@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-6@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-7@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-10@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-4@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-12@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-12@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    SolidWorksDocument.EditDelete();
                }
                else if (serviceSide == ServiceSide.Right)
                {
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-16@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-21@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-22@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-17@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("Threaded Rivets с насечкой-23@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-18@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    SolidWorksDocument.Extension.SelectByID2("M8-Panel block-one side-18@" + modelName.Replace(".SLDASM", ""), "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    SolidWorksDocument.EditDelete();
                }
            }
        }
        public void CreateHeaterCenter(string heaterPathName)
        {
            ISketchPoint       startPoint = null;
            ISketchPoint       endPoint   = null;
            List <SegmentData> list       = new List <SegmentData>();
            List <SegmentData> list2      = new List <SegmentData>();
            List <SegmentData> list3      = new List <SegmentData>();
            List <SegmentData> list4      = new List <SegmentData>();

            _swApp.ActivateDoc(_swPartModel.GetTitle());
            _swPartModel.ShowNamedView2("*Front", 1);

            ISketchArc arc;
            double     length;

            list2.Clear();
            list.Clear();
            _swPartModel.Extension.SelectByID2(heaterPathName, "SKETCH", 0.0, 0.0, 0.0, true, 0, null, 0);
            _swPartModel.ViewZoomToSelection();
            ISelectionMgr iSelectionManager = _swPartModel.ISelectionManager;

            IFeature feature = iSelectionManager.GetSelectedObject6(1, 0);

            ISketch sketch = feature.GetSpecificFeature2();

            Array array = sketch.GetSketchSegments();

            Array array2 = sketch.GetSketchPoints2();

            foreach (ISketchSegment segment in array)
            {
                ISketchSegment segment2 = segment;
                segment2.Select(true);
                if (!segment2.ConstructionGeometry)
                {
                    if (segment2.GetType() == 0)
                    {
                        ISketchLine line = (ISketchLine)segment2;
                        startPoint = line.IGetStartPoint2();
                        endPoint   = line.IGetEndPoint2();
                    }
                    if (segment2.GetType() == 1)
                    {
                        arc        = (ISketchArc)segment2;
                        startPoint = arc.IGetStartPoint2();
                        endPoint   = arc.IGetEndPoint2();
                    }
                    SegmentData item = new SegmentData(segment2, startPoint, endPoint);
                    list.Add(item);
                }
                _swPartModel.ClearSelection2(true);
            }
            for (int i = 0; i < list.Count; i++)
            {
                int num9 = 0;
                list2.Add(list[0]);
                list.Remove(list[0]);
                for (int m = 0; m < list.Count; m++)
                {
                    list2[0].Segment.Select(false);
                    list[m].Segment.Select(false);
                    if ((Math.Round(list2[0].StartPoint.X, 5) == Math.Round(list[m].StartPoint.X, 5)) && (Math.Round(list2[0].StartPoint.Y, 5) == Math.Round(list[m].StartPoint.Y, 5)))
                    {
                        num9++;
                    }
                    if ((Math.Round(list2[0].EndPoint.X, 5) == Math.Round(list[m].EndPoint.X, 5)) && (Math.Round(list2[0].EndPoint.Y, 5) == Math.Round(list[m].EndPoint.Y, 5)))
                    {
                        num9++;
                    }
                    if ((Math.Round(list2[0].EndPoint.X, 5) == Math.Round(list[m].StartPoint.X, 5)) && (Math.Round(list2[0].EndPoint.Y, 5) == Math.Round(list[m].StartPoint.Y, 5)))
                    {
                        num9++;
                    }
                    if ((Math.Round(list2[0].StartPoint.X, 5) == Math.Round(list[m].EndPoint.X, 5)) && (Math.Round(list2[0].StartPoint.Y, 5) == Math.Round(list[m].EndPoint.Y, 5)))
                    {
                        num9++;
                    }
                    _swPartModel.ClearSelection2(true);
                    if (num9 == 2)
                    {
                        list.Add(list2[0]);
                        list2.Remove(list2[0]);
                        break;
                    }
                }
                if (num9 == 1)
                {
                    list2[0].Segment.Select(true);
                    break;
                }
            }
            int num = 0;

            for (int j = 0; j < list.Count; j++)
            {
                list2[num].Segment.Select(true);
                list[j].Segment.Select(false);
                if ((Math.Round(list2[num].StartPoint.X, 5) == Math.Round(list[j].StartPoint.X, 5)) && (Math.Round(list2[num].StartPoint.Y, 5) == Math.Round(list[j].StartPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
                else if ((Math.Round(list2[num].EndPoint.X, 5) == Math.Round(list[j].EndPoint.X, 5)) && (Math.Round(list2[num].EndPoint.Y, 5) == Math.Round(list[j].EndPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
                else if ((Math.Round(list2[num].EndPoint.X, 5) == Math.Round(list[j].StartPoint.X, 5)) && (Math.Round(list2[num].EndPoint.Y, 5) == Math.Round(list[j].StartPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
                else if ((Math.Round(list2[num].StartPoint.X, 5) == Math.Round(list[j].EndPoint.X, 5)) && (Math.Round(list2[num].StartPoint.Y, 5) == Math.Round(list[j].EndPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
            }
            _swPartModel.ClearSelection();
            _swPartModel.Extension.SelectByID2(heaterPathName, "SKETCH", 0.0, 0.0, 0.0, false, 0, null, 0);
            _swPartModel.EditSketch();
            foreach (ISketchPoint point3 in array2)
            {
                point3.Select(false);
                if (point3.Type == 1)
                {
                    _swPartModel.EditDelete();
                }
            }
            double num2 = 0.0;

            foreach (SegmentData data2 in list2)
            {
                data2.Segment.Select(false);
                length = data2.Segment.GetLength();
                num2  += length;
            }
            _swPartModel.ClearSelection();
            double num4 = num2 / 2.0;

            length = 0.0;
            int    num5 = 0;
            double num6 = 0.0;

            for (int k = 0; k < list2.Count; k++)
            {
                list2[k].Segment.Select(false);
                length += list2[k].Segment.GetLength();
                if (num4 < length)
                {
                    num5 = k;
                    double num7 = Math.Abs((double)(length - num4));
                    num6 = (list2[num5].Segment.GetLength() - num7) / list2[num5].Segment.GetLength();
                    break;
                }
            }
            _swPartModel.ClearSelection();
            if (list2[num5].Segment.GetType() == 0)
            {
                double num13 = 0.0;
                double x     = list2[num5].StartPoint.X;
                double y     = list2[num5].StartPoint.Y;
                double num16 = list2[num5].EndPoint.X;
                double num17 = list2[num5].EndPoint.Y;
                if ((Math.Round(num16, 6) == Math.Round(list2[num5 - 1].StartPoint.X, 6)) && (Math.Round(num17, 6) == Math.Round(list2[num5 - 1].StartPoint.Y, 6)))
                {
                    num16 = list2[num5].StartPoint.X;
                    num17 = list2[num5].StartPoint.Y;
                    x     = list2[num5].EndPoint.X;
                    y     = list2[num5].EndPoint.Y;
                }
                else if ((Math.Round(num16, 6) == Math.Round(list2[num5 - 1].EndPoint.X, 6)) && (Math.Round(num17, 6) == Math.Round(list2[num5 - 1].EndPoint.Y, 6)))
                {
                    num16 = list2[num5].StartPoint.X;
                    num17 = list2[num5].StartPoint.Y;
                    x     = list2[num5].EndPoint.X;
                    y     = list2[num5].EndPoint.Y;
                }
                double pointX = x + ((num16 - x) * num6);
                double pointY = y + ((num17 - y) * num6);
                _swPartModel.SetAddToDB(true);
                if (_swPartModel.CreatePoint2(pointX, pointY, 0.0) != null)
                {
                    _swPartModel.SketchAddConstraints("sgFixed");
                }
                if (x == num16)
                {
                    num13 = 1.5707963267948966;
                }
                if (y == num17)
                {
                    num13 = 3.1415926535897931;
                }
                if ((x != num16) && !(y == num17))
                {
                    num13 = Math.Atan((num17 - y) / (num16 - x));
                }
                if (num13 > 3.1415926535897931)
                {
                    num13 -= 3.1415926535897931;
                }
                ISketchSegment segment3 = _swPartModel.ICreateLine2(pointX + (0.005 * Math.Cos(num13 + 1.5707963267948966)), pointY + (0.005 * Math.Sin(num13 + 1.5707963267948966)), 0.0, pointX + (0.005 * Math.Cos(num13 + 4.71238898038469)), pointY + (0.005 * Math.Sin(num13 + 4.71238898038469)), 0.0);
                _swPartModel.SketchAddConstraints("sgFIXED");
                segment3.ConstructionGeometry = true;
                _swPartModel.SetAddToDB(false);
                _swPartModel.ClearSelection2(true);
                _swPartModel.InsertSketch2(true);
            }
            if (list2[num5].Segment.GetType() == 1)
            {
                arc        = (ISketchArc)list2[num5].Segment;
                startPoint = arc.IGetStartPoint2();
                endPoint   = arc.IGetEndPoint2();
                ISketchPoint point4      = arc.IGetCenterPoint2();
                int          rotationDir = arc.GetRotationDir();
                double       num21       = 0.0;
                double       num22       = 0.0;
                double       num23       = list2[num5].Segment.GetLength();
                double       radius      = arc.GetRadius();
                double       num25       = (num6 * num23) / radius;
                double       num26       = startPoint.X;
                double       num27       = startPoint.Y;
                double       num28       = endPoint.X;
                double       num29       = endPoint.Y;
                double       num30       = point4.X;
                double       num31       = point4.Y;
                if ((Math.Round(num28, 6) == Math.Round(list2[num5 - 1].StartPoint.X, 6)) && (Math.Round(num29, 6) == Math.Round(list2[num5 - 1].StartPoint.Y, 6)))
                {
                    num26       = endPoint.X;
                    num27       = endPoint.Y;
                    rotationDir = -1 * rotationDir;
                }
                else if ((Math.Round(num28, 6) == Math.Round(list2[num5 - 1].EndPoint.X, 6)) && (Math.Round(num29, 6) == Math.Round(list2[num5 - 1].EndPoint.Y, 6)))
                {
                    num26       = endPoint.X;
                    num27       = endPoint.Y;
                    rotationDir = -1 * rotationDir;
                }
                if ((num30 != num26) && !(num31 == num27))
                {
                    num21 = Math.Atan((num31 - num27) / (num30 - num26));
                }
                if (Math.Round(num30, 8) == Math.Round(num26, 8))
                {
                    if (Math.Round(num31, 8) > Math.Round(num27, 8))
                    {
                        num21 = 4.71238898038469;
                    }
                    else if (Math.Round(num31, 8) < Math.Round(num27, 8))
                    {
                        num21 = 1.5707963267948966;
                    }
                }
                else if (Math.Round(num31, 8) == Math.Round(num27, 8))
                {
                    if (Math.Round(num30, 8) > Math.Round(num26, 8))
                    {
                        num21 = 3.1415926535897931;
                    }
                    else if (Math.Round(num30, 8) < Math.Round(num26, 8))
                    {
                        if (rotationDir > 0)
                        {
                            num21 = 0.0;
                        }
                        else
                        {
                            num21 = 6.2831853071795862;
                        }
                    }
                }
                if ((Math.Round(num30, 8) < Math.Round(num26, 8)) && (Math.Round(num31, 8) < Math.Round(num27, 8)))
                {
                    num22 = num21 + (rotationDir * num25);
                }
                else if ((Math.Round(num30, 8) < Math.Round(num26, 8)) && (Math.Round(num31, 8) > Math.Round(num27, 8)))
                {
                    num22 = (6.2831853071795862 + num21) + (rotationDir * num25);
                }
                else if ((Math.Round(num30, 8) > Math.Round(num26, 8)) && (Math.Round(num31, 8) > Math.Round(num27, 8)))
                {
                    num22 = (3.1415926535897931 + num21) + (rotationDir * num25);
                }
                else if ((Math.Round(num30, 8) > Math.Round(num26, 8)) && (Math.Round(num31, 8) < Math.Round(num27, 8)))
                {
                    num22 = (3.1415926535897931 + num21) + (rotationDir * num25);
                }
                else if (Math.Round(num30, 8) == Math.Round(num26, 8))
                {
                    num22 = num21 + (rotationDir * num25);
                }
                else if (Math.Round(num31, 8) == Math.Round(num27, 8))
                {
                    num22 = num21 + (rotationDir * num25);
                }
                num22 = Math.Round(num22, 6);
                double num32  = num30 + (radius * Math.Cos(num22));
                double num33  = num31 + (radius * Math.Sin(num22));
                bool   flag29 = true;
                if (_swPartModel.Extension.SelectByID2("", "SKETCHPOINT", num32, num33, 0.0, false, 0, null, 0))
                {
                    ISketchPoint point5 = iSelectionManager.GetSelectedObject6(0, 1);

                    if ((point5 != null) && ((Math.Round(point5.X, 6) == Math.Round(num32, 6)) && (Math.Round(point5.Y, 6) == Math.Round(num33, 6))))
                    {
                        flag29 = false;
                    }
                }
                _swPartModel.SetAddToDB(true);
                if (flag29 && (_swPartModel.CreatePoint2(num32, num33, 0.0) != null))
                {
                    _swPartModel.SketchAddConstraints("sgFIXED");
                    _swPartModel.ICreateLine2(num30, num31, 0.0, num32, num33, 0.0).ConstructionGeometry = true;
                }
                _swPartModel.SetAddToDB(false);
                _swPartModel.ClearSelection2(true);
                _swPartModel.InsertSketch2(true);
            }
        }
예제 #7
0
        public string Build(RoofType_e type, int width, int lenght, bool onlyPath)
        {
            string newPartPath = string.Empty;
            string modelName;

            switch (type)
            {
            case  RoofType_e.One:
            case  RoofType_e.Two:
            case  RoofType_e.Three:
            case  RoofType_e.Four:
            case  RoofType_e.Five:
            case  RoofType_e.Six:
                modelName = "15-000";
                break;

            default:
                modelName = "15-000";
                break;
            }



            string newRoofName = "15-0" + type + "-" + width + "-" + lenght;
            string newRoofPath = $@"{RootFolder}{SubjectDestinationFolder}\{newRoofName}.SLDASM";
            bool   IsExistPart = false;

            CheckExistPart(newRoofName + ".SLDASM", out IsExistPart, out newRoofPath);
            var modelRoofPath = $@"{RootFolder}{SourceFolder}\{modelName}.SLDASM";

            solidWorksDocument = SolidWorksAdapter.SldWoksAppExemplare.OpenDoc6(modelRoofPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                                                                (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel + (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "00", 0, 0);

            AssemblyDoc solidWorcsAssemvlyDocyment = (AssemblyDoc)solidWorksDocument;

            solidWorcsAssemvlyDocyment.ResolveAllLightWeightComponents(false);

            DeleteComponents((int)type);


            #region Сохранение и изменение элементов

            var addwidth  = 100;
            var addwidth2 = 75;
            var type4     = 0;
            var divwidth  = 1;
            if (type == RoofType_e.Two || type == RoofType_e.Six)
            {
                addwidth = 75;
                divwidth = 2;
            }
            if (type == RoofType_e.Four)
            {
                type4     = 170;
                addwidth2 = 170 + 75;
            }

            var          widthD        = (Convert.ToDouble(width) / divwidth + addwidth);
            var          lengthD       = (Convert.ToDouble(lenght) - 28.5);
            const double step          = 200;
            const double step2         = 150;
            var          weldW         = Convert.ToDouble((Math.Truncate(Convert.ToDouble(lenght) / step) + 1));
            var          weldW2        = Convert.ToDouble((Math.Truncate(Convert.ToDouble(lenght) / step2) + 1));
            var          newComponents = new List <FileInfo>();

            //15-001
            SolidWorksAdapter.SldWoksAppExemplare.IActivateDoc2("15-001", true, 0);
            var newPartName = $"15-0{type}-01-{width}-{lenght}";

            CheckExistPart(newPartName, out IsExistPart, out newPartPath);
            if (IsExistPart)
            {
                solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0)));
                solidWorksDocument.Extension.SelectByID2("15-001-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                solidWorcsAssemvlyDocyment.ReplaceComponents(newPartPath, "", true, true);
                SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("15-001.SLDPRT");
            }
            else
            {
                newPartPath = $@"{SourceFolder}\{SubjectDestinationFolder}\{newPartName}.SLDPRT";

                //EditPartParameters("15-001",
                //    $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}",
                //    new[,]
                //    {
                //        {"D1@Эскиз1",  type ==  RoofType.Five || type == RoofType.Six ? Convert.ToString(140 + lengthD + type4) : Convert.ToString(lengthD + type4)},
                //        {"D2@Эскиз1", Convert.ToString(widthD)},
                //        {"D4@Эскиз27", Convert.ToString(addwidth2-4.62)},
                //        {"D1@Эскиз27", Convert.ToString(90)},
                //        {"D2@Эскиз27", Convert.ToString((75-4.62))},

                //        {"D1@Эскиз24", type ==  RoofType.Five || type == RoofType.Six? Convert.ToString(149.53) : Convert.ToString(9.53)},

                //        {"D1@Кривая2", Convert.ToString(weldW2*1000)},
                //        {"D1@Кривая1", Convert.ToString(weldW*1000)}
                //    } );
                try
                {
                    VentsMatdll(new[] { "1700" }, new[] { "", "Шаргень", "2" }, newPartName);
                }
                catch (Exception e)
                {
                    Patterns.Observer.MessageObserver.Instance.SetMessage(e.ToString());
                }

                SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(newPartName);
            }



            //15-002
            if (type == RoofType_e.Six)
            {
                try
                {
                    SolidWorksAdapter.SldWoksAppExemplare.IActivateDoc2("15-002", true, 0);
                    newPartName = $"15-0{type}-02-{width}-{lenght}";


                    CheckExistPart(newPartName, out IsExistPart, out newPartPath);
                    if (IsExistPart)
                    {
                        solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0)));
                        solidWorksDocument.Extension.SelectByID2("15-002-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        solidWorcsAssemvlyDocyment.ReplaceComponents(newPartPath, "", true, true);
                        SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("15-002.SLDPRT");
                    }
                    else
                    {
                        newPartPath =
                            $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}.SLDPRT";
                        //EditPartParameters("15-002",
                        //    $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}",
                        //    new[,]
                        //    {
                        //        {"D1@Эскиз1",  type ==  RoofType.Five || type ==  RoofType.Six ? Convert.ToString(140 + lengthD + type4) : Convert.ToString(lengthD + type4)},
                        //        {"D2@Эскиз1", Convert.ToString(widthD)},
                        //        {"D4@Эскиз27", Convert.ToString(addwidth2-4.62)},
                        //        {"D1@Эскиз27", Convert.ToString(90)},
                        //        {"D2@Эскиз27", Convert.ToString((75-4.62))},

                        //        {"D2@Эскиз23", type ==  RoofType.Five || type ==  RoofType.Six ? Convert.ToString(165) : Convert.ToString(25)},

                        //        {"D1@Кривая2", Convert.ToString(weldW2*1000)},
                        //        {"D1@Кривая1", Convert.ToString(weldW*1000)}
                        //    } );
                        try
                        {
                            VentsMatdll(new[] { "1700" }, new[] { "", "Шаргень", "2" }, newPartName);
                        }
                        catch (Exception e)
                        {
                            //MessageBox.Show(e.ToString());
                        }

                        SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(newPartName);
                    }
                    solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0)));
                    solidWorksDocument.Extension.SelectByID2("15-001-3@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    solidWorksDocument.Extension.SelectByID2("ЗеркальныйКомпонент2@15-000", "COMPPATTERN", 0, 0, 0, false, 0, null, 0);
                    solidWorksDocument.EditSuppress2();
                }
                catch (Exception e)
                {
                    Patterns.Observer.MessageObserver.Instance.SetMessage(e.ToString());
                }
            }
            else if (type != RoofType_e.Six)
            {
                solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0)));
                solidWorksDocument.Extension.SelectByID2("15-002-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                solidWorksDocument.EditDelete();
            }

            switch (type)
            {
            case  RoofType_e.Two:
            case  RoofType_e.Six:
                solidWorksDocument.Extension.SelectByID2("Винт самосверл 6-гр.гол с шайбой-33@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                solidWorksDocument.EditDelete();
                break;

            default:
                solidWorksDocument.Extension.SelectByID2("Винт самосверл 6-гр.гол с шайбой-26@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                solidWorksDocument.EditDelete();
                break;
            }

            #endregion

            //  GabaritsForPaintingCamera(SolidWorksDocument);
            try
            {
                solidWorksDocument.ForceRebuild3(true);
                //Console.WriteLine("newRoofPath " + newRoofPath);
                solidWorksDocument.SaveAs2(newRoofPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                newComponents.Add(new FileInfo(newRoofPath));
                SolidWorksAdapter.CloseAllDocumentsAndExit();
                //  PDMWebService.Data.PDM.SolidWorksPdmAdapter.Instance.CheckInOutPdm(newComponents, true);
                //Console.WriteLine("RoofBuilder строка 324 пересмотреть CheckInOutPdm");

                foreach (var newComponent in ComponentsPathList)
                {
                    //   ExportXmlSql.Export(newComponent.FullName);
                }
            }
            catch (Exception ex)
            {
                Patterns.Observer.MessageObserver.Instance.SetMessage(ex.ToString());
            }
            if (onlyPath)
            {
                return(newRoofPath);
            }
            //MessageBox.Show(newRoofPath, "Модель построена");

            return(newRoofPath);
        }