示例#1
0
        protected override void Command()
        {
            try
            {
                LireInfos();

                AjouterInfos(MdlBase);

                if (MdlBase.TypeDoc() == eTypeDoc.Assemblage)
                {
                    MdlBase.eRecParcourirComposants(c => { if (c.IsHidden(true))
                                                           {
                                                               return(false);
                                                           }
                                                           AjouterInfos(c.eModelDoc2()); return(false); });
                }

                if (ToutReconstruire)
                {
                    MdlBase.ForceRebuild3(false);
                }
            }
            catch (Exception e)
            {
                this.LogErreur(new Object[] { e });
            }
        }
示例#2
0
        public void Build(UpdateState us)
        {
            us(16, "Запускаем Solidworks");
            SldWorks swApp = new SldWorks();

            int error   = 0;
            int warning = 0;

            us(32, "Построение 3Д модели");

            ModelDoc2  part        = swApp.OpenDoc6(pathToBeam, (int)swDocumentTypes_e.swDocPART, 0, "", ref error, ref warning);
            IModelView myModelView = part.ActiveView;

            myModelView.FrameState = (int)swWindowState_e.swWindowMaximized;
            us(48, "Устанавливаем размеры");
            part.Parameter("length@BeamSketch").SystemValue = length / 1000.0;
            part.Parameter("depth@BeamSketch").SystemValue  = depth / 1000.0;
            part.Parameter("externalDiameter@BeamSketch").SystemValue
                = externalDiameter / 1000.0;
            us(64, "Перестраиваем");
            part.EditRebuild3();
            part.ForceRebuild3(false);
            us(80, "Отображаем");
            swApp.FrameState = (int)swWindowState_e.swWindowMaximized;
            us(100, "Готов");
        }
示例#3
0
        public void UseDefaultRadiusBend(ModelDoc2 swmodel)
        {
            var swPart = (PartDoc)swmodel;

            Feature swFeat = swPart.FirstFeature();

            while (swFeat != null)
            {
                string nameTypeFeature = swFeat.GetTypeName2();

                if (nameTypeFeature == "EdgeFlange")
                {
                    EdgeFlangeFeatureData swEdgeFlange = swFeat.GetDefinition();

                    if (swEdgeFlange.UseDefaultBendRadius == false)
                    {
                        swApp.SendMsgToUser2(string.Format("Для \" {0} \" будет установлен параметр \"Использовать радиус по умолчанию\".", swFeat.Name), (int)swMessageBoxIcon_e.swMbInformation, (int)swMessageBoxBtn_e.swMbOk);

                        swEdgeFlange.UseDefaultBendRadius = true;

                        swFeat.ModifyDefinition(swEdgeFlange, swmodel, null);
                    }
                }

                swFeat = swFeat.GetNextFeature();
            }

            swmodel.ForceRebuild3(true);
        }
        public void Rebuild()
        {
            //PbLoadAddTable.Minimum = 0;

            //var confArray = ClassPropertySldWorks.ListColumn(_swModel);
            //PbLoadAddTable.Maximum = confArray.Count;
            //PbLoadAddTable.Value = 0;

            //double value = 0;

            // to the ProgressBar's SetValue method.
            //UpdateProgressBarDelegate updatePbDelegate = PbLoadAddTable.SetValue;

            string[] arrayConfig = _swModel.GetConfigurationNames();

            foreach (var confName in from confName in arrayConfig
                     let swConf = _swModel.GetConfigurationByName(confName)
                                  where ((Configuration)swConf).IsDerived() == false select confName)
            {
                _swModel.ShowConfiguration2(confName);

                //value += 1;

                _swModel.ForceRebuild3(false);

                //Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, value });
            }

            //PbLoadAddTable.Value = 0;
        }
示例#5
0
        private void OnClickVue(object sender, EventArgs e)
        {
            if (CurrentClickVue)
            {
                return;
            }

            try
            {
                if (DessinActif.IsNull() || (MdlActif.eSelect_Nb() == 0))
                {
                    return;
                }

                var typeSel = MdlActif.eSelect_RecupererSwTypeObjet();

                if (typeSel == swSelectType_e.swSelDRAWINGVIEWS)
                {
                    CurrentClickVue = true;

                    var vue = MdlActif.eSelect_RecupererObjet <SolidWorks.Interop.sldworks.View>();

                    if (BtParent.Checked)
                    {
                        vue.UseParentScale = true;
                    }
                    else if (BtFeuille.Checked)
                    {
                        vue.UseSheetScale = 1;
                    }
                    else if (BtPersonnalise.Checked)
                    {
                        var echelle = TextBoxVue.Text.Split(':');
                        if (echelle.Length == 2)
                        {
                            var e1 = echelle[0].eToDouble();
                            var e2 = echelle[1].eToDouble();
                            if (e1 > 0 && e2 > 0)
                            {
                                vue.ScaleRatio = new Double[] { e1, e2 };
                                //vue.ScaleDecimal = e1 / e2;
                                MdlActif.ForceRebuild3(true);
                                MdlActif.EditRebuild3();
                                MdlActif.GraphicsRedraw2();
                            }
                        }
                    }

                    vue.eSelectionner(DessinActif);

                    CurrentClickVue = false;
                }
            }
            catch
            {
                ReinitialiserVue();
            }
        }
示例#6
0
        /// <summary>
        /// Удаляет свойства, если они не в своей категории
        /// </summary>
        public static void FixPropertys()
        {
            string ValOut;
            string ResValOut;
            bool   WasResolved;

            cust  = swModel.Extension.CustomPropertyManager[""];
            cust2 = swModel.Extension.CustomPropertyManager[EditProp.configuracione];

            cust.Delete2("Обозначение");
            cust.Delete2("Наименование");
            cust.Delete2("Наименование_ФБ");
            cust.Delete2("Number");
            cust.Delete2("RenameSWP");
            cust.Delete2("DescriptionEng");
            cust.Delete2("Сборка");
            cust.Delete2("Примечание");
            cust.Delete2("Формат");
            cust.Delete2("DrawnBy");

            cust2.Get5("Проверил", true, out ValOut, out ResValOut, out WasResolved);
            Propertiy.ChechedBy = ResValOut;
            cust2.Delete2("Проверил");
            cust.Add3("Проверил", 30, Propertiy.ChechedBy, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew);

            cust2.Get5("Утвердил", true, out ValOut, out ResValOut, out WasResolved);
            Propertiy.ApprovedBy = ResValOut;
            cust2.Delete2("Утвердил");
            cust.Add3("Утвердил", 30, ResValOut, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew);

            cust2.Get5("Техконтроль", true, out ValOut, out ResValOut, out WasResolved);
            Propertiy.TControl = ResValOut;
            cust2.Delete2("Техконтроль");
            cust.Add3("Техконтроль", 30, ResValOut, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew);

            cust2.Get5("Масса_Таблица", true, out ValOut, out ResValOut, out WasResolved);
            Propertiy.Weight = ResValOut;
            cust2.Delete2("Масса_Таблица");
            cust2.Add3("Масса", 30, ResValOut, (int)swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew);


            cust2.Delete2("CheckedBy");
            cust2.Delete2("EngineeringApproval");
            swModel.ForceRebuild3(false);
        }
示例#7
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (cbCustomer.Text == string.Empty)
            {
                DrawingPropertySet.SwApp.SendMsgToUser2(Properties.Resources.CustomerEmpty,
                                                        (int)swMessageBoxIcon_e.swMbStop,
                                                        (int)swMessageBoxBtn_e.swMbOk);
            }
            else if (cbItemNo.Text == string.Empty)
            {
                DrawingPropertySet.SwApp.SendMsgToUser2(Properties.Resources.ItemNumberEmpty,
                                                        (int)swMessageBoxIcon_e.swMbStop,
                                                        (int)swMessageBoxBtn_e.swMbOk);
            }
            else if (cbDescription.Text.Length > 50)
            {
                DrawingPropertySet.SwApp.SendMsgToUser2(Properties.Resources.CutlistDescriptionTooLong,
                                                        (int)swMessageBoxIcon_e.swMbStop,
                                                        (int)swMessageBoxBtn_e.swMbOk);
            }
            else
            {
                string[] clData = cbItemNo.Text.Split(new string[] { "REV" }, StringSplitOptions.None);
                if (clData.Length > 1)
                {
                    if (CutlistData.GetCutlistID(clData[0].Trim(), clData[1].Trim()) > 0)
                    {
                        UpdateCutlist(clData[0].Trim(), clData[1].Trim());
                    }
                }
                else
                {
                    UpdateCutlist(cbItemNo.Text, cbRev.Text);
                }

                if (mde != null)
                {
                    mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
                                                 (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, fracdisp);
                    mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces,
                                                 (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, decs);
                    mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
                                                 (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, decd);
                    md.ForceRebuild3(false);
                }

                if (Properties.Settings.Default.MakeSounds)
                {
                    System.Media.SystemSounds.Beep.Play();
                }

                Close();
            }
        }
示例#8
0
        // Строит или изменяет модель
        public void Build()
        {
            InitAndRunSwApp();
            // имена размеров в документе полумуфты
            string fingerParameter1          = "fingers@Круговой массив1";
            string fingerParameter2          = "fingers@Круговой массив2";
            string nomianalDiameterParameter = "nominalDiameter@Эскиз1";

            // имя полумуфты в сборке (имя компонента верхнего уровня)
            string assemblyPolumuftaName = "Полумуфта-1";
            // Менеджер выделения, выбора
            SelectionMgr swSelMgr = (SelectionMgr)swModel.SelectionManager;

            // удалить выделение
            swModel.ClearSelection2(true);
            Component2 swComp = assembly.GetComponentByName(assemblyPolumuftaName);

            // выбрать полумуфту, не добавлять к выбранным, дата?, показать всплывающее кокшко
            swComp.Select4(false, null, false);
            int info = 0;

            // начать изменение полумуфты
            assembly.EditPart2(false, false, ref info);
            // получить редактируемую модель
            ModelDoc2 polumufta = (ModelDoc2)assembly.GetEditTarget();

            // установка изменяемых параметров для всех конфигураций
            polumufta.Parameter(fingerParameter1).SetSystemValue3(
                countFingers,
                (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations
                );
            polumufta.Parameter(fingerParameter2).SetSystemValue3(
                countFingers,
                (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations
                );

            polumufta.Parameter(nomianalDiameterParameter).SetSystemValue3(
                nominalDiameter,
                (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations
                );
            // ??
            bool retVal = polumufta.EditSuppress2();

            //Debug.Assert(retVal);
            // ??
            assembly.EditAssembly();
            swModel.EditRebuild3();
            swModel.ForceRebuild3(false);
            swModel.ViewZoomtofit2();
        }
示例#9
0
        private void InitTableData()
        {
            md       = (ModelDoc2)DrawingPropertySet.SwApp.ActiveDoc;
            mde      = md.Extension;
            fracdisp = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
                                                    (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);
            //int den = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator,
            //  (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);
            decs = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces,
                                                (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);
            decd = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
                                                (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);

            try {
                mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
                                             (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, (int)swFractionDisplay_e.swDECIMAL);
                mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces,
                                             (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 3);
                mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
                                             (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 3);
                md.ForceRebuild3(false);

                table = new swTableType.swTableType((DrawingPropertySet.SwApp.ActiveDoc as ModelDoc2),
                                                    Redbrick.MasterHashes);
            } catch (NullReferenceException nre) {
                if (_swApp != null)
                {
                    if (dept > -1)
                    {
                        Redbrick.InsertBOM(_swApp, dept);
                    }
                    else
                    {
                        Redbrick.InsertBOM(_swApp);
                    }
                    InitTableData();
                }
                else
                {
                    throw new NullReferenceException(@"No table found.");
                }
            } catch (Exception e) {
                RedbrickErr.ErrMsg em = new RedbrickErr.ErrMsg(e);
                em.ShowDialog();
                Close();
            } finally {
                //
            }
        }
示例#10
0
        public void Write(ModelDoc2 doc)
        {
            // OK, so the controls were linked on update. This reads whatever was
            // entered into the controls, then writes to SW.
            //mp.Update(ref props, cs.EdgeDiffL, cs.EdgeDiffW);
            ReadControls();
            props.Write();
            //ch.Write();
            // Show changes.
            doc.ForceRebuild3(false);

            // This isn't too slow. Might be too slow in DrawingRedbrick though.
            //int err = 0;
            //int wrn = 0;
            //swSaveAsOptions_e op = swSaveAsOptions_e.swSaveAsOptions_Silent;
            //doc.Save3((int)op, ref err, ref wrn);
        }
示例#11
0
        // Проверка на дублирование конфигураций
        public void SplitConfigurations(string configName)
        {
            swApp   = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            swModel = swApp.ActiveDoc;

            CustomPropertyManager swCustProp;
            var ValOut = "";
            var number = "";
            var razdel = "";

            swCustProp = swModel.Extension.CustomPropertyManager[configName];

            if (swModel.CustomInfo2["", "RenameSWP"] == "1")
            {
                return;
            }

            if (configName != "00")
            {
                swCustProp.Get4("Обозначение", true, out ValOut, out number);

                swCustProp.Get4("Раздел", true, out ValOut, out razdel);

                //var stringSldasm = swModel.GetTitle().Replace(".SLDASM", "");

                //if (number != swModel.GetTitle() + "-" + configName)
                if ((number != swModel.GetTitle().Replace(".SLDASM", "") + "-" + configName) || (number != swModel.GetTitle().Replace(".SLDPRT", "") + "-" + configName))
                {
                    if (razdel == "Детали" | razdel == "Сборочные единицы")
                    {
                        MessageBox.Show("Для конфигурации " + "\"" + configName + "\"" + " не проставленно исполнение. Параметр будет проставлен автоматически.");

                        swModel.DeleteCustomInfo2(configName, "Обозначение");
                        swModel.DeleteCustomInfo2(configName, "Исполнение");
                        swModel.AddCustomInfo3(configName, "Исполнение", 30, "");

                        swModel.AddCustomInfo3(configName, "Обозначение", 30, "$PRP:\"SW-File Name\"-" + configName);
                        swModel.AddCustomInfo3(configName, "Обозначение", 30, "$PRP:\"SW-File Name\"");
                        swModel.CustomInfo2[configName, "Исполнение"] = "1";

                        swModel.ForceRebuild3(false);
                    }
                }
            }
        }
示例#12
0
        public void CreatePart()
        {
            string guild = Guid.NewGuid().ToString();
            string root  = @"C:\Users\timos\source\Project\Solution\Project\VenturiPart\" + guild;

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            else
            {
                throw new ArgumentException("Чертеж уже существует.");
            }
            swApp = GetSolidWorks.GetApplication();
            defaultPartTemplate = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            swApp.NewDocument(defaultPartTemplate, 0, 0, 0);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.InsertSketch(true);
            swModel.ClearSelection2(true);
            swModel.SketchManager.CreateCenterLine(0.000000, 0.000000, 0.000000, -0.173611, 0.000000, 0.000000);
            swModel.SketchManager.CreateLine(0.000000, -0.026016, 0.000000, -0.039342, -0.026016, 0.000000);
            swModel.SketchManager.CreateLine(-0.039342, -0.026016, 0.000000, -0.075130, -0.007488, 0.000000);
            swModel.SketchManager.CreateLine(-0.075130, -0.007488, 0.000000, -0.092897, -0.007488, 0.000000);
            swModel.SketchManager.CreateLine(-0.092897, -0.007488, 0.000000, -0.173611, -0.026016, 0.000000);
            swModel.ClearSelection2(true);
            swModel.Extension.SelectByID2("Point8", "SKETCHPOINT", -0.17361079172679997, -0.026016237064323086, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("Point2", "SKETCHPOINT", -0.17361079172679997, 0, 0, true, 0, null, 0);
            swModel.SketchAddConstraints("sgVERTICALPOINTS2D");
            swModel.Extension.SelectByID2("Point4", "SKETCHPOINT", 0, -0.026016237064323086, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            swModel.SketchAddConstraints("sgVERTICALPOINTS2D");
            swModel.Extension.SelectByID2("Point4", "SKETCHPOINT", 0, -0.026016237064323086, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            swModel.ClearSelection2(true);
            swModel.FeatureManager.FeatureRevolve2(true, true, true, false, false, false, 0, 0, 6.2831853071796004, 0, false, false, 0.01, 0.01, 0, 0.005, 0.01, true, true, true);
            swModel.ISelectionManager.EnableContourSelection = false;
            swModel.ViewZoomtofit2();
            swModel.ForceRebuild3(true);
            swModel.SaveAs(PartName + ".SPLDRT");
            swApp = null;
        }
示例#13
0
        public static void UpdateProperty(MaterialModel objMaterial)
        {
            //1.打开指定的SW文件
            ModelDoc2 swDoc = swAppHelper.ActiveDoc(Globals.FileName);
            //2.获取当前激活配置名
            string configName = swDoc.ConfigurationManager.ActiveConfiguration.Name;

            #region 封装所有的SolidWorks属性(配置+自定义)
            //获取属性值:图号、名称、型号规格、单位、热处理、表面处理、品牌、血液
            Dictionary <string, string> MyCustominfos = new Dictionary <string, string>();
            MyCustominfos.Add("Identification Nb", objMaterial.MaterialCode);
            MyCustominfos.Add("Description", objMaterial.MaterialName);
            MyCustominfos.Add("规格", objMaterial.MaterialSpec);
            MyCustominfos.Add("型号", objMaterial.MaterialType);
            MyCustominfos.Add("单位", objMaterial.Unit);
            MyCustominfos.Add("加工属性", objMaterial.MachiningPropertyId);
            MyCustominfos.Add("涂装颜色", objMaterial.PaintingColor);
            MyCustominfos.Add("品牌", objMaterial.BrandId);
            //遍历每个属性并赋值
            foreach (string key in MyCustominfos.Keys)
            {
                //删除,添加配置特定的属性
                swDoc.DeleteCustomInfo2(configName, key);
                swDoc.AddCustomInfo3(configName, key, (int)swCustomInfoType_e.swCustomInfoText, MyCustominfos[key]);
                //删除,添加自定义的属性
                swDoc.DeleteCustomInfo(key);
                swDoc.AddCustomInfo2(key, (int)swCustomInfoType_e.swCustomInfoText, MyCustominfos[key]);
            }
            #endregion

            #region 重建模型
            swDoc.ClearSelection();    //清除选择
            swDoc.ForceRebuild3(true); //重建模型Ctrl+Q
            //swDoc.ShowNamedView2("*等轴测", 7);//等轴测显示
            //swDoc.ViewZoomtofit2();//全屏显示
            //swDoc.Save();
            //swAppHelper.CloseDoc(objDoc.OriginalFileName);
            #endregion
        }
示例#14
0
文件: Class.cs 项目: CatEye12/FixV.2
        public static void SetProperties(string confName)
        {
            if (docType != swDocumentTypes_e.swDocDRAWING && confName != "")//  свойства для Configuration
            {
                swModel.Extension.CustomPropertyManager[confName].Add3("Обозначение", 30, Propertiy.Designition, 2);
                swModel.Extension.CustomPropertyManager[confName].Add3("Раздел", 30, Propertiy.Division, 2);
                swModel.Extension.CustomPropertyManager[confName].Add3("Масса", 30, Propertiy.Weight, 2);
                swModel.Extension.CustomPropertyManager[confName].Add3("Наименование", 30, Propertiy.Name, 2);
            }
            if (docType != swDocumentTypes_e.swDocDRAWING)
            {
                swModel.Extension.CustomPropertyManager[""].Add3("Код документа", 30, Propertiy.DocCode, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Разработал", 30, Propertiy.DevelopedBy, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Проверил", 30, Propertiy.ChechedBy, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Техконтроль", 30, Propertiy.TControl, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Н.контр.", 30, Propertiy.NControl, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Утвердил", 30, Propertiy.ApprovedBy, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Контора", 30, Propertiy.Subvision, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("N извещения", 30, Propertiy.Notification, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Изменение", 30, Propertiy.Changing, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Тип документа", 30, Propertiy.DocType, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("MassaFormat", 30, Propertiy.MassaFormat, 2);
            }
            else if (docType == swDocumentTypes_e.swDocDRAWING)
            {
                swModel.Extension.CustomPropertyManager[""].Add3("Литера", 30, Propertiy.Letter, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Масштаб", 30, Propertiy.Scale, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Материал", 30, Propertiy.Material, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Тип документа1", 30, Propertiy.DocType1, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Литера2", 30, Propertiy.Letter2, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Литера3", 30, Propertiy.Letter3, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Раздел", 30, Propertiy.Division, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Лист", 30, Propertiy.Sheet, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Листов", 30, Propertiy.Sheets, 2);
                swModel.Extension.CustomPropertyManager[""].Add3("Формат", 30, Propertiy.Format, 2);
            }

            swModel.ForceRebuild3(false);
        }
示例#15
0
        public void updateExtrusionDepth(double depthInInches)
        {
            if (depthInInches < 0)
            {
                return;
            }

            double depthInMeters = Utilities.inchesToMeters(depthInInches);

            IDisplayDimension dispDim = (IDisplayDimension)extrusion.GetFirstDisplayDimension();
            IDimension        dim     = dispDim.IGetDimension();

            dim.SetSystemValue3(depthInMeters,
                                (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations,
                                new string[] { belongsTo.ReferencedConfiguration });

            swFeatureMgr.EditRollback((int)swMoveRollbackBarTo_e.swMoveRollbackBarToEnd, extrusion.Name);

            swAssembly.EditRebuild();
            swDoc.EditRebuild3();
            swDoc.ForceRebuild3(false);

            swAssembly.EditAssembly();
        }
示例#16
0
        public void setObject(string[] values)
        {
            ModelDoc2   swModelDoc = swApp.ActiveDoc;
            EquationMgr swEqnMgr   = swModelDoc.GetEquationMgr();

            for (int i = 0; i < swEqnMgr.GetCount(); i++)
            {
                if (swEqnMgr.GlobalVariable[i])
                {
                    string newEquation;

                    // Get the variable name from the swEqn

                    string[] temp = swEqnMgr.Equation[i].Split(new string[] { "=" }, StringSplitOptions.None);
                    string   name = temp[0];

                    // Get the variable unit from the swEqn

                    Regex re     = new Regex(@"([._0-9]+)([a-zA-Z]+)");
                    Match result = re.Match(temp[1]);

                    string unit = result.Groups[2].Value;

                    // Get the index of swEqn variable at variables.

                    temp = temp[0].Split('"');
                    int index = variables.indexVariable(temp[1]);
                    if (index >= 0)
                    {
                        newEquation          = name + "= " + values[index] + unit;
                        swEqnMgr.Equation[i] = newEquation;
                    }
                }
            }
            swModelDoc.ForceRebuild3(true);
        }
        public void CmdRevMethod(bool m)
        {
            try
            {
                if (m & string.IsNullOrEmpty(TxtBox.Text))
                {
                    MessageBox.Show("Введите номер извещения.");
                    return;
                }

                for (var i = 0; i <= _vSheetNames.GetUpperBound(0); i++)
                {
                    //TODO: _swNote

                    //ok = _swDraw.ActivateSheet(_vSheetNames[i]);
                    _swDraw.ActivateSheet(_vSheetNames[i]);
                    _swSheet            = _swDraw.GetCurrentSheet();
                    _strSheetFormatName = _swSheet.GetSheetFormatName();

                    _swModel = (ModelDoc2)_swDraw;

                    _swSelMgr = _swModel.SelectionManager;

                    //MessageBox.Show(_swSelMgr.ToString());
                    // Дата
                    StrTempData = "Revision4@" + _strSheetFormatName;
                    ok          = _swModel.Extension.SelectByID2(StrTempData, "NOTE", 0, 0, 0, false, 0, null, 0);

                    if (ok)
                    {
                        _swNote = _swSelMgr.GetSelectedObject2(1);

                        //MessageBox.Show(_swNote.ToString());
                        if (m)
                        {
                            var date = (DateTime)StrData.SelectedDate;
                            StrTempData = Convert.ToString(date.ToString("dd-MM-yy"));
                            _swNote.SetText(StrTempData);
                        }
                        else
                        {
                            //MessageBox.Show(StrTempData);
                            StrTempData = _swNote.GetText();

                            if (StrTempData == "" | StrTempData == " ")
                            {
                                StrData.SelectedDate = (DateTime.Today);
                            }
                            else
                            {
                                StrData.SelectedDate = Convert.ToDateTime(StrTempData);
                            }
                        }
                    }

                    // Номер
                    StrTempNumber = "Revision3@" + _strSheetFormatName;
                    _swModel.Extension.SelectByID2(StrTempNumber, "NOTE", 0, 0, 0, false, 0, null, 0);

                    if (ok)
                    {
                        _swNote = _swSelMgr.GetSelectedObject2(1);

                        if (m)
                        {
                            StrTempNumber = "ИКД-" + TxtBox.Text;
                            _swNote.SetText(StrTempNumber);
                        }
                        else
                        {
                            StrTempNumber = _swNote.GetText();
                            if (StrTempNumber != " ")
                            {
                                TxtBox.Text = StrTempNumber.Substring(4);
                            }
                        }
                    }

                    // Зам.
                    _strTemp = "Revision2@" + _strSheetFormatName;
                    _swModel.Extension.SelectByID2(_strTemp, "NOTE", 0, 0, 0, false, 0, null, 0);


                    if (ok)
                    {
                        _swNote = _swSelMgr.GetSelectedObject2(1);


                        if (m)
                        {
                            if (Rb1.IsChecked == true)
                            {
                                _swNote.SetText("Зам.");
                                _swModel.DeleteCustomInfo2("", "Revision");
                            }

                            if (Rb3.IsChecked == true)
                            {
                                _swNote.SetText("Нов.");
                                _swModel.DeleteCustomInfo2("", "Revision");
                            }

                            if (Rb2.IsChecked == true)
                            {
                                _swNote.SetText("Змін.");
                                _swModel.DeleteCustomInfo2("", "Revision");
                                _swModel.AddCustomInfo3("", "Revision", 30, "");
                                _swModel.CustomInfo2["", "Revision"] = Convert.ToString(SpinButton.Content);
                            }
                        }
                        else
                        {
                            _strTemp = _swNote.GetText();

                            if (_strTemp == "Зам.")
                            {
                                Rb1.IsChecked        = true;
                                Rb3.IsChecked        = false;
                                Rb2.IsChecked        = false;
                                SpinButton.IsEnabled = false;
                            }

                            if (_strTemp == "Нов.")
                            {
                                Rb1.IsChecked        = false;
                                Rb3.IsChecked        = true;
                                Rb2.IsChecked        = false;
                                SpinButton.IsEnabled = false;
                            }

                            if (_strTemp == "Змін.")
                            {
                                Rb1.IsChecked        = false;
                                Rb3.IsChecked        = false;
                                Rb2.IsChecked        = true;
                                SpinButton.IsEnabled = true;
                            }

                            int  n;
                            bool isNumeric = int.TryParse(_swModel.CustomInfo2["", "Revision"], out n);

                            if (isNumeric)
                            {
                                SpinButton.Content = _swModel.CustomInfo2["", "Revision"];
                            }
                            else
                            {
                                _swModel.DeleteCustomInfo2("", "Revision");
                            }
                        }
                    }
                }

                // Возвращение активного листа
                _swDraw.ActivateSheet(_strActiveSheetName);

                // Перестраиваем чертеж
                _swModel.ForceRebuild3(false);

                _swModel.GraphicsRedraw2();
                _swModel.ClearSelection2(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "; " + ex.StackTrace);
            }
        }
示例#18
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            DP330 item = (DP330)objDP330Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2         swModel = default(ModelDoc2);
            ModelDoc2         swPart  = default(ModelDoc2);
            AssemblyDoc       swAssy  = default(AssemblyDoc);
            Component2        swComp;
            Feature           swFeat        = default(Feature);
            object            configNames   = null;
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            bool   status     = false;
            string compReName = string.Empty;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc;                                                  //装配体
            string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称

            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);
            //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------
            decimal leftSBDis  = item.LeftDis;
            decimal rightSBDis = item.RightDis;

            try
            {
                //----------Top Level----------
                if (item.Length < 1000m)
                {
                    swModel.Parameter("D1@LocalLPattern2").SystemValue = 2;
                    swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 1000m;
                }
                else if (item.Length >= 1000m && item.Length < 2000m)
                {
                    swModel.Parameter("D1@LocalLPattern2").SystemValue = 3;
                    swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 2000m;
                }
                else
                {
                    swModel.Parameter("D1@LocalLPattern2").SystemValue = 4;
                    swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 3000m;
                }
                //----------侧板----------
                switch (item.SidePanel)
                {
                case "LEFT":
                case "DPBACKL":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

                case "RIGHT":
                case "DPBACKR":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;

                case "MIDDLE":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }
                //----------背板----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0002-2"));
                swPart = swComp.GetModelDoc2();//打开零件
                swPart.Parameter("D3@Skizze1").SystemValue = item.Length / 1000m;
                swFeat = swComp.FeatureByName("DPB-LEFT");
                if (item.SidePanel == "DPBACKL" || item.SidePanel == "DPBACKB")
                {
                    swFeat.SetSuppression2(1, 2, configNames);                                                         //参数1:1解压,0压缩
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                }
                swFeat = swComp.FeatureByName("DPB-RIGHT");
                if (item.SidePanel == "DPBACKR" || item.SidePanel == "DPBACKB")
                {
                    swFeat.SetSuppression2(1, 2, configNames);                                                             //参数1:1解压,0压缩
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                }
                //----------NOCJ腔主体----------
                //重命名装配体内部
                compReName = "FNCS0001[DP330-" + tree.Module + "]{" + (int)item.Length + "}";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCS0001-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                if (status)
                {
                    swModelDocExt.RenameDocument(compReName);
                }
                swModel.ClearSelection2(true);
                status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                swModel.ClearSelection2(true);
                if (status)
                {
                    swComp = swAssy.GetComponentByName(compReName + "-1");
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Skizze1").SystemValue = item.Length / 1000m;
                    if (item.Outlet == "LEFT")
                    {
                        swFeat = swComp.FeatureByName("OUTLET-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("OUTLET-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    else if (item.Outlet == "RIGHT")
                    {
                        swFeat = swComp.FeatureByName("OUTLET-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("OUTLET-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("OUTLET-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("OUTLET-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    swFeat = swComp.FeatureByName("DPB-LEFT");
                    if (item.SidePanel == "DPBACKL" || item.SidePanel == "DPBACKB")
                    {
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swFeat = swComp.FeatureByName("DPB-RIGHT");
                    if (item.SidePanel == "DPBACKR" || item.SidePanel == "DPBACKB")
                    {
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    //DP
                    if (item.DPSide == "LEFT" || item.DPSide == "BOTH")
                    {
                        swFeat = swComp.FeatureByName("DP-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D14@Sketch42").SystemValue = (item.LeftDis + 1m) / 1000m;
                        leftSBDis = leftSBDis + 90m;
                        swFeat    = swComp.FeatureByName("CUT-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@Sketch56").SystemValue = 105m / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("DP-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("CUT-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    if (item.DPSide == "RIGHT" || item.DPSide == "BOTH")
                    {
                        swFeat = swComp.FeatureByName("DP-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D14@Sketch43").SystemValue = (item.RightDis + 1m) / 1000m;
                        rightSBDis = rightSBDis + 90m;
                        swFeat     = swComp.FeatureByName("CUT-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@Sketch58").SystemValue = 105m / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("DP-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("CUT-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    //BCJ
                    if (item.BackCJSide == "LEFT" || item.BackCJSide == "BOTH")
                    {
                        swFeat = swComp.FeatureByName("BCJ-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D8@Sketch19").SystemValue = (item.LeftDis + 11m) / 1000m;
                        leftSBDis = leftSBDis + 90m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("BCJ-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    if (item.BackCJSide == "RIGHT" || item.BackCJSide == "BOTH")
                    {
                        swFeat = swComp.FeatureByName("BCJ-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@Sketch20").SystemValue = (item.RightDis + 11m) / 1000m;
                        rightSBDis = rightSBDis + 90m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("BCJ-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    //----------左----------
                    ////左类型排风腔KCJDB800
                    //if (item.LeftBeamType == "KCJDB800" || item.LeftBeamType == "UCJDB800")
                    //{
                    //    swFeat = swComp.FeatureByName("BCJ-LEFT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //    swFeat = swComp.FeatureByName("KCJDB800-LEFT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D59@Sketch46").SystemValue = (item.LeftBeamDis + 1m) / 1000m;
                    //    if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-LEFT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D6@Sketch48").SystemValue = (item.Length - item.LeftBeamDis + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJDB800-LEFT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    //左类型排风腔KCWDB800
                    if (item.LeftBeamType == "KCWDB800" || item.LeftBeamType == "UCWDB800")
                    {
                        swFeat = swComp.FeatureByName("BCJ-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("DP-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("KCWDB800-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D30@Sketch50").SystemValue = (item.LeftBeamDis + 1m) / 1000m;
                        if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                        {
                            swFeat = swComp.FeatureByName("GUTTER-LEFT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m;
                            swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m;
                            swPart.Parameter("D7@Sketch53").SystemValue = (item.Length - item.LeftBeamDis + 1m) / 1000m;
                        }
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("KCWDB800-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    ////左类型排风腔KCJSB535
                    //if (item.LeftBeamType == "KCJSB535" || item.LeftBeamType == "UCJSB535")
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB535-LEFT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D46@Sketch35").SystemValue = (leftSBDis + 1m) / 1000m;
                    //    if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-LEFT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 535m + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB535-LEFT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    //左类型排风腔KCWSB535
                    if (item.LeftBeamType == "KCWSB535" || item.LeftBeamType == "UCWSB535")
                    {
                        swFeat = swComp.FeatureByName("KCWSB535-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D25@Sketch48").SystemValue = (leftSBDis + 1m) / 1000m;
                        if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                        {
                            swFeat = swComp.FeatureByName("GUTTER-LEFT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m;
                            swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m;
                            swPart.Parameter("D7@Sketch53").SystemValue = (leftSBDis + 535m + 1m) / 1000m;
                        }
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("KCWSB535-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    ////左类型排风腔UCJSB385
                    //if (item.LeftBeamType == "UCJSB385")
                    //{
                    //    swFeat = swComp.FeatureByName("UCJSB385-LEFT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D16@Sketch43").SystemValue = (leftSBDis + 1m) / 1000m;
                    //    if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-LEFT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 385m + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("UCJSB385-LEFT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    ////左类型排风腔KCJSB290
                    //if (item.LeftBeamType == "KCJSB290")
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB290-LEFT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D14@Sketch41").SystemValue = (leftSBDis + 1m) / 1000m;
                    //    if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-LEFT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 290m + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB290-LEFT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    ////左类型排风腔KCJSB265
                    //if (item.LeftBeamType == "KCJSB265")
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB265-LEFT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D23@Sketch28").SystemValue = (leftSBDis + 1m) / 1000m;
                    //    if (item.LKSide == "LEFT" || item.LKSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("LKS270-LEFT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D24@Sketch51").SystemValue = (leftSBDis + 265m + 1m) / 1000m;
                    //        if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                    //        {
                    //            swFeat = swComp.FeatureByName("GUTTER-LEFT");
                    //            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //            swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //            swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //            swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 270m + 265m + 1m) / 1000m;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                    //        {
                    //            swFeat = swComp.FeatureByName("GUTTER-LEFT");
                    //            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //            swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //            swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //            swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 265m + 1m) / 1000m;
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB265-LEFT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    //左类型排风腔KCWSB265
                    if (item.LeftBeamType == "KCWSB265")
                    {
                        swFeat = swComp.FeatureByName("KCWSB265-LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D15@Sketch46").SystemValue = (leftSBDis + 1m) / 1000m;
                        if (item.LKSide == "LEFT" || item.LKSide == "BOTH")
                        {
                            swFeat = swComp.FeatureByName("LKS270-LEFT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D24@Sketch52").SystemValue = (leftSBDis + 265m + 1m) / 1000m;
                            if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                            {
                                swFeat = swComp.FeatureByName("GUTTER-LEFT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m;
                                swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m;
                                swPart.Parameter("D7@Sketch53").SystemValue = (leftSBDis + 270m + 265m + 1m) / 1000m;
                            }
                        }
                        else
                        {
                            if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH")
                            {
                                swFeat = swComp.FeatureByName("GUTTER-LEFT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m;
                                swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m;
                                swPart.Parameter("D7@Sketch53").SystemValue = (leftSBDis + 265m + 1m) / 1000m;
                            }
                        }
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("KCWSB265-LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }

                    //----------右----------
                    ////右类型排风腔KCJDB800
                    //if (item.RightBeamType == "KCJDB800" || item.RightBeamType == "UCJDB800")
                    //{
                    //    swFeat = swComp.FeatureByName("BCJ-RIGHT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //    swFeat = swComp.FeatureByName("KCJDB800-RIGHT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D59@Sketch47").SystemValue = (item.RightBeamDis + 1m) / 1000m;
                    //    if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D7@Sketch50").SystemValue = (item.Length - item.RightBeamDis + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJDB800-RIGHT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    //右类型排风腔KCWDB800
                    if (item.RightBeamType == "KCWDB800" || item.RightBeamType == "UCWDB800")
                    {
                        swFeat = swComp.FeatureByName("BCJ-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("DP-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("KCWDB800-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D31@Sketch51").SystemValue = (item.RightBeamDis + 1m) / 1000m;
                        if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                        {
                            swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m;
                            swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m;
                            swPart.Parameter("D7@Sketch55").SystemValue =
                                (item.Length - item.RightBeamDis + 1m) / 1000m;
                        }
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("KCWDB800-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    ////右类型排风腔KCJSB535
                    //if (item.RightBeamType == "KCJSB535" || item.RightBeamType == "UCJSB535")
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB535-RIGHT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D46@Sketch37").SystemValue = (rightSBDis + 1m) / 1000m;
                    //    if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 535m + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB535-RIGHT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    //右类型排风腔KCWSB535
                    if (item.RightBeamType == "KCWSB535" || item.RightBeamType == "UCWSB535")
                    {
                        swFeat = swComp.FeatureByName("KCWSB535-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D24@Sketch49").SystemValue = (rightSBDis + 1m) / 1000m;
                        if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                        {
                            swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m;
                            swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m;
                            swPart.Parameter("D7@Sketch55").SystemValue = (rightSBDis + 535m + 1m) / 1000m;
                        }
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("KCWSB535-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    ////右类型排风腔UCJSB385
                    //if (item.RightBeamType == "UCJSB385")
                    //{
                    //    swFeat = swComp.FeatureByName("UCJSB385-RIGHT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D16@Sketch44").SystemValue = (rightSBDis + 1m) / 1000m;
                    //    if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 385m + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("UCJSB385-RIGHT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    ////右类型排风腔KCJSB290
                    //if (item.RightBeamType == "KCJSB290")
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB290-RIGHT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D14@Sketch42").SystemValue = (rightSBDis + 1m) / 1000m;
                    //    if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //        swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //        swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 290m + 1m) / 1000m;
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB290-RIGHT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    ////右类型排风腔KCJSB265
                    //if (item.RightBeamType == "KCJSB265")
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB265-RIGHT");
                    //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //    swPart.Parameter("D1@Sketch55").SystemValue = (rightSBDis + 1m) / 1000m;
                    //    if (item.LKSide == "RIGHT" || item.LKSide == "BOTH")
                    //    {
                    //        swFeat = swComp.FeatureByName("LKS270-RIGHT");
                    //        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //        swPart.Parameter("D24@Sketch53").SystemValue = (rightSBDis + 265m + 1m) / 1000m;
                    //        if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                    //        {
                    //            swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                    //            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //            swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //            swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //            swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 270m + 265m + 1m) / 1000m;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                    //        {
                    //            swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                    //            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    //            swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m;
                    //            swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m;
                    //            swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 265m + 1m) / 1000m;
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    swFeat = swComp.FeatureByName("KCJSB265-RIGHT");
                    //    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //}
                    //右类型排风腔KCWSB265
                    if (item.RightBeamType == "KCWSB265")
                    {
                        swFeat = swComp.FeatureByName("KCWSB265-RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D15@Sketch47").SystemValue = (rightSBDis + 1m) / 1000m;
                        if (item.LKSide == "RIGHT" || item.LKSide == "BOTH")
                        {
                            swFeat = swComp.FeatureByName("LKS270-RIGHT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D24@Sketch54").SystemValue = (rightSBDis + 265m + 1m) / 1000m;
                            if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                            {
                                swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m;
                                swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m;
                                swPart.Parameter("D7@Sketch55").SystemValue = (rightSBDis + 270m + 265m + 1m) / 1000m;
                            }
                        }
                        else
                        {
                            if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH")
                            {
                                swFeat = swComp.FeatureByName("GUTTER-RIGHT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m;
                                swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m;
                                swPart.Parameter("D7@Sketch55").SystemValue = (rightSBDis + 265m + 1m) / 1000m;
                            }
                        }
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("KCWSB265-RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                }
                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
示例#19
0
        /// <summary>
        /// 天花子装配导出DXF图纸
        /// </summary>
        /// <param name="swApp"></param>
        /// <param name="tree"></param>
        /// <param name="dxfPath"></param>
        /// <param name="userId"></param>
        public void CeilingAssyToDxf(SldWorks swApp, SubAssy subAssy, string dxfPath, int userId)
        {
            swApp.CommandInProgress = true;
            List <CeilingCutList> celingCutLists = new List <CeilingCutList>();
            string assyPath = subAssy.SubAssyPath;

            if (assyPath.Length == 0)
            {
                return;
            }
            try
            {
                //打开模型
                ModelDoc2 swModel = swApp.OpenDoc6(assyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                                   (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
                if (swModel == null)
                {
                    MessageBox.Show("模型不存在,请认真检查", "模型不存在");
                    return;
                }
                string modulePath = dxfPath + @"\" + subAssy.SubAssyName;
                if (!Directory.Exists(modulePath))
                {
                    Directory.CreateDirectory(modulePath);
                }
                swModel.ForceRebuild3(true);
                AssemblyDoc swAssy = swModel as AssemblyDoc;
                //获取所有零部件集合
                var compList = swAssy.GetComponents(false);
                //遍历集合中的所有零部件对象
                foreach (var swComp in compList)
                {
                    //判断零件是否被压缩,不显示,封套,零件名称不是以sldprt或SLDPRT结尾
                    if (swComp.Visible == 1 && !swComp.IsEnvelope() && !swComp.IsSuppressed() &&
                        (swComp.GetPathName().EndsWith(".sldprt") || swComp.GetPathName().EndsWith(".SLDPRT")))
                    {
                        Component2 swParentComp = swComp.GetParent();
                        //总装没有父装配体
                        if (swParentComp == null)
                        {
                            ConfigurationManager swConfigMgr = swModel.ConfigurationManager;
                            Configuration        swConfig2   = swConfigMgr.ActiveConfiguration;
                            swParentComp = swConfig2.GetRootComponent3(true);
                        }
                        //判断父装配体是否可视,并且不封套
                        if (swParentComp.Visible == 1 && !swParentComp.IsEnvelope() && !swComp.IsSuppressed())
                        {
                            PartDoc swPart = swComp.GetModelDoc2();
                            //获取文档中的额Body对象集合
                            var bodyList = swPart.GetBodies2(0, false);
                            //遍历集合中的所有Body对象,判断是否为钣金
                            foreach (var swBody in bodyList)
                            {
                                //如果是钣金则将零件地址添加到列表中
                                if (swBody.IsSheetMetal())
                                {
                                    if (sheetMetaDic.ContainsKey(swComp.GetPathName()))
                                    {
                                        sheetMetaDic[swComp.GetPathName()] += 1;
                                    }
                                    else
                                    {
                                        sheetMetaDic.Add(swComp.GetPathName(), 1);
                                    }
                                }
                            }
                        }
                    }
                }
                //关闭装配体零件
                swApp.CloseDoc(assyPath);
                //遍历钣金零件
                foreach (var sheetMeta in sheetMetaDic)
                {
                    //打开模型
                    ModelDoc2 swPart = swApp.OpenDoc6(sheetMeta.Key, (int)swDocumentTypes_e.swDocPART,
                                                      (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
                    Feature        swFeat    = (Feature)swPart.FirstFeature();
                    CeilingCutList cutRecord = new CeilingCutList()
                    {
                        SubAssyId = subAssy.SubAssyId,
                        Quantity  = sheetMeta.Value,
                        UserId    = userId
                    };
                    while (swFeat != null)
                    {
                        var suppStatus = swFeat.IsSuppressed2((int)swInConfigurationOpts_e.swThisConfiguration, null);
                        if (suppStatus[0] == false && swFeat.GetTypeName() == "SolidBodyFolder")
                        {
                            BodyFolder swBodyFolder = (BodyFolder)swFeat.GetSpecificFeature2();
                            swBodyFolder.SetAutomaticCutList(true);
                            swBodyFolder.SetAutomaticUpdate(true);
                            Feature SubFeat = swFeat.GetFirstSubFeature();
                            if (SubFeat != null)
                            {
                                Feature    ownerFeature    = SubFeat.GetOwnerFeature();
                                BodyFolder swSubBodyFolder = ownerFeature.GetSpecificFeature2();
                                swSubBodyFolder.UpdateCutList();
                                string val         = string.Empty;
                                string valout      = string.Empty;
                                bool   wasResolved = false;
                                bool   linkToProp  = false;
                                SubFeat.CustomPropertyManager.Get4("Bounding Box Length", false, out val, out valout);
                                cutRecord.Length = Convert.ToDecimal(valout);
                                SubFeat.CustomPropertyManager.Get4("Bounding Box Width", false, out val, out valout);
                                cutRecord.Width = Convert.ToDecimal(valout);
                                SubFeat.CustomPropertyManager.Get4("Sheet Metal Thickness", false, out val, out valout);
                                cutRecord.Thickness = Convert.ToDecimal(valout);
                                SubFeat.CustomPropertyManager.Get4("Material", false, out val, out valout);
                                cutRecord.Materials = valout;
                                swPart.GetActiveConfiguration().CustomPropertyManager.Get6("Description", false, out valout, out val, out wasResolved, out linkToProp);
                                cutRecord.PartDescription = valout;
                                cutRecord.PartNo          = swPart.GetTitle().Substring(0, swPart.GetTitle().Length - 7);
                                celingCutLists.Add(cutRecord);//将信息添加到集合中
                            }
                        }
                        swFeat = swFeat.GetNextFeature();
                    }
                    PartToDxf(swApp, swPart, modulePath);
                    //关闭零件
                    swApp.CloseDoc(sheetMeta.Key);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(assyPath + "导图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                sheetMetaDic.Clear();
                swApp.CloseDoc(assyPath);        //关闭,很快
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
            //基于事务ceilingCutLists提交SQLServer
            if (celingCutLists.Count == 0)
            {
                return;
            }
            try
            {
                if (objCeilingCutListService.ImportCutList(celingCutLists))
                {
                    celingCutLists.Clear();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Cutlist导入数据库失败" + ex.Message);
            }
        }
示例#20
0
                public void OpenDoc(int idPdm, int revision, int taskType, string filePath, string fileName)
                {
        
                    swApp = new SldWorks() {Visible = true};

                    Process[] processes = Process.GetProcessesByName("SLDWORKS");

                    var errors = 0;
                    var warnings = 0;

                    #region Case

                    switch (taskType)
                    {
                        case 1:

                            Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black));
                            Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("Выполняется: {0}\r\n", filePath))));
  
                            swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocPART, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
                            swModel = swApp.ActiveDoc;

                            if (!IsSheetMetalPart((IPartDoc) swModel))
                            {

                                Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.DarkBlue));
                                Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("Не листовой металл!\r\n")));
                                Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("--------------------------------------------------------------------------------------------------------------\r\n")));
                                Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n")));

                                swApp.CloseDoc(filePath);
                                swApp.ExitApp();
                                swApp = null;

                                foreach (Process process in processes)
                                {
                                    process.CloseMainWindow();
                                    process.Kill();
                                }
                                return;
                            }

                            swExtension = (ModelDocExtension) swModel.Extension;
                            swModel.EditRebuild3();
                            swModel.ForceRebuild3(false);

                            CreateFlattPatternUpdate();

                            object[] confArray = swModel.GetConfigurationNames();
                            foreach (var confName in confArray)
                            {
                                Configuration swConf = swModel.GetConfigurationByName(confName.ToString());
                                if (swConf.IsDerived()) continue;
                                    
                                Area(confName.ToString());
                                GabaritsForPaintingCamera(confName.ToString());
                            }

                            ExportDataToXmlSql(fileName, idPdm, revision);

                            ConvertToErpt(filePath);
                            Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black));
                            Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("{0} - Выполнен!\r\n", filePath))));
                            Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("-----------------------------------------------------------------\r\n")));
                            Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n")));

                            break;
                        case 2:

                            swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocDRAWING, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

                            //if (warnings == (int)swFileLoadWarning_e.swFileLoadWarning_ReadOnly)
                            //{MessageBox.Show("This file is read-only.");}

                            swDraw = (DrawingDoc) swModel;
                            swExtension = (ModelDocExtension) swModel.Extension;
                            ConvertToPdf(filePath);

                            break;
                        case 3:

                            //swModel = swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

                            MessageBox.Show("3");
                            break;
                    }

                    //TODO: swApp exit
                    swApp.CloseDoc(filePath);
                    swApp.ExitApp();
                    swApp = null;
                    
                    foreach (Process process in processes)
                    {
                        process.CloseMainWindow();
                        process.Kill();
                    }
                    #endregion
                }
示例#21
0
        public string Build(SpigotType_e type, int width, int height)
        {
            string modelName = GetModelName(type);

            NewSpigotName = GetSpigotName(type, width, height);


            Dimension dimension;

            int addDimH = modelName == "12-30" ? 10 : 1;

            string newSpigotPath = $@"{RootFolder}{SubjectDestinationFolder}\{NewSpigotName}";

            string drawingName = modelName == "12-30" ? modelName : "12-00";

            var modelSpigotDrw = $@"{RootFolder}{SourceFolder}\{drawingName}.SLDDRW";

            ModelDoc2 swDrawingSpigot = SolidWorksAdapter.OpenDocument(modelSpigotDrw, swDocumentTypes_e.swDocDRAWING);

            solidWorksDocument = SolidWorksAdapter.AcativeteDoc("12-00");
            AssemblyDoc assemblyDocument = (AssemblyDoc)solidWorksDocument;

            assemblyDocument.ResolveAllLightWeightComponents(false);

            DeleteEquations(modelName);
            solidWorksDocument.ForceRebuild3(true);

            #region formuls
            var          w          = (Convert.ToDouble(width) - 1) / 1000;                                   // ????????????
            var          h          = Convert.ToDouble((Convert.ToDouble(height) + addDimH) / 1000);          // ????????????
            const double step       = 50;
            var          weldWidth  = Convert.ToDouble((Math.Truncate(Convert.ToDouble(width) / step) + 1));  // ????????????
            var          weldHeight = Convert.ToDouble((Math.Truncate(Convert.ToDouble(height) / step) + 1)); // ????????????
            #endregion

            DeleteComponents((int)type);
            if (modelName == "12-20")
            {
                PartName = $"12-20-{height}.SLDPRT";
                if (CheckExistPart != null)
                {
                    CheckExistPart(PartName, out IsPartExist, out NewPartPath);
                }
                else
                {
                    MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning);
                }

                if (IsPartExist)
                {
                    solidWorksDocument.Extension.SelectByID2("12-20-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    assemblyDocument.ReplaceComponents(NewPartPath, "", true, true);
                }
                else
                {
                    NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}";
                    solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]")));
                    dimension.SystemValue = h - 0.031;
                    solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]")));
                    dimension.SystemValue = weldHeight;
                    SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
                    InitiatorSaveExeption(error, warning, NewPartPath);
                    ComponentsPathList.Add(NewPartPath);
                    SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(NewPartPath);
                }

                //12-20-002

                PartName = $"12-20-{width}.SLDPRT";

                MessageObserver.Instance.SetMessage("Check exist part. " + NewPartPath);
                if (CheckExistPart != null)
                {
                    MessageObserver.Instance.SetMessage("\tCheckExistPartEvent");
                    CheckExistPart(PartName, out IsPartExist, out NewPartPath);
                }
                else
                {
                    MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning);
                }

                if (IsPartExist)
                {
                    solidWorksDocument.Extension.SelectByID2("12-20-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    assemblyDocument.ReplaceComponents(PartName, "", true, true);
                }
                else
                {
                    NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}";
                    solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]")));
                    dimension.SystemValue = w - 0.031;
                    solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]")));
                    dimension.SystemValue = weldWidth;
                    SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
                    InitiatorSaveExeption(error, warning, NewPartPath);
                    ComponentsPathList.Add(NewPartPath);
                }

                //12-003
                PartName = $"12-03-{width}-{height}.SLDPRT";
                if (CheckExistPart != null)
                {
                    CheckExistPart(PartName, out IsPartExist, out NewPartPath);
                }
                else
                {
                    MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning);
                }
                if (IsPartExist)
                {
                    solidWorksDocument.Extension.SelectByID2("12-003-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    assemblyDocument.ReplaceComponents(PartName, "", true, true);
                }
                else
                {
                    NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}";
                    solidWorksDocument.Extension.SelectByID2("D3@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D3@Эскиз[email protected]")));
                    dimension.SystemValue = w;
                    solidWorksDocument.Extension.SelectByID2("D2@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D2@Эскиз[email protected]")));
                    dimension.SystemValue = h;
                    solidWorksDocument.EditRebuild3();
                    SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
                    InitiatorSaveExeption(error, warning, NewPartPath);
                    ComponentsPathList.Add(NewPartPath);
                    SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(NewPartPath);
                }
            }
            if (modelName == "12-30")
            {
                //12-30-001

                PartName = $"12-30-{height}.SLDPRT";

                MessageObserver.Instance.SetMessage("Check exist part. " + NewPartPath);
                if (CheckExistPart != null)
                {
                    CheckExistPart(PartName, out IsPartExist, out NewPartPath);
                }
                else
                {
                    MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning);
                }

                if (IsPartExist)
                {
                    solidWorksDocument.Extension.SelectByID2("12-30-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    assemblyDocument.ReplaceComponents(PartName, "", true, true);
                }
                else
                {
                    NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}";
                    solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]")));
                    dimension.SystemValue = h - 0.031;
                    solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]")));
                    dimension.SystemValue = weldHeight;
                    SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
                    InitiatorSaveExeption(error, warning, NewPartPath);
                    ComponentsPathList.Add(NewPartPath);
                }
                //12-30-002
                PartName = $"12-30-{width}.SLDPRT";


                if (CheckExistPart != null)
                {
                    CheckExistPart(PartName, out IsPartExist, out NewPartPath);
                }
                else
                {
                    MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning);
                }

                if (IsPartExist)
                {
                    solidWorksDocument.Extension.SelectByID2("12-30-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    assemblyDocument.ReplaceComponents(PartName, "", true, true);
                }
                else
                {
                    NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}";
                    solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]")));
                    dimension.SystemValue = w - 0.031;
                    solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]")));
                    dimension.SystemValue = weldHeight;
                    SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
                    InitiatorSaveExeption(error, warning, NewPartPath);
                    ComponentsPathList.Add(NewPartPath);
                }
                //12-003

                PartName = $"12-03-{width}-{height}.SLDPRT";
                if (CheckExistPart != null)
                {
                    CheckExistPart(PartName, out IsPartExist, out NewPartPath);
                }
                else
                {
                    MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning);
                }

                if (IsPartExist)
                {
                    solidWorksDocument.Extension.SelectByID2("12-003-2@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    assemblyDocument.ReplaceComponents(PartName, "", true, true);
                }
                else
                {
                    NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}";
                    solidWorksDocument.Extension.SelectByID2("D3@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D3@Эскиз[email protected]")));
                    dimension.SystemValue = w;
                    solidWorksDocument.Extension.SelectByID2("D2@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    dimension             = ((Dimension)(solidWorksDocument.Parameter("D2@Эскиз[email protected]")));
                    dimension.SystemValue = h;
                    solidWorksDocument.EditRebuild3();
                    SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
                    InitiatorSaveExeption(error, warning, NewPartPath);
                    ComponentsPathList.Add(NewPartPath);
                }
            }

            solidWorksDocument.ForceRebuild3(true);
            solidWorksDocument.Extension.SaveAs(newSpigotPath + ".SLDASM", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
            InitiatorSaveExeption(error, warning, newSpigotPath + ".SLDASM");

            SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(NewSpigotName + ".SLDASM");
            ComponentsPathList.Add(newSpigotPath + ".SLDASM");
            swDrawingSpigot.Extension.SelectByID2("DRW1", "SHEET", 0, 0, 0, false, 0, null, 0);
            var drw = (DrawingDoc)SolidWorksAdapter.AcativeteDoc(drawingName + ".SLDDRW");
            drw.ActivateSheet("DRW1");
            drw.SetupSheet5("DRW1", 12, 12, 1, GetDrawingScale(width, height), true, @"\\pdmsrv\SolidWorks Admin\Templates\Основные надписи\A3-A-1.slddrt", 0.42, 0.297, "По умолчанию", false);
            swDrawingSpigot.Extension.SaveAs(newSpigotPath + ".SLDDRW", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning);
            InitiatorSaveExeption(error, warning, newSpigotPath + ".SLDDRW");

            ComponentsPathList.Add(newSpigotPath + ".SLDDRW");
            SolidWorksAdapter.CloseAllDocumentsAndExit();
            return(newSpigotPath);
        }
示例#22
0
        private void AutoDimensionDrawing2(ModelDoc2 swModel, bool many )
        {
            bool del3List = false;
            var thrdList = new List<string>();
            int shi = 0;
            isValidXml = true;

            var swDrawing = (DrawingDoc)swModel;
            if (swModel.GetCustomInfoValue("", "AutoDim") == "No")
            {
                if (many)
                {
                    MessageBox.Show(@"Если хотите образмерить чертеж, смените No на Yes в поле 'AutoDim' свойств данного чертежа",
                        @"MrDoors", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                isValidXml = false;
            }
            if (swModel.GetCustomInfoValue("", "MakeCNCprog") == "Yes")
            {
                _createProgramm = true;
            }
            if (!isValidXml && !_createProgramm) // если не надо создавать программу и авто дим = но, то образмеривать просто не нужно.
                return;
            swModel.Extension.SetUserPreferenceDouble((int)swUserPreferenceDoubleValue_e.swDetailingDimToDimOffset,
                                                      (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0.006);
            swModel.Extension.SetUserPreferenceDouble((int)swUserPreferenceDoubleValue_e.swDetailingObjectToDimOffset,
                                                      (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0.010);

            Dictionary<string, bool> listSide;
            string targetModelPath = null;
            if (!File.Exists(Path.Combine(Path.GetDirectoryName(_swAdd.RootModel.GetPathName()), "fpTime.txt")))
            {
                //MessageBox.Show("Образмеривание детали может пройти некорректно! Для корректного образмеривания детали необходимо произвести Окончательную обработку заказа.");
                throw new Exception("Образмеривание детали может пройти некорректно! Для корректного образмеривания детали необходимо произвести Окончательную обработку заказа.");
            }
            else
            {
                //просто взять Sketch Number

               string fnameWithoutExt = Path.GetFileNameWithoutExtension(swModel.GetPathName());
                fnameWithoutExt = fnameWithoutExt.Substring(fnameWithoutExt.Length - 4, 4);
                SwDMDocument8 swDoc = null;
                SwDMApplication swDocMgr = SwAddin.GetSwDmApp();
                SwDmDocumentOpenError oe;
                SwDmCustomInfoType type;
                if (!(fnameWithoutExt[0] == '#' && (fnameWithoutExt[3] == 'P' || fnameWithoutExt[3] == 'p')))
                {

                    swDoc = (SwDMDocument8) swDocMgr.GetDocument(Path.ChangeExtension(swModel.GetPathName(), "SLDASM"),SwDmDocumentType.swDmDocumentAssembly, true, out oe);

                }
                else
                {
                    object brokenRefVar;
                    SwDMSearchOption src = swDocMgr.GetSearchOptionObject();

                    var swDocDraw = (SwDMDocument8)swDocMgr.GetDocument(swModel.GetPathName(), SwDmDocumentType.swDmDocumentDrawing, true, out oe);
                    var varRef = (object[])swDocDraw.GetAllExternalReferences2(src, out brokenRefVar);
                    swDocDraw.CloseDoc();
                    targetModelPath = (string)varRef[0];
                    swDoc = (SwDMDocument8)swDocMgr.GetDocument(targetModelPath, SwDmDocumentType.swDmDocumentAssembly, true, out oe);
                }
                if (swDoc != null)
                {
                    var prop = swDoc.GetCustomProperty("Sketch Number", out type);
                    if (string.IsNullOrEmpty(prop) || prop == "0")
                        throw new Exception("Образмеривание детали прервано, т.к. может пройти некорректно ! Для корректного образмеривания детали необходимо произвести Окончательную обработку заказа.");
                    swDoc.CloseDoc();
                }
                _swAdd.SetModelProperty(swModel, "WasMesure", string.Empty, swCustomInfoType_e.swCustomInfoYesOrNo, "Yes", true);
            }
            string pathXml = WriteXmlFile(swModel, isValidXml, targetModelPath);

            bool isNeededSheetNumber = PrepareDrawingDoc(swModel, out listSide);
            bool dimOnlyNew = false;
            if (swModel.GetCustomInfoValue("", "DimOnlyNew") == "Yes")
                dimOnlyNew = true;
            var vSheetNames = (string[])swDrawing.GetSheetNames();
            var rootNode = _node;
            bool atLeastOneF1View = false;

            foreach (var vSheetName in vSheetNames)
            {
                bool iftherewasAhole = false;
                XmlElement element = null;
                XmlElement sheetNode = null;
                KeyValuePair<string,string> tableNameAttribute = new KeyValuePair<string, string>();
                if (_createProgramm && !string.IsNullOrEmpty(pathXml))
                {
                    element = _cxml.CreateElement("Sheet");
                    element.SetAttribute("Name", vSheetName);
                    _node = rootNode.AppendChild(element);
                    sheetNode = element;
                }

                double vScale = 0;
                var type = new List<string>();
                var listSize = new List<SizeForDim>();
                swDrawing.ActivateSheet(vSheetName);
                swModel.Extension.SelectByID2(vSheetName, "SHEET", 0, 0, 0, true,
                                              (int)swSelectionMarkAction_e.swSelectionMarkAppend, null, 0);
                swModel.ViewZoomToSelection();
                swModel.ClearSelection();
                var swSheet = (Sheet)swDrawing.GetCurrentSheet();
                var swViews = (object[])swSheet.GetViews();
                bool side = shi == 1;
                if (isNeededSheetNumber && listSide.ContainsKey(vSheetName.Substring(vSheetName.Length - 1)))
                    side = listSide[vSheetName.Substring(vSheetName.Length - 1)];
                if (vSheetName.ToUpper().Contains("FACE"))
                    side = true;
                if (vSheetName.ToUpper().Contains("BACK"))
                    side = false;

                if (swViews != null)
                {
                    var rootViewElement = _node;
                    if (Properties.Settings.Default.ViewsBeforeDimen)
                        ReplaceViews(swViews, swDrawing);
                    foreach (var t in swViews)
                    {
                        #region Образмеривание вида
                        var swView = (View) t;
                        swModel.ClearSelection2(true);

                        const string expr = "^F[1-6]$";

                        Match isMatch = Regex.Match(swView.Name, expr, RegexOptions.IgnoreCase);

                        if (_createProgramm && swView.Name.ToLower().Contains("const"))
                        {

                            //Logging.Log.Instance.Fatal(@"На данный чертеж программа не будет создана! " + swModel.GetPathName() + "swView.Name = " + swView.Name);
                            //MessageBox.Show(@"На данный чертеж программа не будет создана!", @"MrDoors",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                        }

                        if (!(isMatch.Success || swView.Name.Contains("Чертежный вид")) ||
                            swView.Name.ToLower().Contains("const") ||
                            swView.Type == (int)swDrawingViewTypes_e.swDrawingDetailView) continue;

                        if (_createProgramm && !isMatch.Success)
                        {
                            _createProgramm = false;
                            //Logging.Log.Instance.Fatal(@"На данный чертеж программа не будет создана! " + swModel.GetPathName() + "swView.Name = " + swView.Name);
                            //MessageBox.Show(@"На данный чертеж программа не будет создана!", @"MrDoors",
                            //                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }

                        swDrawing.ActivateView(swView.GetName2());
                        swView.UseSheetScale = 0;

                        var list = HideUnusedComponents(swView, dimOnlyNew);

                        try
                        {
                            vScale = ((double[]) swView.ScaleRatio)[1];
                            swView.SetDisplayMode3(false, (int) swDisplayMode_e.swFACETED_HIDDEN, true, true);

                            #region Процесс образмеривания

                            using (var d = new DimensionView(_swApp, BlockPositionExtension.FromBool(side), dimOnlyNew))
                            {

                                d.DimView(side);
                                if (!iftherewasAhole)
                                    iftherewasAhole = d.IsHole;
                                if (!isNeededSheetNumber && !side && !iftherewasAhole)
                                    del3List = true;
                                else
                                {
                                    if (isNeededSheetNumber && !iftherewasAhole)
                                    {
                                        del3List = true;
                                        thrdList.Add(vSheetName);
                                    }
                                }
                                foreach (var tp in d.List)
                                {
                                    if (!type.Contains(tp))
                                        type.Add(tp);
                                }
                                listSize.Add(d.AddSize);

                                #region Запись данных в xml файл

                                if (element != null)
                                {
                                    element = _cxml.CreateElement("View");
                                    element.SetAttribute("Name", swView.Name);
                                    if (swView.Name == "F1")
                                    {
                                        atLeastOneF1View = true;

                                            SwDmDocumentOpenError oe;
                                            SwDMApplication swDocMgr = SwAddin.GetSwDmApp();
                                            var swDoc = (SwDMDocument8)swDocMgr.GetDocument(Path.ChangeExtension(swModel.GetPathName(), "SLDASM"),
                                                                                             SwDmDocumentType.swDmDocumentAssembly, true, out oe);
                                            if (swDoc != null)
                                            {
                                                var cit = new SwDmCustomInfoType();
                                                string[] names = swDoc.GetCustomPropertyNames();
                                                string extFeats = null,faner11 = null,faner12 = null,faner21 = null,faner22 = null;

                                                if (names.Contains("ExtFanerFeats"))
                                                    extFeats = swDoc.GetCustomProperty("ExtFanerFeats", out cit);
                                                double angle = 57.29577951308232*swView.Angle; //(180/П)
                                                if (Math.Abs(angle) < 0.000001 || Math.Abs(angle + 90) < 0.000001 || Math.Abs(angle - 270) < 0.000001 || Math.Abs(angle - 180) < 0.000001 || Math.Abs(angle - 90) < 0.000001) //!string.IsNullOrEmpty(extFeats) && extFeats == "Yes" &&
                                                {
                                                    if (names.Contains("Faner11"))
                                                        faner11 = swDoc.GetCustomProperty("Faner11", out cit);
                                                    if (names.Contains("Faner12"))
                                                        faner12 = swDoc.GetCustomProperty("Faner12", out cit);
                                                    if (names.Contains("Faner21"))
                                                        faner21 = swDoc.GetCustomProperty("Faner21", out cit);
                                                    if (names.Contains("Faner22"))
                                                        faner22 = swDoc.GetCustomProperty("Faner22", out cit);

                                                    var tmpElem = _cxml.CreateElement("Comment");
                                                    string comment = FrmEdge.GetCommentFromProperties(faner11,faner12,faner21,faner22, angle, _swAdd,swModel);
                                                    double angle2 = angle + 90;
                                                    double angle4 = angle + 180;
                                                    double angle3 = angle + 270;
                                                    if (angle2 > 270)
                                                        angle2 = angle2%360;
                                                    if (angle3 > 270)
                                                        angle3 = angle3 % 360;
                                                    if (angle4 > 270)
                                                        angle4 = angle4 % 360;
                                                    string comment2 = FrmEdge.GetCommentFromProperties(faner11, faner12, faner21, faner22, angle2, _swAdd, swModel);
                                                    string comment3 = FrmEdge.GetCommentFromProperties(faner11, faner12, faner21, faner22, angle3, _swAdd, swModel);
                                                    string comment4 = FrmEdge.GetCommentFromProperties(faner11, faner12, faner21, faner22, angle4, _swAdd, swModel);
                                                    tmpElem.SetAttribute("Rot270",comment3);
                                                    tmpElem.SetAttribute("Rot180",comment4);
                                                    tmpElem.SetAttribute("Rot90", comment2);
                                                    tmpElem.SetAttribute("Rot0", comment);
                                                    rootNode.PrependChild(tmpElem);
                                                }

                                            }

                                        //swDoc.CloseDoc();

                                        //int warnings = 0;
                                        //int errors = 0;
                                        //var swModelDoc = _swApp.OpenDoc6(Path.ChangeExtension(swModel.GetPathName(), "SLDASM"), (int)swDocumentTypes_e.swDocASSEMBLY,
                                        //                  (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors,
                                        //                  warnings);
                                        //if (!string.IsNullOrEmpty(swModelDoc.CustomInfo2["", "ExtFanerFeats"]) && swModelDoc.CustomInfo2["", "ExtFanerFeats"] == "Yes")
                                        //{
                                        //    var tmpElem = _cxml.CreateElement("Comment");
                                        //    string comment = FrmEdge.GetComment(swModelDoc, swView.Angle, _swAdd);
                                        //    tmpElem.SetAttribute("Rot270", string.Empty);
                                        //    tmpElem.SetAttribute("Rot90", string.Empty);
                                        //    tmpElem.SetAttribute("Rot0", comment);
                                        //    rootNode.PrependChild(tmpElem);
                                        //}

                                    }
                                    if (_node != null)
                                    {
                                        _node = rootViewElement.AppendChild(element);
                                        switch (d.Side)
                                        {
                                            case BlockPosition.LeftTopToRightBottom:

                                                if (swView.Name == "F1")
                                                    tableNameAttribute = new KeyValuePair<string, string>("F1","J");
                                                if (swView.Name == "F6")
                                                {
                                                    if (tableNameAttribute.Key!="F1") // F1 -  приоритетнее
                                                        tableNameAttribute = new KeyValuePair<string, string>("F6", "B");
                                                }
                                                if (string.IsNullOrEmpty(tableNameAttribute.Key))
                                                {
                                                    tableNameAttribute = new KeyValuePair<string, string>("none","J");
                                                }
                                                break;
                                            case BlockPosition.RightTopToLeftBottom:
                                                if (swView.Name == "F1")
                                                    tableNameAttribute = new KeyValuePair<string, string>("F1","B");
                                                if (swView.Name == "F6")
                                                {
                                                    if (tableNameAttribute.Key!="F1") // F1 -  приоритетнее
                                                        tableNameAttribute = new KeyValuePair<string, string>("F6", "J");
                                                }
                                                if (string.IsNullOrEmpty(tableNameAttribute.Key))
                                                {
                                                    tableNameAttribute = new KeyValuePair<string, string>("none", "B");
                                                }
                                                break;
                                            case BlockPosition.LeftBottomToRightTop:
                                            case BlockPosition.RigthBottomToLeftTop:
                                                //MessageBox.Show(
                                                //    "В этом чертеже начало координат находится внизу. Программа может быть создана некорректно!",
                                                //    @"MrDoors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                                // element = _cxml.CreateElement("Table");
                                                // element.SetAttribute("Name", "Не удалось определить наименование стола!");
                                                //_node=_node.AppendChild(element);
                                                break;

                                        }
                                    }

                                    int i = 0;
                                    string id = "id" + i;
                                    element = _cxml.CreateElement(id);

                                    element.SetAttribute("X", Math.Round(d.X).ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                    element.SetAttribute("Y", Math.Round(d.Y).ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                    if (swView.Name == "F1" || swView.Name == "F6")
                                        element.SetAttribute("Z", _z.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                    if (_node != null)
                                        _node.AppendChild(element);

                                    foreach (var ls in d.ListSize)
                                    {
                                        i++;
                                        id = "id" + i;
                                        element = _cxml.CreateElement(id);

                                        element.SetAttribute("X", ls.X.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                        element.SetAttribute("Y",  ls.Y.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                        element.SetAttribute("Diameter",  ls.Diameter.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));
                                        element.SetAttribute("Depth",ls.Depth.ToString(CultureInfo.CreateSpecificCulture("ru-RU")));

                                        if (_node != null)
                                            _node.AppendChild(element);
                                    }
                                    _node = _node.ParentNode;
                                }

                                #endregion
                            }

                            #endregion

                            swView.SetDisplayMode3(false, (int) swDisplayMode_e.swFACETED_HIDDEN_GREYED, true, true);

                            swDrawing.ActivateSheet(vSheetName);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(@"Ошибка при образмеривании! " + e.Message, @"MrDoors",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        finally
                        {
                            if (dimOnlyNew)
                                ShowHiddenComponents(list);
                        }

                        #endregion
                    }
                }
                if (type.Count != 0)
                    LegendMaker(swModel, swDrawing, type, vScale);
                if (!string.IsNullOrEmpty(tableNameAttribute.Value))
                    sheetNode.SetAttribute("TableName", tableNameAttribute.Value);
                if (Properties.Settings.Default.ScaleWhenDimen && !del3List && shi != 0)
                    AutoScaleSheet(listSize, swSheet, vScale, side);
                shi++;
                if(_node!=null)
                    _node = _node.ParentNode;
                AutoArrangeDimentions(vSheetName,dimOnlyNew);
            }
            swModel.EditRebuild3();
            if (shi == 3)
            {
                if (del3List)
                {
                    if (isNeededSheetNumber && thrdList.Count > 0)
                        foreach (var sh in thrdList)
                            swModel.Extension.SelectByID2(sh, "SHEET", 0, 0, 0, true, 0, null, 0);
                    else
                    {
                     if (!swModel.Extension.SelectByID2("Лист3", "SHEET", 0, 0, 0, false, 0, null, 0))
                     {
                         swModel.Extension.SelectByID2("Back3", "SHEET", 0, 0, 0, false, 0, null, 0);
                     }
                    }
                    swModel.DeleteSelection(true);
                }
                else
                    SheetNumering(swModel, swDrawing);
            }
            swModel.ForceRebuild3(false);
            bool writeXml = true;
            if (atLeastOneF1View)
            {
                try
                {
                    writeXml=SomeLogicChanges(swModel);
                }
                catch(Exception e)
                {
                    if (swModel.GetPathName() != null)
                        Logging.Log.Instance.Fatal(e, "Ошибка при применении логики к XML. " + swModel.GetPathName());
                    else
                        Logging.Log.Instance.Fatal(e, "Ошибка при применении логики к XML. ");

                }
                if (writeXml)
                    StopWriteXml(pathXml);
            }

            return;
        }
示例#23
0
        public void StoreToSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            System.Windows.Forms.MessageBox.Show("StoreToSelection()");

            // If user pressed OK, apply settings to all selected parts (i.e. ChBody in C::E):
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    Component2 swPart      = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc();

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPart, "Chrono ChBody data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                        swPartModel.ForceRebuild3(false); // needed?
                        if (myattr == null)
                        {
                            System.Windows.Forms.MessageBox.Show("myattr null in setting!!");
                        }
                    }

                    ((Parameter)myattr.GetParameter("collision_on")).SetDoubleValue2(
                        Convert.ToDouble(m_collide), (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("friction")).SetDoubleValue2(
                        m_friction, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("rolling_friction")).SetDoubleValue2(
                        m_rolling_friction, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("spinning_friction")).SetDoubleValue2(
                        m_spinning_friction, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("restitution")).SetDoubleValue2(
                        m_restitution, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("collision_margin")).SetDoubleValue2(
                        m_collision_margin, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("collision_envelope")).SetDoubleValue2(
                        m_collision_envelope, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    ((Parameter)myattr.GetParameter("collision_family")).SetDoubleValue2(
                        (double)m_collision_family, (int)swInConfigurationOpts_e.swThisConfiguration, "");

                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  myattr_conveyor = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono ChConveyor data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     *  if (myattr_conveyor == null)
                     *      System.Windows.Forms.MessageBox.Show("myattr null in setting!!");
                     * }
                     *
                     * ((Parameter)myattr_conveyor.GetParameter("conveyor_speed")).SetDoubleValue2(
                     *            m_conveyor_speed, (int)swInConfigurationOpts_e.swThisConfiguration, "");
                     */
                }
            }
        }
示例#24
0
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            // Fetch current properties from the selected part(s) (i.e. ChBody in C::E)
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    Component2 swPart      = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc();

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPart, "Chrono::ChBody_data", 0, (int)swInConfigurationOpts_e.swAllConfiguration);

                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityInvalid))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityInvalid!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntitySuppressed))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntitySuppressed!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityAmbiguous))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityAmbiguous!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityDeleted))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityDeleted!");
                        }

                        swPartModel.ForceRebuild3(false); // needed?
                    }

                    Set_collision_on(Convert.ToBoolean(((Parameter)myattr.GetParameter(
                                                            "collision_on")).GetDoubleValue()));
                    Set_friction(((Parameter)myattr.GetParameter(
                                      "friction")).GetDoubleValue());
                    Set_rolling_friction(((Parameter)myattr.GetParameter(
                                              "rolling_friction")).GetDoubleValue());
                    Set_spinning_friction(((Parameter)myattr.GetParameter(
                                               "spinning_friction")).GetDoubleValue());
                    Set_restitution(((Parameter)myattr.GetParameter(
                                         "restitution")).GetDoubleValue());
                    Set_collision_envelope(((Parameter)myattr.GetParameter(
                                                "collision_envelope")).GetDoubleValue());
                    Set_collision_margin(((Parameter)myattr.GetParameter(
                                              "collision_margin")).GetDoubleValue());
                    Set_collision_family((int)((Parameter)myattr.GetParameter(
                                                   "collision_family")).GetDoubleValue());



                    // fetch SW attribute with Chrono parameters for ChConveyor

                    /*
                     * SolidWorks.Interop.sldworks.Attribute myattr_conv = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conv == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  //myattr_conv = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono::ChConveyor_data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     * }
                     */
                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor (if any!)
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor != null)
                     * {
                     *  show_conveyor_params = true;
                     *
                     *  Set_conveyor_speed(((Parameter)myattr_conveyor.GetParameter(
                     *                  "conveyor_speed")).GetDoubleValue());
                     * }
                     */
                }
            }
        }
示例#25
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            KCJSB265 item = (KCJSB265)objKCJSB265Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2         swModel = default(ModelDoc2);
            ModelDoc2         swPart  = default(ModelDoc2);
            AssemblyDoc       swAssy  = default(AssemblyDoc);
            Component2        swComp;
            Feature           swFeat        = default(Feature);
            object            configNames   = null;
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            bool   status     = false;
            string compReName = string.Empty;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc;                                                  //装配体
            string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称

            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);
            //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------
            int fcNo = (int)((item.Length - item.FCSideLeft - item.FCSideRight) / 499m) - item.FCBlindNo;

            try
            {
                //----------Top Level----------
                //判断FC数量,FC侧板长度
                if (item.FCBlindNo > 0)
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1"));
                    swComp.SetSuppression2(2);                                           //2解压缩,0压缩
                    swFeat = swAssy.FeatureByName("LocalLPattern3");
                    swFeat.SetSuppression2(1, 2, configNames);                           //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern3").SystemValue = item.FCBlindNo; //D1阵列数量,D3阵列距离
                    swModel.Parameter("D1@Distance11").SystemValue     = item.FCSideLeft / 1000m;
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩
                    swFeat = swAssy.FeatureByName("LocalLPattern3");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                //判断FC/KSA
                if (item.FCType == "KSA")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1"));
                    swComp.SetSuppression2(2);                                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern4");
                    swFeat.SetSuppression2(1, 2, configNames);                 //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern4").SystemValue = fcNo; //D1阵列数量,D3阵列距离
                    swModel.Parameter("D1@Distance9").SystemValue      = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern2");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1"));
                    swComp.SetSuppression2(2);                                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern2");
                    swFeat.SetSuppression2(1, 2, configNames);                 //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern2").SystemValue = fcNo; //D1阵列数量,D3阵列距离
                    swModel.Parameter("D1@Distance10").SystemValue     = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern4");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                //----------油网侧板----------
                switch (item.FCSide)
                {
                case "LEFT":
                    //重命名装配体内部
                    if (item.FCType == "KSA")
                    {
                        compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft + fcNo * 2.5m) + "}";
                    }
                    else
                    {
                        compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft - 4m) + "}";
                    }
                    status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-1");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        if (item.FCType == "KSA")
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft + fcNo * 2.5m) / 1000m;
                        }
                        else
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - 4m) / 1000m;
                        }
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;

                case "RIGHT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    //重命名装配体内部
                    if (item.FCType == "KSA")
                    {
                        compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight + fcNo * 2.5m) + "}";
                    }
                    else
                    {
                        compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight - 4m) + "}";
                    }
                    status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-1");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        if (item.FCType == "KSA")
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight + fcNo * 2.5m) / 1000m;
                        }
                        else
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - 4m) / 1000m;
                        }
                    }
                    break;

                case "BOTH":
                    //重命名装配体内部
                    if (item.FCType == "KSA")
                    {
                        compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft + fcNo * 1.25m) + "}";
                    }
                    else
                    {
                        compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft - 2m) + "}";
                    }
                    status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-1");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        if (item.FCType == "KSA")
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft + fcNo * 1.25m) / 1000m;
                        }
                        else
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - 2m) / 1000m;
                        }
                    }
                    //重命名装配体内部
                    if (item.FCType == "KSA")
                    {
                        compReName = "FNCE0109[BP-" + tree.Module + ".2]{" + (int)(item.FCSideRight + fcNo * 1.25m) + "}";
                    }
                    else
                    {
                        compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight - 2m) + "}";
                    }
                    status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-1");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        if (item.FCType == "KSA")
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight + fcNo * 1.25m) / 1000m;
                        }
                        else
                        {
                            swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - 2m) / 1000m;
                        }
                    }
                    break;

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }
                //----------日本项目需要压缩零件----------
                if (item.Japan == "YES")
                {
                    //吊装垫片
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //排风脖颈
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    //排风滑门
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXDOOR-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    //排风腔
                    //重命名装配体内部
                    compReName = "FNCE0125[KCJSB265-" + tree.Module + "]{" + (int)item.Length + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0125-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-2");
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D1@Aufsatz-Linear austragen1").SystemValue = item.Length / 1000m;
                        swFeat = swComp.FeatureByName("EX");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("Cut-Extrude4");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTECSIDE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        if (item.MARVEL == "YES")
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("MA-TAB");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("MA-TAB");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                    }
                }
                else
                {
                    //吊装垫片
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9"));
                    swComp.SetSuppression2(2);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩
                    //排风脖颈
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0019-1"));
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swFeat = swComp.FeatureByName("ANSUL");
                    if (item.ANSUL == "YES")
                    {
                        swFeat.SetSuppression2(1, 2, configNames);                      //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0020-1"));
                    swPart = swComp.GetModelDoc2();//打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0047-1"));
                    swPart = swComp.GetModelDoc2();//打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swFeat = swComp.FeatureByName("ANDTEC");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0048-2"));
                    swPart = swComp.GetModelDoc2();            //打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swFeat = swComp.FeatureByName("ANDTEC");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //排风滑门
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXDOOR-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Distance3").SystemValue = (item.ExWidth + 20m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0018-1"));
                    swPart = swComp.GetModelDoc2();//打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = (item.ExLength * 2m + 100m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0013-1"));
                    swPart = swComp.GetModelDoc2();//打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength / 2m + 10m) / 1000m;
                    swPart.Parameter("D2@Sketch1").SystemValue = (item.ExWidth + 40m) / 1000m;
                    //排风腔
                    //重命名装配体内部
                    compReName = "FNCE0125[KCJSB265-" + tree.Module + "]{" + (int)item.Length + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0125-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-2");
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D1@Aufsatz-Linear austragen1").SystemValue = item.Length / 1000m;
                        swFeat = swComp.FeatureByName("EX");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("Cut-Extrude4");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D4@Sketch2").SystemValue = item.ExRightDis / 1000m;
                        swPart.Parameter("D1@Sketch2").SystemValue = item.ExLength / 1000m;
                        swPart.Parameter("D2@Sketch2").SystemValue = item.ExWidth / 1000m;
                        if (item.ANSUL == "YES")
                        {
                            //侧喷
                            if (item.ANSide == "LEFT")
                            {
                                swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            }
                            else if (item.ANSide == "RIGHT")
                            {
                                swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            }
                            else
                            {
                                swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            }
                            //探测器
                            if (item.ANDetector == "LEFT")
                            {
                                swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANDTECSIDE LEFT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            }
                            else if (item.ANDetector == "RIGHT")
                            {
                                swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANDTECSIDE LEFT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            }
                            else if (item.ANDetector == "BOTH")
                            {
                                swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANDTECSIDE LEFT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            }
                            else
                            {
                                swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANDTECSIDE LEFT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            }
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTECSIDE LEFT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }

                        if (item.MARVEL == "YES")
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("MA-TAB");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("MA-TAB");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                    }
                }
                //----------SSP灯板支撑条----------
                if (item.SSPType == "DOME")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m;
                    if (item.Gutter == "YES")
                    {
                        swModel.Parameter("D1@Distance12").SystemValue = item.GutterWidth / 1000m;
                    }
                    else
                    {
                        swModel.Parameter("D1@Distance12").SystemValue = 0.5m / 1000m;
                    }
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m;
                    if (item.Gutter == "YES")
                    {
                        swModel.Parameter("D1@Distance2").SystemValue = item.GutterWidth / 1000m;
                    }
                    else
                    {
                        swModel.Parameter("D1@Distance2").SystemValue = 0.5m / 1000m;
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }

                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
示例#26
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Item + "-" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Item + "-" + tree.Module + "-" +
                            tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            ABD200 item = (ABD200)objABD200Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2   swModel = default(ModelDoc2);
            ModelDoc2   swPart  = default(ModelDoc2);
            AssemblyDoc swAssy  = default(AssemblyDoc);
            Component2  swComp;
            Feature     swFeat      = default(Feature);
            object      configNames = null;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc; //装配体
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);     //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------
            //铆钉数量
            int     rivetNo  = (int)((item.Length - 47m) / 400m);
            decimal rivetDis = (item.Length - 47m) / rivetNo;

            try
            {
                //----------Top Level----------

                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHO0136-1"));
                swPart = swComp.GetModelDoc2();//打开零件3
                swPart.Parameter("D1@Sketch1").SystemValue = (item.Length - 5m) / 1000m;
                if (item.Length == 400m || item.Length == 500m)
                {
                    swFeat = swComp.FeatureByName("MIDDLE");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("300");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swFeat = swComp.FeatureByName("MIDDLE");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("300");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHO0134-1"));
                swPart = swComp.GetModelDoc2();//打开零件3
                swPart.Parameter("D12@Sketch1").SystemValue = (item.Length - 6m) / 1000m;
                if (item.Length == 400m || item.Length == 750m)
                {
                    swPart.Parameter("D5@Sketch27").SystemValue = 28.5m / 1000m;
                }
                else
                {
                    swPart.Parameter("D5@Sketch27").SystemValue = 78.5m / 1000m;
                }
                swFeat = swComp.FeatureByName("750");
                if (item.Length == 750m)
                {
                    swFeat.SetSuppression2(1, 2, configNames);                      //参数1:1解压,0压缩
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHO0135-2"));
                swPart = swComp.GetModelDoc2();//打开零件3
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 25m) / 1000m;
                if (item.Length == 400m || item.Length == 750m)
                {
                    swPart.Parameter("D4@Sketch7").SystemValue = 17.5m / 1000m;
                }
                else
                {
                    swPart.Parameter("D4@Sketch7").SystemValue = 67.5m / 1000m;
                }
                swFeat = swComp.FeatureByName("750");
                if (item.Length == 750m)
                {
                    swFeat.SetSuppression2(1, 2, configNames);                      //参数1:1解压,0压缩
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0006-1"));
                swPart = swComp.GetModelDoc2();//打开零件3
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length + 50m) / 1000m;
                swFeat = swComp.FeatureByName("ABD");
                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                if (item.Length == 400m || item.Length == 500m)
                {
                    swFeat = swComp.FeatureByName("ABD-MIDDLE");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("ABD-300");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swFeat = swComp.FeatureByName("ABD-MIDDLE");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("ABD-300");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0007-1"));
                swPart = swComp.GetModelDoc2();//打开零件3
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length + 50m) / 1000m;
                swFeat = swComp.FeatureByName("ABD");
                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                if (item.Length == 400m || item.Length == 500m)
                {
                    swFeat = swComp.FeatureByName("ABD-MIDDLE");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("ABD-300");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swFeat = swComp.FeatureByName("ABD-MIDDLE");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("ABD-300");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                }


                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
示例#27
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            LFUSA item = (LFUSA)objLFUSAService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2         swModel = default(ModelDoc2);
            ModelDoc2         swPart  = default(ModelDoc2);
            AssemblyDoc       swAssy  = default(AssemblyDoc);
            Component2        swComp;
            Feature           swFeat        = default(Feature);
            object            configNames   = null;
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            bool   status     = false;
            string compReName = string.Empty;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc;                                                  //装配体
            string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称

            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);
            //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------


            try
            {
                //----------Top Level----------

                //----------散流器主体----------
                //重命名装配体内部
                compReName = "FNCA0001[LFUSA-" + tree.Module + "]{" + (int)item.Length + "}(" + (int)item.Width + ")";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCA0001-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                if (status)
                {
                    swModelDocExt.RenameDocument(compReName);
                }
                swModel.ClearSelection2(true);
                status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                swModel.ClearSelection2(true);
                if (status)
                {
                    swComp = swAssy.GetComponentByName(compReName + "-1");
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = item.Length / 1000m;
                    swPart.Parameter("D1@Sketch1").SystemValue      = (item.Width - 2m) / 1000m;
                    swPart.Parameter("D2@Sketch2").SystemValue      = item.SuDia / 1000m;
                    swPart.Parameter("D1@Sketch2").SystemValue      =
                        (item.SuDis * (item.SuNo / 2m - 1m) + item.SuDis / 2m) / 1000m;
                    if (item.SuNo < 2)
                    {
                        swFeat = swComp.FeatureByName("LPattern1");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("LPattern1");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@LPattern1").SystemValue = item.SuNo;
                        swPart.Parameter("D3@LPattern1").SystemValue = item.SuDis / 1000m;
                    }

                    swFeat = swComp.FeatureByName("HANGERHOLE");
                    if (item.Japan == "YES")
                    {
                        swFeat.SetSuppression2(0, 2, configNames);                      //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(1, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swFeat = swComp.FeatureByName("CUTLEFT");
                    if (item.SidePanel == "LEFT" || item.SidePanel == "BOTH")
                    {
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swFeat = swComp.FeatureByName("CUTRIGHT");
                    if (item.SidePanel == "RIGHT" || item.SidePanel == "BOTH")
                    {
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                }
                //----------侧板----------
                switch (item.SidePanel)
                {
                case "LEFT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D9@Skizze1").SystemValue = (item.Width - 2m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;

                case "RIGHT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D9@Skizze1").SystemValue = (item.Width - 2m) / 1000m;
                    break;

                case "MIDDLE":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D9@Skizze1").SystemValue = (item.Width - 2m) / 1000m;
                    break;

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }

                if (item.Japan == "YES")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9"));
                    swComp.SetSuppression2(2);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                }

                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false;  //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
        private void InitTableData()
        {
            md = (ModelDoc2)DrawingPropertySet.SwApp.ActiveDoc;
              mde = md.Extension;
              fracdisp = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
            (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);
              //int den = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator,
              //  (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);
              decs = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces,
            (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);
              decd = mde.GetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
            (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified);

              try {
            mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
              (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, (int)swFractionDisplay_e.swDECIMAL);
            mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalPlaces,
              (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 3);
            mde.SetUserPreferenceInteger((int)swUserPreferenceIntegerValue_e.swUnitsLinearDecimalDisplay,
              (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, 3);
            md.ForceRebuild3(false);

            table = new swTableType.swTableType((DrawingPropertySet.SwApp.ActiveDoc as ModelDoc2),
              Redbrick.MasterHashes);
              } catch (NullReferenceException nre) {
            if (_swApp != null) {
              Redbrick.InsertBOM(_swApp);
              InitTableData();
            } else {
              throw new NullReferenceException(@"No table found.");
            }
              } catch (Exception e) {
            RedbrickErr.ErrMsg em = new RedbrickErr.ErrMsg(e);
            em.ShowDialog();
            Close();
              } finally {
            //
              }
        }
示例#29
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();
                }
            }
        }
示例#30
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            LLEDS item = (LLEDS)objLLEDSService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2         swModel = default(ModelDoc2);
            ModelDoc2         swPart  = default(ModelDoc2);
            AssemblyDoc       swAssy  = default(AssemblyDoc);
            Component2        swComp;
            Feature           swFeat        = default(Feature);
            object            configNames   = null;
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            bool   status     = false;
            string compReName = string.Empty;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc;                                                  //装配体
            string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称

            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);
            //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------
            int     stdPanelNo = (int)((item.Length - 300.5m) / 1500m);//1500+300直接做成一块
            decimal sideLength = item.Length - stdPanelNo * 1500m;
            int     ledNo      = (int)((sideLength - 300m) / 500m);

            try
            {
                //----------Top Level----------
                swModel.Parameter("D1@Distance3").SystemValue = item.Length / 1000m;
                //----------边缘板----------
                //重命名装配体内部
                compReName = "FNCL0023[LLEDS-" + tree.Module + "]{" + (int)sideLength + "}";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0023[LLEDS-]{}-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                if (status)
                {
                    swModelDocExt.RenameDocument(compReName);
                }
                swModel.ClearSelection2(true);
                status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                swModel.ClearSelection2(true);
                if (status)
                {
                    swComp = swAssy.GetComponentByName(compReName + "-2");
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Skizze1").SystemValue = sideLength / 1000m;
                    swFeat = swComp.FeatureByName("LPattern1");
                    if (ledNo > 0)
                    {
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@LPattern1").SystemValue = ledNo + 1;
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                }

                //----------标准板----------
                if (stdPanelNo > 0)
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0022[LLEDS-STD]{1483}-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0022[LLEDS-STD]{1483}-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }

                swFeat = swAssy.FeatureByName("LocalLPattern1");
                if (stdPanelNo > 1)
                {
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern1").SystemValue = stdPanelNo;
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                swModel.ForceRebuild3(true);                   //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                                //保存,很耗时间
                swApp.CloseDoc(packedAssyPath);                //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
示例#31
0
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            // Fetch current properties from the selected part(s) (i.e. ChBody in C::E)
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    //Component2 swPart = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    Component2 swPart      = swSelMgr.GetSelectedObjectsComponent3(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc2();
                    Component2 swPartcorr  = swPartModel.Extension.GetCorresponding(swPart); // ***TODO*** for instanced parts? does not work...
                    swPartcorr = swPart;                                                     // ***TODO***

                    if (swPartModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                    {
                        if (swPart.Solving == (int)swComponentSolvingOption_e.swComponentFlexibleSolving)
                        {
                            System.Windows.Forms.MessageBox.Show("Fexible assemblies not supported as ChBody (set as Rigid?)");
                            return;
                        }
                        if (swPart.Solving == (int)swComponentSolvingOption_e.swComponentRigidSolving)
                        {
                            System.Windows.Forms.MessageBox.Show("Setting props to rigid assembly as ChBody");
                            AssemblyDoc swAssemblyDoc = (AssemblyDoc)swPartModel;
                            swPart.Select(false);
                            swAssemblyDoc.EditAssembly();
                            swAssemblyDoc.EditRebuild();
                            //return;
                        }
                    }

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = null;
                    if (swPartcorr != null)
                    {
                        myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    }
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        //System.Windows.Forms.MessageBox.Show("Create data");
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPartcorr, "Chrono::ChBody_data", 0, (int)swInConfigurationOpts_e.swAllConfiguration);

                        swPartModel.ForceRebuild3(false); // needed, but does not work...
                        //swPartModel.Rebuild((int)swRebuildOptions_e.swRebuildAll); // needed but does not work...

                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityInvalid))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityInvalid!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntitySuppressed))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntitySuppressed!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityAmbiguous))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityAmbiguous!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityDeleted))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityDeleted!");
                        }
                    }

                    Set_collision_on(Convert.ToBoolean(((Parameter)myattr.GetParameter(
                                                            "collision_on")).GetDoubleValue()));
                    Set_friction(((Parameter)myattr.GetParameter(
                                      "friction")).GetDoubleValue());
                    Set_rolling_friction(((Parameter)myattr.GetParameter(
                                              "rolling_friction")).GetDoubleValue());
                    Set_spinning_friction(((Parameter)myattr.GetParameter(
                                               "spinning_friction")).GetDoubleValue());
                    Set_restitution(((Parameter)myattr.GetParameter(
                                         "restitution")).GetDoubleValue());
                    Set_collision_envelope(((Parameter)myattr.GetParameter(
                                                "collision_envelope")).GetDoubleValue());
                    Set_collision_margin(((Parameter)myattr.GetParameter(
                                              "collision_margin")).GetDoubleValue());
                    Set_collision_family((int)((Parameter)myattr.GetParameter(
                                                   "collision_family")).GetDoubleValue());



                    // fetch SW attribute with Chrono parameters for ChConveyor

                    /*
                     * SolidWorks.Interop.sldworks.Attribute myattr_conv = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conv == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  //myattr_conv = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono::ChConveyor_data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     * }
                     */
                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor (if any!)
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor != null)
                     * {
                     *  show_conveyor_params = true;
                     *
                     *  Set_conveyor_speed(((Parameter)myattr_conveyor.GetParameter(
                     *                  "conveyor_speed")).GetDoubleValue());
                     * }
                     */
                }
            }
        }
示例#32
0
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建项目模型存放地址
            string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName;

            if (!Directory.Exists(itemPath))
            {
                Directory.CreateDirectory(itemPath);
            }
            else
            {
                DialogResult result =
                    MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息",
                                    MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            //Pack的后缀
            string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6);
            //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack
            //packango后需要接收打包完成的地址,参数为后缀
            string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm";

            if (!File.Exists(packedAssyPath))
            {
                packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath);
            }

            //查询参数
            UCJDB800 item = (UCJDB800)objUCJDB800Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());

            swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令
            int warnings = 0;
            int errors   = 0;

            suffix = "_" + suffix;//后缀
            ModelDoc2         swModel = default(ModelDoc2);
            ModelDoc2         swPart  = default(ModelDoc2);
            AssemblyDoc       swAssy  = default(AssemblyDoc);
            Component2        swComp;
            Feature           swFeat        = default(Feature);
            object            configNames   = null;
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            bool   status     = false;
            string compReName = string.Empty;

            //打开Pack后的模型
            swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                     (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2;
            swAssy = swModel as AssemblyDoc;                                                  //装配体
            string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称

            swModelDocExt = (ModelDocExtension)swModel.Extension;
            //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错
            swModel.ForceRebuild3(true);
            //TopOnly参数设置成true,只重建顶层,不重建零件内部

            /*注意SolidWorks单位是m,计算是应当/1000m
             * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了
             * (int)不进行四舍五入,Convert.ToInt32会四舍五入
             */
            //-----------计算中间值,----------
            int fcNo = (int)((item.Length - item.FCSideLeft - item.FCSideRight) / 499m) - item.FCBlindNo;

            try
            {
                //----------Top Level----------
                //判断FC数量,FC侧板长度
                if (item.FCBlindNo > 0)
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1"));
                    swComp.SetSuppression2(2);                                           //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-5"));
                    swComp.SetSuppression2(2);                                           //2解压缩,0压缩
                    swFeat = swAssy.FeatureByName("LocalLPattern4");
                    swFeat.SetSuppression2(1, 2, configNames);                           //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern4").SystemValue = item.FCBlindNo; //D1阵列数量,D3阵列距离
                    swModel.Parameter("D1@Distance29").SystemValue     = item.FCSideLeft / 1000m;
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-5"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩
                    swFeat = swAssy.FeatureByName("LocalLPattern4");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }

                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "UCJ FC COMBI-12"));
                swComp.SetSuppression2(2);                                 //2解压缩,0压缩.
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "UCJ FC COMBI-15"));
                swComp.SetSuppression2(2);                                 //2解压缩,0压缩.
                swFeat = swAssy.FeatureByName("LocalLPattern3");
                swFeat.SetSuppression2(1, 2, configNames);                 //参数1:1解压,0压缩
                swModel.Parameter("D1@LocalLPattern3").SystemValue = fcNo; //D1阵列数量,D3阵列距离
                swModel.Parameter("D1@Distance35").SystemValue     = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m;

                //----------HCL----------
                if (item.LightType == "HCL")
                {
                    //灯腔
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0054-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m;
                    swFeat = swComp.FeatureByName("LIGHT T8");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("FC SUPPORT");
                    swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("FC SUPPORT B");
                    swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("JAP LED M8");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    if (item.LightCable == "LEFT")
                    {
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    else if (item.LightCable == "RIGHT")
                    {
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0069-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m;
                    swPart.Parameter("D1@LPattern1").SystemValue    = fcNo + item.FCBlindNo;
                    swPart.Parameter("D3@Sketch6").SystemValue      = (item.FCSideLeft + 250m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0071-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m;
                    swPart.Parameter("D1@LPattern1").SystemValue    = fcNo + item.FCBlindNo;
                    swPart.Parameter("D3@Sketch6").SystemValue      = (item.FCSideLeft + 250m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0116-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-3"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-4"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0145-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0161-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }
                else
                {
                    //灯腔
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0054-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-2"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0069-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0071-1"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0116-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m;
                    swFeat = swComp.FeatureByName("LIGHT T8");
                    if (item.LightType == "T8")
                    {
                        swFeat.SetSuppression2(2, 2, configNames);                         //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swFeat = swComp.FeatureByName("FC SUPPORT");
                    swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("FC SUPPORT B");
                    swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("JAP LED M8");
                    if (item.Japan == "YES")
                    {
                        swFeat.SetSuppression2(2, 2, configNames);                      //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    if (item.LightCable == "LEFT")
                    {
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    else if (item.LightCable == "RIGHT")
                    {
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-3"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-4"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0145-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m;
                    swPart.Parameter("D1@LPattern1").SystemValue    = fcNo + item.FCBlindNo;
                    swPart.Parameter("D3@Sketch6").SystemValue      = (item.FCSideLeft + 250m) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0161-2"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m;
                    swPart.Parameter("D1@LPattern1").SystemValue    = fcNo + item.FCBlindNo;
                    swPart.Parameter("D3@Sketch6").SystemValue      = (item.FCSideLeft + 250m) / 1000m;
                }
                //----------UV灯----------
                if (item.UVType == "LONG")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4S-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4L-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4S-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4L-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }
                //----------油网侧板----------
                switch (item.FCSide)
                {
                case "LEFT":
                    //重命名装配体内部
                    compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft - fcNo * 1m - 4m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-2");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 4m) / 1000m;
                    }
                    //重命名装配体内部
                    compReName = "FNCE0136[BP-" + tree.Module + ".2]{" + (int)(item.FCSideLeft - fcNo * 1m - 4m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-3");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 4m) / 1000m;
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;

                case "RIGHT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    //重命名装配体内部
                    compReName = "FNCE0109[BP-" + tree.Module + ".1]{" + (int)(item.FCSideRight - fcNo * 1m - 4m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-3");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 4m) / 1000m;
                    }
                    //重命名装配体内部
                    compReName = "FNCE0162[BP-" + tree.Module + ".2]{" + (int)(item.FCSideRight - fcNo * 1m - 4m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-4" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-4");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 4m) / 1000m;
                    }
                    break;

                case "BOTH":
                    //重命名装配体内部
                    compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft - fcNo * 1m - 2m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-2");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 2m) / 1000m;
                    }
                    //重命名装配体内部
                    compReName = "FNCE0136[BP-" + tree.Module + ".2]{" + (int)(item.FCSideLeft - fcNo * 1m - 2m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-3");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 2m) / 1000m;
                    }
                    //重命名装配体内部
                    compReName = "FNCE0109[BP-" + tree.Module + ".3]{" + (int)(item.FCSideRight - fcNo * 1m - 2m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-3");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 2m) / 1000m;
                    }
                    //重命名装配体内部
                    compReName = "FNCE0162[BP-" + tree.Module + ".4]{" + (int)(item.FCSideRight - fcNo * 1m - 2m) + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-4" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-4");
                        swComp.SetSuppression2(2);      //2解压缩,0压缩.
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 2m) / 1000m;
                    }
                    break;

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }
                //----------日本项目需要压缩零件----------
                if (item.Japan == "YES")
                {
                    //吊装垫片
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-10"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern22");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //排风脖颈
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    //排风腔
                    //重命名装配体内部
                    compReName = "FNCE0141[UCJDB800-" + tree.Module + "]{" + (int)item.Length + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0141-1") + "@" + assyName,
                                                           "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false,
                                                       0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-1");
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m;
                        swFeat = swComp.FeatureByName("EX");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("Cut-Extrude4");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTEC1");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTEC2");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTEC3");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTEC4");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("ANDTEC5");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("MA-TAB");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        if (item.MARVEL == "YES")
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                    }
                }
                else
                {
                    //吊装垫片
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-10"));
                    swComp.SetSuppression2(2);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern2");
                    swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩
                    //排风脖颈
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0019-1"));
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swFeat = swComp.FeatureByName("ANSUL");
                    if (item.ANSUL == "YES")
                    {
                        swFeat.SetSuppression2(1, 2, configNames);                      //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0020-1"));
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0047-1"));
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swFeat = swComp.FeatureByName("ANDTEC");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0048-2"));
                    swPart = swComp.GetModelDoc2();            //打开零件
                    swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m;
                    swPart.Parameter("D3@草图1").SystemValue    = item.ExHeight / 1000m;
                    swFeat = swComp.FeatureByName("ANDTEC");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    //排风腔
                    //重命名装配体内部
                    compReName = "FNCE0141[UCJDB800-" + tree.Module + "]{" + (int)item.Length + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0141-1") + "@" + assyName,
                                                           "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    if (status)
                    {
                        swModelDocExt.RenameDocument(compReName);
                    }
                    swModel.ClearSelection2(true);
                    status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false,
                                                       0, null, 0);
                    swModel.ClearSelection2(true);
                    if (status)
                    {
                        swComp = swAssy.GetComponentByName(compReName + "-1");
                        swPart = swComp.GetModelDoc2(); //打开零件
                        swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m;
                        swFeat = swComp.FeatureByName("EX");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("Cut-Extrude4");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swFeat = swComp.FeatureByName("MA-TAB");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D3@Sketch3").SystemValue = item.ExRightDis / 1000m;
                        swPart.Parameter("D1@Sketch3").SystemValue = item.ExLength / 1000m;
                        swPart.Parameter("D2@Sketch3").SystemValue = item.ExWidth / 1000m;
                        if (item.ANSUL == "YES")
                        {
                            //侧喷
                            if (item.ANSide == "LEFT")
                            {
                                swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            }
                            else if (item.ANSide == "RIGHT")
                            {
                                swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            }
                            else
                            {
                                swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                                swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            }
                            //探测器
                            swFeat = swComp.FeatureByName("ANDTEC1");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC2");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC3");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC4");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC5");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            if (item.ANDetectorNo > 0)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC1");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D3@Sketch9").SystemValue = item.ANDetectorDis1 / 1000m;
                                if (item.ANDetectorEnd == "RIGHT" ||
                                    (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 1))
                                {
                                    swPart.Parameter("D1@Sketch9").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D1@Sketch9").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 1)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC2");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D1@Sketch15").SystemValue = item.ANDetectorDis2 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 2)
                                {
                                    swPart.Parameter("D2@Sketch15").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D2@Sketch15").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 2)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC3");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D1@Sketch16").SystemValue = item.ANDetectorDis3 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 3)
                                {
                                    swPart.Parameter("D2@Sketch16").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D2@Sketch16").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 3)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC4");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D1@Sketch17").SystemValue = item.ANDetectorDis4 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 4)
                                {
                                    swPart.Parameter("D2@Sketch17").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D2@Sketch17").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 4)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC5");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D1@Sketch18").SystemValue = item.ANDetectorDis5 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 5)
                                {
                                    swPart.Parameter("D2@Sketch18").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D2@Sketch18").SystemValue = 175m / 1000m;
                                }
                            }
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("ANSULSIDE RIGHT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANSULSIDE LEFT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC1");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC2");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC3");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC4");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("ANDTEC5");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                        if (item.MARVEL == "YES")
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("MA-NTC");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                        if (item.LightCable == "LEFT")
                        {
                            swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                        else if (item.LightCable == "RIGHT")
                        {
                            swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("LIGHT HOLE LEFT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                            swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT");
                            swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                        }
                        //UV灯
                        if (item.UVType == "LONG")
                        {
                            swFeat = swComp.FeatureByName("UV L");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D5@Sketch4").SystemValue = (item.ExRightDis - 800m) / 1000m;
                            swPart.Parameter("D8@Sketch4").SystemValue = (item.ExRightDis - 600m) / 1000m;
                            swFeat = swComp.FeatureByName("UV S");
                            swFeat.SetSuppression2(0, 2, configNames);
                        }
                        else
                        {
                            swFeat = swComp.FeatureByName("UV S");
                            swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                            swPart.Parameter("D3@Sketch11").SystemValue = (item.ExRightDis - 446.5m) / 1000m;
                            swPart.Parameter("D8@Sketch11").SystemValue = (item.ExRightDis - 300m) / 1000m;
                            swFeat = swComp.FeatureByName("UV L");
                            swFeat.SetSuppression2(0, 2, configNames);
                        }
                    }
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0056-1"));
                swPart = swComp.GetModelDoc2();//打开零件
                swPart.Parameter("D1@Skizze1").SystemValue = item.Length / 1000m;

                //----------SSP灯板支撑条----------
                if (item.SSPType == "DOME")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-4"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-5"));
                    swComp.SetSuppression2(0);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-6"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-5"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m;
                    if (item.Gutter == "YES")
                    {
                        swModel.Parameter("D1@Distance27").SystemValue = item.GutterWidth / 1000m;
                        swModel.Parameter("D1@Distance36").SystemValue = item.GutterWidth / 1000m;
                    }
                    else
                    {
                        swModel.Parameter("D1@Distance27").SystemValue = 0.5m / 1000m;
                        swModel.Parameter("D1@Distance36").SystemValue = 0.5m / 1000m;
                    }
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-4"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-5"));
                    swComp.SetSuppression2(2);      //2解压缩,0压缩.
                    swPart = swComp.GetModelDoc2(); //打开零件
                    swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m;
                    if (item.Gutter == "YES")
                    {
                        swModel.Parameter("D1@Distance28").SystemValue = item.GutterWidth / 1000m;
                        swModel.Parameter("D1@Distance37").SystemValue = item.GutterWidth / 1000m;
                    }
                    else
                    {
                        swModel.Parameter("D1@Distance28").SystemValue = 0.5m / 1000m;
                        swModel.Parameter("D1@Distance37").SystemValue = 0.5m / 1000m;
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-6"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-5"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }

                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
示例#33
0
        public void generateRandomObject() //this function makes the "generate Random Object" button in the GUI work
        {
            string[] arguments = new string[variables.numVariables + constraints.numConstraints + 1];
            arguments[0] = variables.numVariables.ToString() + "," + constraints.numConstraints.ToString();
            for (int i = 0; i < variables.numVariables; i++)
            {
                arguments[i + 1] = variables.variablesName[i] + "," + variables.variablesMin[i] + "," + variables.variablesMax[i] + "," + variables.variablesType[i].ToString();
            }
            for (int i = variables.numVariables; i < variables.numVariables + constraints.numConstraints; i++)
            {
                arguments[i + 1] = constraints.constraintsEquation[i - variables.numVariables];
            }

            writeArgument(arguments);

            string[] pythonResult = runPython("randomSample.py");

            if (pythonResult == null)
            {
                return;
            }
            else if (pythonResult[1] == "false")   //If couldn't create object
            {
                sendMessageToUser("Failed to generate random object");
                return;
            }

            ModelDoc2   swModelDoc = swApp.ActiveDoc;
            EquationMgr swEqnMgr   = swModelDoc.GetEquationMgr();

            string[] csStdout = pythonResult[0].Split(',');
            for (int i = 0; i < swEqnMgr.GetCount(); i++)
            {
                if (swEqnMgr.GlobalVariable[i])
                {
                    string newEquation;

                    // Get the variable name from the swEqn

                    string[] temp = swEqnMgr.Equation[i].Split(new string[] { "=" }, StringSplitOptions.None);
                    string   name = temp[0];

                    // Get the variable unit from the swEqn

                    Regex re     = new Regex(@"([._0-9]+)([a-zA-Z]+)");
                    Match result = re.Match(temp[1]);

                    string unit = result.Groups[2].Value;

                    // Get the index of swEqn variable at variables.

                    temp = temp[0].Split('"');
                    int index = variables.indexVariable(temp[1]);
                    //string[] randomVariables;
                    if (index >= 0)
                    {
                        // No constraints

                        //string random = randomNumber(variables.variablesMax[index], variables.variablesMin[index], variables.variablesType[index]);
                        //newEquation = name + "= " + random + unit; //

                        // HAVE TO COMPARE WITH CONSTRAINTS!!!!!!

                        newEquation = name + "= " + float.Parse(csStdout[index]).ToString() + unit;

                        swEqnMgr.Equation[i] = newEquation;
                    }
                }
            }
            swModelDoc.ForceRebuild3(true);
        }