示例#1
1
 public static void DoWithSwDoc(SldWorks swApp, CompType docType, string docId, Act doWithDoc)
 {   
     var doc = swApp.IActiveDoc2;            
     var select = doc.Extension.SelectByID2(docId + "@" + doc.GetTitle(), DocCompName(docType), 0, 0, 0, true, 0, null, 0);
     if (!select) return;
     
     if (doWithDoc == Act.DoNothing)
     {
         doc.ClearSelection2(true);
         return;
     }
     switch (doWithDoc)
     {
         case Act.Delete:
             doc.EditDelete();
             break;
         case Act.DeletWithOption:
             const int deleteOption = (int)swDeleteSelectionOptions_e.swDelete_Absorbed +
                                         (int)swDeleteSelectionOptions_e.swDelete_Children;
             doc.Extension.DeleteSelection2(deleteOption);
             break;
         case Act.Unsuppress:
             doc.EditUnsuppress2();
             break;
         case Act.Suppress:
             doc.EditSuppress2();
             break;
         default:
             break;
     }
     doc.ClearSelection2(true);
 }
 public SwContext()
 {
     //var sw = Activator.GetObject(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks;
     //var sw = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
     sw = new SldWorks();
     sw.Visible = true;
 }
示例#3
0
        public JointAxis(SldWorks swApp, AssemblyDoc asm, StorageModel swData, string path, Joint current, int index, RobotModel robot)
        {
            this.swApp = swApp;
            this.asmDoc = asm;
            this.modelDoc = (ModelDoc2)asm;
            this.swData = swData;
            this.path = path;
            this.owner = current;
            this.robot = robot;

            this.AxisIndex = index;

            if (EffortLimit == 0)
            {
                this.EffortLimit = 1;
            }
            if (this.VelocityLimit == 0)
            {
                this.VelocityLimit = 1;
            }

            if (Axis != null)
            {
                CalcAxisVectors();
                //CalcLimits(null);
            }
            if (index == 2)
            {
                IsContinuous = true;
            }
        }
        /// <summary>
        /// Creates a new joint editor proptery manager page that allows the user to edit joint properties.
        /// </summary>
        /// <param name="robot">Active robot model</param>
        /// <param name="joint">Joint to be edited</param>
        /// <param name="document">Active assembly document</param>
        /// <param name="swApp">Solidworks application environment</param>
        public JointPMPage(RobotModel robot, Joint joint, AssemblyDoc document, SldWorks swApp)
        {
            //Validate parameters
            if (robot == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null robot model.");
            if (document == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null assembly document.");
            if (swApp == null)
                throw new ProgramErrorException("Tried to create a JointPMPage with a null solidworks application interface.");

            //Initialize fields
            this.robot = robot;
            this.swApp = swApp;
            currentJoint = joint;
            mathUtil = ((IMathUtility)swApp.GetMathUtility());

            //AssemblyDoc inherits ModelDoc2 but the relationship dosn't carry through the COM interface
            //Having two fields prevents having to cast half of the time
            modelDoc = (ModelDoc2)document;
            assemblyDoc = document;

            //Setup the page, its controls and their visual layout
            SetupPage();

            SelectionObservers = new List<SelectionObserver>();
            ButtonObservers = new List<ButtonObserver>();
            CheckboxObservers = new List<CheckboxObserver>();
        }
示例#5
0
 void SetPAram(SldWorks swApp)
 {
     //var doc = swApp.IActiveDoc2;
     //swDoc.Extension.SelectByID2("D1@Кривая16@" + nameDownPanel + "-1@" + nameAsm, "DIMENSION", 0, 0, 0, false, 0, null, 0);
     //((Dimension)(swDoc.Parameter("D1@Кривая16@" + nameDownPanel + ".Part"))).SystemValue = zaklHeight == 1 ? 2 : zaklHeight;
     //swDoc.EditRebuild3();
 }
        public static void Init(SldWorks SldWks)
        {
            try
            {
                foreach (String F in Directory.GetFiles(_DOSSIER, _FICHIER_BASE + "*", SearchOption.TopDirectoryOnly))
                {
                    File.Delete(F);
                }

                _CHEMIN_FICHIER = Path.Combine(_DOSSIER, _FICHIER_BASE + "-" + _NO_FICHIER.ToString() + ".txt");
                StreamWriter pFichierDebug = new StreamWriter(_CHEMIN_FICHIER, false, System.Text.Encoding.Unicode);

                /// A chaque initialisation, on inscrit la version de SW
                String pVersionDeBase; String pVersionCourante; String pHotfixe;
                SldWks.GetBuildNumbers2(out pVersionDeBase, out pVersionCourante, out pHotfixe);
                String pRevision = SldWks.RevisionNumber();
                pFichierDebug.WriteLine("\n ");
                pFichierDebug.WriteLine("====================================================================================================");
                pFichierDebug.WriteLine("|                                                                                                  |");
                pFichierDebug.WriteLine("|                                       SOLIDWORKS DEBUG                                           |");
                pFichierDebug.WriteLine("|                                                                                                  |");
                pFichierDebug.WriteLine("====================================================================================================");
                pFichierDebug.WriteLine("Version de base : " + pVersionDeBase + "    Version courante : " + pVersionCourante + "    Hotfixe : " + pHotfixe + "    Revision : " + pRevision);
                pFichierDebug.WriteLine("----------------------------------------------------------------------------------------------------");
                pFichierDebug.WriteLine("\n ");

                pFichierDebug.Close();
            }
            catch
            {
                _INIT = false;
            }
        }
示例#7
0
        static void Main(string[] args) {
            swApp = new SldWorks();
            ExtractTree();

            System.Console.WriteLine("Extraction finished!");
            System.Console.ReadKey();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="iSwApp">Solidworks app</param>
        /// <param name="asm">The assembly document the export takes place in</param>
        public STLExporter(SldWorks iSwApp, AssemblyDoc asm)
        {
            this.iSwApp = iSwApp;
            this.asm = asm;

            saveUserPreferences();
            setSTLExportPreferences();
        }
        public DrawingRedbrick(SldWorks sw)
        {
            this._swApp = sw;
              InitializeComponent();

              this.PropertySet = new DrawingProperties(this._swApp);
              this.RevSet = new DrawingRevs(this._swApp);
              DrbUpdate();
              t();
        }
 public CutlistHeaderInfo(DrawingProperties dp, string descr, SldWorks swapp)
 {
     _swApp = swapp;
       InitializeComponent();
       SetLWHVisibility(Properties.Settings.Default.CHIHideLWH);
       DrawingPropertySet = dp;
       CutlistData = dp.CutlistData;
       Location = Properties.Settings.Default.CutlistHeaderLocation;
       Size = Properties.Settings.Default.CutlistHeaderSize;
       description = descr;
       InitControlsWithDrawing();
 }
        /// <summary>
        /// Creates a new Specific Joint object
        /// </summary>
        /// <param name="joint">The joint that this joint is in</param>
        /// <param name="path">The storage path for this joint</param>
        protected JointSpecifics(Joint joint, string path)
        {
            this.robot = RobotInfo.Robot;
            this.joint = joint;
            this.swApp = RobotInfo.SwApp;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;

            OriginValues = new OriginPoint();
            if(OriginPt != null)
                OriginValues.Point = GetPointFromEntity(OriginPt);
        }
        public AssemblyContext(string assemblyPath)
        {
            //var sw = Activator.GetObject(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks;
            //var sw = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
            sw = new SldWorks();
            sw.Visible = true;
            workingFolder = Path.GetDirectoryName(assemblyPath);
            sw.SetCurrentWorkingDirectory(workingFolder);

            var filePath = assemblyPath;

            doc = sw.OpenDoc6(filePath,
                (int)swDocumentTypes_e.swDocASSEMBLY,
                (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                ref error, ref warning);

            drag = (DragOperator)((AssemblyDoc)doc).GetDragOperator();
            math = (MathUtility)sw.GetMathUtility();
        }
示例#13
0
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            //System.Windows.Forms.MessageBox.Show("Add-in: ConnectToSW");
            try
            {
            mSWApplication = (SldWorks)ThisSW;
            mSWCookie = Cookie;
            bool result = mSWApplication.SetAddinCallbackInfo(0, this, Cookie);

            // Attributes register

            defattr_chbody = (AttributeDef)mSWApplication.DefineAttribute("chrono::ChBody");
            defattr_chbody.AddParameter("friction",             (int)swParamType_e.swParamTypeDouble, 0.6, 0);
            defattr_chbody.AddParameter("rolling_friction",     (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("spinning_friction",    (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("restitution",          (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.AddParameter("collision_on",         (int)swParamType_e.swParamTypeDouble, 1, 0);
            defattr_chbody.AddParameter("collision_margin",     (int)swParamType_e.swParamTypeDouble, 0.01, 0);
            defattr_chbody.AddParameter("collision_envelope",   (int)swParamType_e.swParamTypeDouble, 0.03, 0);
            defattr_chbody.AddParameter("collision_family",     (int)swParamType_e.swParamTypeDouble, 0, 0);
            defattr_chbody.Register();
            /*
            defattr_chconveyor = (AttributeDef)moSWApplication.DefineAttribute("chrono::ChConveyor");
            defattr_chconveyor.AddParameter("conveyor_speed",   (int)swParamType_e.swParamTypeDouble, 1.0, 0);
            defattr_chconveyor.Register();
            */

            // Register the taskpane
            this.UISetup();

            // Event register: here is an example of how to do...
            SldWorks moSWApplication = (SldWorks)mSWApplication;
            moSWApplication.ActiveDocChangeNotify += new DSldWorksEvents_ActiveDocChangeNotifyEventHandler(test_event_ActiveDocChangeNotify);
            moSWApplication.ActiveModelDocChangeNotify += new DSldWorksEvents_ActiveModelDocChangeNotifyEventHandler(test_event_ActiveModelDocChangeNotify);
            }
            catch (Exception ex)
            {
            System.Windows.Forms.MessageBox.Show("ConnectToSW failed! " + ex.Message);
            }

            return true;
        }
示例#14
0
        /// <summary>
        /// Constructs a new IJointAxis
        /// </summary>
        /// <param name="path">Path to this joint's storage</param>
        /// <param name="current">The joint that this axis is contained in</param>
        public IJointAxis(string path, Joint current)
        {
            this.swApp = RobotInfo.SwApp;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;
            this.owner = current;
            this.robot = RobotInfo.Robot;

            if (EffortLimit == 0)
            {
                this.EffortLimit = 1;
            }

            if (Axis != null)
            {
                CalcAxisVector();
            }
            mathUtil = (MathUtility)swApp.GetMathUtility();
        }
        public static IDisposable Setup(SldWorks swApp)
        {
            if (swApp == null)
                throw new ArgumentNullException(nameof(swApp));

            if (Interlocked.CompareExchange(ref _isInitialized, 1, 0) == 1) return Disposable.Empty;

            var d0 = swApp
                .DoWithOpenDoc(modelDoc =>
                {
                    if (!modelDoc.Visible)
                        return Disposable.Empty;

                    var modelView = (ModelView) modelDoc.GetFirstModelView();
                    Lookup.GetOrAdd(modelDoc, mv => new OpenGlRenderer(modelView));

                    return Disposable.Create(() =>
                    {
                        OpenGlRenderer openGlRenderer;
                        if (Lookup.TryRemove(modelDoc, out openGlRenderer))
                        {
                            openGlRenderer.Dispose();
                        }
                    });
                });

            var d1 = Disposable.Create(() =>
            {
                foreach (var modelView in Lookup.Keys)
                {
                    OpenGlRenderer openGlRenderer;
                    Lookup.TryRemove(modelView, out openGlRenderer);
                    openGlRenderer.Dispose();
                }
                Debug.Assert(Lookup.IsEmpty);
            });

            return new CompositeDisposable(d0, d1);
        }
示例#16
0
        /// <summary>
        /// Creates a new joint
        /// </summary>
        /// <param name="path">Path to this joint in the StorageModel</param>
        /// <param name="owner">The Link that owns this joint (child Link in the joint)</param>
        public Joint(string path, Link parent, Link child)
        {
            this.swApp = RobotInfo.SwApp;
            this.asmDoc = RobotInfo.AssemDoc;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;
            this.robot = RobotInfo.Robot;
            this.Parent = parent;
            Parent.ChildJoints.Add(this);
            this.Child = child;
            this.Selected = false;
            this.Type = JointFactory.DefaultJointType;

            RobotInfo.WriteToLogFile("Getting Joint Specifics (Joint)");
            jointSpecifics = JointFactory.GetSpecificJoint(Type,path,this);
            RobotInfo.WriteToLogFile("Successfully created Joint Specifics (Joint)");

            if (swData.GetDouble(path) == 0)
            {
                swData.SetDouble(path, 1);
            }
        }
示例#17
0
 /// <summary>
 /// Define this.SwApp, then use it to write on the active document.
 /// </summary>
 /// <param name="sw">SwApp</param>
 public void Write(SldWorks sw)
 {
     if (sw != null) {
     SwApp = sw;
     Write();
       } else {
     if (SwApp != null)
       Write();
       }
 }
示例#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);
            }

            //查询参数
            DP340 item = (DP340)objDP340Service.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----------

                //----------侧板----------
                switch (item.SidePanel)
                {
                case "LEFT":
                case "DPBACKL":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0017-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0019-10"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0018-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0019-11"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

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

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

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0017-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0019-10"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0018-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0019-11"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }

                //----------NOCJ腔主体----------
                //重命名装配体内部
                compReName = "FNCS0015[DP340-" + tree.Module + "]{" + (int)item.Length + "}";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCS0015-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的使用
            }
        }
        //public class JsonNodeConverter : CustomCreationConverter<KLgraph.KLnode>
        //{
        //    public override KLgraph.KLnode Create(Type objectType)
        //    {
        //        throw new NotImplementedException();
        //    }

        //    public KLgraph.KLnode Create(Type objectType, JObject jObject)
        //    {
        //        var type = (string) jObject.Property("valueType");
        //        switch (type)
        //        {
        //            case "int":
        //                return new KLgraph.KLnodePart();
        //            case "string":
        //                return new KLgraph.KLnodeAssembly();
        //        }

        //        throw new ApplicationException(String.Format("The given vehicle type {0} is not supported!", type));
        //    }

        //    public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
        //        JsonSerializer serializer)
        //    {
        //        // Load JObject from stream
        //        JObject jObject = JObject.Load(reader);

        //        // Create target object based on JObject
        //        var target = Create(objectType, jObject);

        //        // Populate the object properties
        //        serializer.Populate(jObject.CreateReader(), target);

        //        return target;
        //    }
        //}

        public static bool ReadJsonModel(string jsonFile, ref AdjacencyGraph <KLgraph.KLnode, KLgraph.KLedge> graph, SldWorks swApplication)
        {
            Type[] runtimeTypes             = new Type[] { typeof(KLgraph.KLedgeJoint), typeof(KLgraph.KLedgeContact), typeof(KLgraph.KLedgeStructure) };
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                TypeNameHandling       = TypeNameHandling.All,
                TypeNameAssemblyFormat = FormatterAssemblyStyle.Full,
                Binder = new Serialization.binder(runtimeTypes)
            };
            var deserializedGraph = JsonConvert.DeserializeObject <KLgraph.Graph>(jsonFile, settings);


            graph.Clear();
            graph.AddVertexRange(deserializedGraph.Nodes);
            graph.AddEdgeRange(deserializedGraph.Edges);

            if (deserializedGraph.Edges == null)
            {
                swApplication.SendMsgToUser("DelegateNode graph nulli");
                return(false);
            }
            if (graph == null)
            {
                swApplication.SendMsgToUser("Comparison nullo");
                return(false);
            }

            return(true);
        }
示例#20
0
        internal static HelperResult ImportProperties(SldWorks swApp, BindingSource bindingSource,
                                                      string path, string configName = "")
        {
            Console.WriteLine("Import: path={0}, config={1}", path, configName);


            if (swApp == null)
            {
                return(HelperResult.SLDWORKS_NOT_RUNNING);
            }

            string            ext = Path.GetExtension(path);
            swDocumentTypes_e type;

            if (ext.ToLower().Contains("sldprt"))
            {
                type = swDocumentTypes_e.swDocPART;
            }
            else if (ext.ToLower().Contains("sldasm"))
            {
                type = swDocumentTypes_e.swDocASSEMBLY;
            }
            else if (ext.ToLower().Contains("slddrw") && string.IsNullOrEmpty(configName))
            {
                type = swDocumentTypes_e.swDocDRAWING;
            }
            else
            {
                return(HelperResult.WRONG_ARG);
            }


            int       Error   = 0;
            int       Warning = 0;
            ModelDoc2 doc;


            // checking if the document is open
            if (((ModelDoc2)swApp.ActiveDoc) != null && ((ModelDoc2)swApp.ActiveDoc).GetPathName().ToLower() == path.ToLower())
            {
                doc = (ModelDoc2)swApp.ActiveDoc;
            }
            else
            {
                doc = swApp.OpenDoc6(path, (int)type, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, configName, ref Error, ref Warning);
            }

            if (Error != 0)
            {
                return(HelperResult.OPEN_ERROR);
            }

            CustomPropertyManager manager = doc.Extension.CustomPropertyManager[configName];

            if (manager == null)
            {
                return(HelperResult.OPEN_ERROR);
            }

            string[] names = manager.GetNames();

            if (names == null || !names.Any())
            {
                return(HelperResult.NOT_EXIST);
            }

            BindingList <PropertyObject> list = new BindingList <PropertyObject>();

            foreach (string field in names)
            {
                PropertyObject obj = new PropertyObject();

                obj.FieldName = field;
                int ret = manager.Get6(field, true, out string ValOut, out string ResolvedValOut, out bool WasResolved, out bool LinkToProperty);

                if (ret == (int)swCustomInfoGetResult_e.swCustomInfoGetResult_NotPresent)
                {
                    continue;
                }

                obj.Value = ValOut;
                list.Add(obj);
            }

            if (!list.Any())
            {
                return(HelperResult.NOT_EXIST);
            }

            bindingSource.Clear();
            bindingSource.DataSource = list;

            return(HelperResult.SUCCESS);
        }
示例#21
0
        static void Main(string[] args)
        {
            ISldWorks swApp;

            try {
                var progId = "SldWorks.Application";
                swApp = Marshal2.GetActiveObject(progId) as ISldWorks;
            } catch (COMException e) {
                swApp         = new SldWorks();
                swApp.Visible = true;
            }

            // If file paths aren't correctly specified, warn the user and exit
            if (args.Length != 2)
            {
                Console.Error.Write("Incorrect number of arguments");
                return;
            }

            string ext = Path.GetExtension(args[0]);

            if (ext != Path.GetExtension(args[1]))
            {
                Console.Error.Write("File types don't match");
                return;
            }

            int filetype_int;

            switch (ext)
            {
            case ".SLDPRT":
                filetype_int = 1;                         // swDocPART
                break;

            case ".SLDASM":
                filetype_int = 2;                         // swDocASSEMBLY
                break;

            default:
                filetype_int = 0;                         // swDocNONE
                break;
            }

            int openDocOptions = 1;             // swOpenDocOptions_Silent
            int fileError      = 0;
            int fileWarning    = 0;

            // open the second window first to tile properly
            swApp.OpenDoc6(
                args[1],                          // FileName
                filetype_int,                     // Type
                openDocOptions,                   // Options
                "",                               // Configuration
                ref fileError,                    // Errors
                ref fileWarning                   // Warnings
                );
            if (fileError != 0)
            {
                Console.Error.Write("Encountered error opening file: "
                                    + fileError.ToString());
            }
            else if (fileWarning != 0)
            {
                Console.WriteLine("Encountered warning opening file: "
                                  + fileWarning.ToString());
            }
            swApp.OpenDoc6(
                args[0],                          // FileName
                filetype_int,                     // Type
                openDocOptions,                   // Options
                "",                               // Configuration
                ref fileError,                    // Errors
                ref fileWarning                   // Warnings
                );
            if (fileError != 0)
            {
                Console.Error.Write("Encountered error opening file: "
                                    + fileError.ToString());
            }
            else if (fileWarning != 0)
            {
                Console.WriteLine("Encountered warning opening file: "
                                  + fileWarning.ToString());
            }
            // Arrange Windows to vertical tiling
            swApp.ArrangeWindows(2);
        }
示例#22
0
 void StartSolidWorks(bool visible = true)
 {
     sw         = new SldWorks();
     sw.Visible = visible;
 }
        public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath)
        {
            //创建下料图文件夹,默认在D盘MyProjects目录下(先判断文件夹是否存在)
            string dxfPath = projectPath + @"\DXF-CUTLIST";

            if (!Directory.Exists(dxfPath))
            {
                Directory.CreateDirectory(dxfPath);
            }
            //创建dxf图文件夹
            string newPath = dxfPath + @"\" + tree.Item + "-" + tree.Module + @"\";

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }
            //拷贝文件,调用通用函数
            if (!CommonFunc.CopyDxfFiles(tree.ModelPath, newPath))
            {
                return;
            }
            //查询参数
            LFUMC250DXF objLFUMC250DXF = (LFUMC250DXF)objLFUMC250DXFService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString());
            //查询标准DxfCutlist,根据item.categoryId查询dxfCutList对象列表
            List <DXFCutList> oldList = objDxfCutListService.GetDXFCutListsByCategoryId(tree.CategoryId.ToString());

            Project objProject = objProjectService.GetProjectByProjectId(tree.ProjectId.ToString());

            #region HoodCutList
            if (objProject.HoodType == "Hood")
            {
                //乘以数量,赋值moduletreeid
                foreach (var item in oldList)
                {
                    hoodCutLists.Add(new HoodCutList()
                    {
                        ModuleTreeId    = objLFUMC250DXF.ModuleTreeId,
                        PartDescription = item.PartDescription,
                        Length          = item.Length,
                        Width           = item.Width,
                        Thickness       = item.Thickness,
                        Quantity        = item.Quantity * objLFUMC250DXF.Quantity,//多个UCP
                        Materials       = item.Materials,
                        PartNo          = item.PartNo,
                        UserId          = 1
                    });
                }
                //基于事务hoodCutLists提交SQLServer
                if (hoodCutLists.Count == 0)
                {
                    return;
                }
                try
                {
                    if (objHoodCutListService.ImportCutList(hoodCutLists))
                    {
                        hoodCutLists.Clear();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("LFUMC250DXF的HoodCutlist导入数据库失败" + ex.Message);
                }
            }
            #endregion


            #region CeilingCutList

            if (objProject.HoodType == "Ceiling")
            {
                //添加SubAssy,获得SubAssyId
                int subAssyId = objSubAssyService.AddSubAssy(new SubAssy()
                {
                    ProjectId   = objProject.ProjectId,
                    SubAssyName = tree.Module
                });
                //乘以数量,赋值moduletreeid
                foreach (var item in oldList)
                {
                    ceilingCutLists.Add(new CeilingCutList()
                    {
                        SubAssyId       = subAssyId,
                        PartDescription = item.PartDescription,
                        Length          = item.Length,
                        Width           = item.Width,
                        Thickness       = item.Thickness,
                        Quantity        = item.Quantity * objLFUMC250DXF.Quantity,//多个UCP
                        Materials       = item.Materials,
                        PartNo          = item.PartNo,
                        UserId          = 1
                    });
                }
                //基于事务CeilingCutLists提交SQLServer
                if (ceilingCutLists.Count == 0)
                {
                    return;
                }
                try
                {
                    if (objCeilingCutListService.ImportCutList(ceilingCutLists))
                    {
                        ceilingCutLists.Clear();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("LFUMC250DXF的CeilingCutlist导入数据库失败" + ex.Message);
                }
            }
            #endregion
        }
示例#24
0
        private const string ШаблонЧертежаРазверткиВнеХранилища = "flattpattern.drwdot";//@"C:\flattpattern.drwdot";

        public void CreateFlattPatternUpdateCutlistAndEdrawing()
        {
            #region Сбор информации по детали и сохранение разверток

            //SldWorks swApp = null;
            try
            {
                var swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
                swApp = new SldWorks {
                    Visible = true
                };

                IModelDoc2 swModel = swApp.IActiveDoc2;
                swModel.Extension.ViewDisplayRealView = false;

                if (!IsSheetMetalPart((IPartDoc)swModel))
                {
                    MessageBox.Show("Деталь не из листового материала");
                }

                string[] swModelConfNames;


                var activeconfiguration = (Configuration)swModel.GetActiveConfiguration();
                swModelConfNames = (string[])swModel.GetConfigurationNames();


                var swModelConfNames2 = (string[])swModel.GetConfigurationNames();

                try
                {
                    foreach (var configName in from name in swModelConfNames2
                             let config = (Configuration)swModel.GetConfigurationByName(name)
                                          where !config.IsDerived()
                                          select name)
                    {
                        swModel.ShowConfiguration2(configName);
                        swModel.EditRebuild3();

                        FileInfo template = null;

                        try
                        {
                            template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища);
                            //MessageBox.Show(template.FullName);

                            Thread.Sleep(1000);
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.ToString());
                            template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища);
                            Thread.Sleep(1000);
                        }
                        finally
                        {
                            if (template == null)
                            {
                                template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища);
                            }
                        }

                        //MessageBox.Show(template.FullName);

                        var swDraw = (DrawingDoc)swApp.INewDocument2(template.FullName, (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594);

                        swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, false);

                        ((IModelDoc2)swDraw).ForceRebuild3(true);


                        #region  азгибание всех сгибов

                        try
                        {
                            swModel.EditRebuild3();
                            var swPart = (IPartDoc)swModel;

                            Feature      swFeature = swPart.FirstFeature();
                            const string strSearch = "FlatPattern";
                            while (swFeature != null)
                            {
                                var nameTypeFeature = swFeature.GetTypeName2();

                                if (nameTypeFeature == strSearch)
                                {
                                    swFeature.Select(true);
                                    swPart.EditUnsuppress();

                                    Feature swSubFeature = swFeature.GetFirstSubFeature();
                                    while (swSubFeature != null)
                                    {
                                        var nameTypeSubFeature = swSubFeature.GetTypeName2();

                                        if (nameTypeSubFeature == "UiBend")
                                        {
                                            swFeature.Select(true);
                                            swPart.EditUnsuppress();
                                            swModel.EditRebuild3();

                                            try
                                            {
                                                swSubFeature.SetSuppression2(
                                                    (int)swFeatureSuppressionAction_e.swUnSuppressFeature,
                                                    (int)swInConfigurationOpts_e.swAllConfiguration,
                                                    swModelConfNames2);
                                            }
                                            catch (Exception) {}
                                        }
                                        swSubFeature = swSubFeature.GetNextSubFeature();
                                    }
                                }
                                swFeature = swFeature.GetNextFeature();
                            }
                            swModel.EditRebuild3();
                        }

                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message);
                        }

                        #endregion

                        swModel.ForceRebuild3(false);

                        var thikness = GetFromCutlist(swModel, "Толщина листового металла");

                        var errors   = 0;
                        var warnings = 0;
                        var newDxf   = (IModelDoc2)swDraw;
                        try
                        {
                            Directory.CreateDirectory("C:\\Dxf\\");
                        }
                        catch (Exception) {}

                        newDxf.Extension.SaveAs(
                            "C:\\Dxf\\" + Path.GetFileNameWithoutExtension(swModel.GetPathName()) + "-" + configName + "-" + thikness + ".dxf",
                            (int)swSaveAsVersion_e.swSaveAsCurrentVersion,
                            (int)swSaveAsOptions_e.swSaveAsOptions_UpdateInactiveViews, null, ref errors, ref warnings);

                        swApp.CloseDoc(Path.GetFileName(newDxf.GetPathName()));
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }

                try
                {
                    swModel.ShowConfiguration2(activeconfiguration.Name);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }

                #endregion
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
示例#25
0
        public static void MyVisualOutput_ComposedPatterns(List <MyComposedPattern> listOfOutputComposedPattern,
                                                           List <MyComposedPattern> listOfOutputComposedPatternTwo, SldWorks mySwApplication, ModelDoc2 SwModel)
        {
            SwModel.ClearSelection2(true);
            //SwModel.Insert3DSketch();

            int      nOfPatterns = 0;
            var      tolerance   = Math.Pow(10, -4);
            MyVertex headCentroidPattern;
            MyVertex backCentroidPattern;

            foreach (var composedPattern in listOfOutputComposedPattern)
            {
                nOfPatterns         = composedPattern.listOfMyPattern.Count;
                headCentroidPattern = composedPattern.listOfMyPattern[0].patternCentroid;
                backCentroidPattern = composedPattern.listOfMyPattern[nOfPatterns - 1].patternCentroid;
                if (composedPattern.pathOfMyComposedPattern.GetType() == typeof(MyLine))
                {
                    SwModel.GetActiveSketch2();
                    SwModel.CreateLine2(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                        backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z);
                }
                else //typeof(MyCircumForPath)
                {
                    var pathObject   = (MyCircumForPath)composedPattern.pathOfMyComposedPattern;
                    var circumCenter = pathObject.circumcenter;
                    //SwModel.CreateArc2(pathObject.circumcenter.x, pathObject.circumcenter.y, pathObject.circumcenter.z,
                    //    headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                    //    backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z, -1);   //o +1?

                    if (
                        Math.Abs(headCentroidPattern.Distance(backCentroidPattern) -
                                 composedPattern.constStepOfMyComposedPattern) < tolerance)
                    {
                        //SwModel.ClearSelection2(true);
                        SwModel.Insert3DSketch();
                        SwModel.GetActiveSketch2();
                        SwModel.CreateCircle2(circumCenter.x, circumCenter.y, circumCenter.z,
                                              headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z);
                        //SwModel.InsertSketch();
                    }
                    else
                    {
                        //SwModel.ClearSelection2(true);
                        //SwModel.Insert3DSketch();
                        SwModel.GetActiveSketch2();
                        SwModel.Create3PointArc(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                                backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z,
                                                composedPattern.listOfMyPattern[1].patternCentroid.x,
                                                composedPattern.listOfMyPattern[1].patternCentroid.y,
                                                composedPattern.listOfMyPattern[1].patternCentroid.z);
                        //SwModel.InsertSketch();
                    }
                }
            }

            foreach (var composedPattern in listOfOutputComposedPatternTwo)
            {
                headCentroidPattern = composedPattern.listOfMyPattern[0].patternCentroid;
                backCentroidPattern = composedPattern.listOfMyPattern[1].patternCentroid;
                SwModel.GetActiveSketch2();
                SwModel.CreateLine2(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                    backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z);
            }
            SwModel.InsertSketch();

            #region esempio linea funzionante
            //ModelDoc2 SwModel = mySwApplication.ActiveDoc;
            //SwModel.ClearSelection2(true);
            //SwModel.Insert3DSketch();
            //SwModel.GetActiveSketch2();
            //SwModel.CreateLine2(0, 0, 0, 0, 0.1, 0.1);

            //SwModel.InsertSketch();
            #endregion
        }
示例#26
0
        //public static IEdmObject5 GetObject(IEdmVault12 vault, int objectId, EdmObjectType objectType)
        //{
        //    try
        //    {
        //        var obj = vault.GetObject(objectType, objectId);
        //        return obj;
        //    }
        //    catch (Exception e)
        //    {
        //        Console.WriteLine("Ошибка в процедуре  public static IEdmObject5 GetObject {0}:", e);
        //    }
        //    foreach (EdmObjectType enumObjectType in Enum.GetValues(typeof(EdmObjectType)))
        //    {
        //        try
        //        {
        //            var obj = vault.GetObject(enumObjectType, objectId);
        //            return obj;
        //        }
        //        catch (Exception e)
        //        {
        //            Console.WriteLine("Ошибка в процедуре  public static IEdmObject5 GetObject {0}:", e);
        //        }
        //    }
        //    //nothing found
        //    return null;
        //}

        static void CreateFlattPatternUpdateCutlist(string filePath, bool savedxf)
        {
            //var vault1 = new EdmVault5();
            //IEdmFolder5 oFolder;
            //vault1.LoginAuto("Vents-PDM", 0);
            //var edmFile5 = vault1.GetFileFromPath("D:\\Vents-PDM\\Библиотека проектирования\\Templates\\flattpattern.drwdot", out oFolder);
            //edmFile5.GetFileCopy(0, 0, oFolder.ID, (int)EdmGetFlag.EdmGet_Simple);

            try
            {
                SwApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            }
            catch (Exception)
            {
                SwApp = new SldWorks {
                    Visible = true
                };
            }
            if (SwApp == null)
            {
                return;
            }

            var swModel = SwApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART,
                                         (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0);

            SwApp.SetUserPreferenceStringValue(((int)(swUserPreferenceStringValue_e.swFileLocationsDocumentTemplates)), "D:\\Vents-PDM\\Библиотека проектирования\\Templates\\");
            try
            {
                if (!IsSheetMetalPart((IPartDoc)swModel))
                {
                    SwApp.CloseDoc(swModel.GetTitle());
                    return;
                }
            }
            catch (Exception)
            {
                return;
            }

            var activeconfiguration = (Configuration)swModel.GetActiveConfiguration();

            var swModelConfNames = (string[])swModel.GetConfigurationNames();

            foreach (var name in from name in swModelConfNames
                     let config = (Configuration)swModel.GetConfigurationByName(name)
                                  where config.IsDerived()
                                  select name)
            {
                swModel.DeleteConfiguration(name);
            }

            var swModelDocExt     = swModel.Extension;
            var swModelConfNames2 = (string[])swModel.GetConfigurationNames();

            // Проход по всем родительским конфигурациям (т.е. - конфигурациям деталей)


            var dataList = new List <DataToExport>();

            foreach (var configName in from name in swModelConfNames2
                     let config = (Configuration)swModel.GetConfigurationByName(name)
                                  where !config.IsDerived()
                                  select name)
            {
                swModel.ShowConfiguration2(configName); swModel.EditRebuild3();

                var confiData = new DataToExport {
                    Config = configName
                };
                var swDraw =
                    (DrawingDoc)SwApp.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateA0size, "D:\\Vents-PDM\\Библиотека проектирования\\Templates\\flattpattern.drwdot",// "D:\\Vents-PDM\\Библиотека проектирования\\Templates\\flattpattern.drwdot",
                                                  (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594);
                swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, true);
                swModel.ForceRebuild3(false);

                var    swCustProp = swModelDocExt.CustomPropertyManager[configName];
                string valOut;

                string codMaterial;
                swCustProp.Get4("Код материала", true, out valOut, out codMaterial);
                confiData.КодМатериала = codMaterial;

                string материал;
                swCustProp.Get4("Материал", true, out valOut, out материал);
                confiData.Материал = материал;

                string обозначение;
                swCustProp.Get4("Обозначение", true, out valOut, out обозначение);
                confiData.Обозначение = обозначение;

                var    swCustPropForDescription = swModelDocExt.CustomPropertyManager[""];
                string наименование;
                swCustPropForDescription.Get4("Наименование", true, out valOut, out наименование);
                confiData.Наименование = наименование;


                if (savedxf)
                {
                    var newDxf = (IModelDoc2)swDraw;
                    SwApp.CloseDoc(newDxf.GetPathName());
                }
                else
                {
                    var newDxf = (IModelDoc2)swDraw;
                    SwApp.CloseDoc(newDxf.GetTitle());
                }

                //UpdateCustomPropertyListFromCutList
                const string длинаГраничнойРамкиName     = "Длина граничной рамки";
                const string ширинаГраничнойРамкиName    = "Ширина граничной рамки";
                const string толщинаЛистовогоМеталлаNAme = "Толщина листового металла";
                const string сгибыName           = "Сгибы";
                const string площадьПокрытияName = "Площадь покрытия";

                Feature swFeat2 = swModel.FirstFeature();
                while (swFeat2 != null)
                {
                    if (swFeat2.GetTypeName2() == "SolidBodyFolder")
                    {
                        BodyFolder swBodyFolder = swFeat2.GetSpecificFeature2();
                        swFeat2.Select2(false, -1);
                        swBodyFolder.SetAutomaticCutList(true);
                        swBodyFolder.UpdateCutList();

                        Feature swSubFeat = swFeat2.GetFirstSubFeature();
                        while (swSubFeat != null)
                        {
                            if (swSubFeat.GetTypeName2() == "CutListFolder")
                            {
                                BodyFolder bodyFolder = swSubFeat.GetSpecificFeature2();
                                swSubFeat.Select2(false, -1);
                                bodyFolder.SetAutomaticCutList(true);
                                bodyFolder.UpdateCutList();
                                var swCustPrpMgr = swSubFeat.CustomPropertyManager;
                                swCustPrpMgr.Add("Площадь поверхности", "Текст", "\"SW-SurfaceArea@@@Элемент списка вырезов1@" + Path.GetFileName(swModel.GetPathName()) + "\"");

                                string длинаГраничнойРамки;
                                swCustPrpMgr.Get4(длинаГраничнойРамкиName, true, out valOut, out длинаГраничнойРамки);
                                swCustProp.Set(длинаГраничнойРамкиName, длинаГраничнойРамки);
                                confiData.ДлинаГраничнойРамки = длинаГраничнойРамки;

                                string ширинаГраничнойРамки;
                                swCustPrpMgr.Get4(ширинаГраничнойРамкиName, true, out valOut, out ширинаГраничнойРамки);
                                swCustProp.Set(ширинаГраничнойРамкиName, ширинаГраничнойРамки);
                                confiData.ШиринаГраничнойРамки = ширинаГраничнойРамки;

                                string толщинаЛистовогоМеталла;
                                swCustPrpMgr.Get4(толщинаЛистовогоМеталлаNAme, true, out valOut, out толщинаЛистовогоМеталла);
                                swCustProp.Set(толщинаЛистовогоМеталлаNAme, толщинаЛистовогоМеталла);
                                confiData.ТолщинаЛистовогоМеталла = толщинаЛистовогоМеталла;

                                string сгибы;
                                swCustPrpMgr.Get4(сгибыName, true, out valOut, out сгибы);
                                swCustProp.Set(сгибыName, сгибы);
                                confiData.Сгибы = сгибы;

                                string площадьПоверхности;
                                swCustPrpMgr.Get4("Площадь поверхности", true, out valOut, out площадьПоверхности);
                                swCustProp.Set(площадьПокрытияName, площадьПоверхности);
                                confiData.ПлощадьПокрытия = площадьПоверхности;
                            }
                            swSubFeat = swSubFeat.GetNextFeature();
                        }
                    }
                    swFeat2 = swFeat2.GetNextFeature();
                }
                dataList.Add(confiData);
            }

            swModel.ShowConfiguration2(activeconfiguration.Name);
            //GetXml(swModel);
            ExportDataToXmlSql(swModel, dataList);
            SwApp.CloseDoc(swModel.GetTitle());
        }
示例#27
0
 public void DoFunc(int rowindex, int sampleindex)
 {
     #region 1.Solidworks应用程序对象--初识SldWorks对象
     if (rowindex == 0)        //
     {
         if (sampleindex == 1) //新建
         {
             SldWorks swApp = API_Learn.Learn_Sldworks.NewSolidworksApp();
             swApp.NewPart();//新建零件,验证获得Solidworks程序对象成功
         }
         else if (sampleindex == 2)
         {
             SldWorks swApp = API_Learn.Learn_Sldworks.GetSolidworksApp();
             if (swApp != null)
             {
                 swApp.NewPart();//新建零件,验证获得Solidworks程序对象成功
             }
             else
             {
                 MessageBox.Show("无打开的Solidworks");
             }
         }
     }
     #endregion
     #region 2.Solidworks应用程序对象--文档操作1
     else if (rowindex == 1)//
     {
         SldWorks swApp = API_Learn.Learn_Sldworks.GetSolidworksApp();
         if (sampleindex == 1)//新建
         {
             API_Learn.Learn_Sldworks.NewDoc(swApp);
         }
         else if (sampleindex == 2)//打开
         {
             API_Learn.Learn_Sldworks.OpenDoc(swApp);
         }
         else if (sampleindex == 3)//所有文档
         {
             API_Learn.Learn_Sldworks.GetAllOpenedDoc(swApp);
         }
     }
     #endregion
     #region 3.Solidworks应用程序对象--文档操作2
     else if (rowindex == 2)//
     {
         SldWorks swApp = API_Learn.Learn_Sldworks.GetSolidworksApp();
         if (sampleindex == 1)//文档切换
         {
             API_Learn.Learn_Sldworks.ActivateDoc(swApp);
         }
         else if (sampleindex == 2)//加载
         {
             API_Learn.Learn_Sldworks.LoadThirdPartFile(swApp);
         }
         else if (sampleindex == 3)//关闭
         {
             API_Learn.Learn_Sldworks.CloseDoc(swApp);
         }
     }
     #endregion
     #region 4.Solidworks应用程序对象--文档与系统设置
     else if (rowindex == 3)//
     {
         SldWorks swApp = API_Learn.Learn_Sldworks.GetSolidworksApp();
         if (sampleindex == 1)//系统设置
         {
             API_Learn.Learn_Sldworks.SystamSet(swApp);
         }
         else if (sampleindex == 2)//文档设置
         {
         }
         else if (sampleindex == 3)//
         {
         }
     }
     #endregion
 }
示例#28
0
        public static void pointIntersection(double[] firstPoint, Face2 firstFace, double[] secondPoint, Face2 secondFace, IBody2[] body, ModelDoc2 myModel, SldWorks mySwApplication, ref int correctIntersection, ref int correctIntersectionForPair)
        {
            var firstSurface  = (Surface)firstFace.GetSurface();
            var secondSurface = (Surface)secondFace.GetSurface();

            correctIntersection = 0;
            if (firstPoint != null && secondPoint != null)
            {
                var direction    = (double[])MathFunctions.MyNormalization(MathFunctions.MyVectorDifferent(secondPoint, firstPoint));
                var intersection =
                    (int)
                    myModel.RayIntersections(
                        body,
                        (object)firstPoint,
                        (object)direction,
                        (int)(swRayPtsOpts_e.swRayPtsOptsENTRY_EXIT),
                        (double)0,
                        (double)0);

                // Se sono dei presenti dei punti di intersezione li salvo in un apposito vettore.

                if (intersection > 0)
                {
                    var points      = (double[])myModel.GetRayIntersectionsPoints();
                    var totalEntity = (Array)myModel.GetRayIntersectionsTopology();
                    //mySwApplication.SendMsgToUser("punti totali " + points.Length.ToString() + "intersezioni " + intersection.ToString());
                    if (points != null)
                    {
                        for (int i = 0; i < points.Length; i += 9)
                        {
                            double[] pt = new double[] { points[i + 3], points[i + 4], points[i + 5] };
                            double[] directionIntersection =
                                (double[])MathFunctions.MyNormalization(MathFunctions.MyVectorDifferent(pt, firstPoint));

                            if (Math.Abs(MathFunctions.MyInnerProduct(direction, directionIntersection) - 1) < 0.01
                                /*&& MyDistanceTwoPoint(pt, secondPoint) > 0.001 && MyDistanceTwoPoint(pt, firstPoint) > 0.001*/)
                            {
                                if (firstSurface.Identity() == 4001 && secondSurface.Identity() == 4001)
                                {
                                    if (Distance.MyDistanceTwoPoint(firstPoint, secondPoint) > Distance.MyDistanceTwoPoint(firstPoint, pt))
                                    {
                                        correctIntersection++;
                                        correctIntersectionForPair++;
                                    }
                                }
                                else if (firstSurface.Identity() == 4002 && secondSurface.Identity() == 4002)
                                {
                                    double[] closestPointToIntersectionOnFirstSurface  = firstSurface.GetClosestPointOn(pt[0], pt[1], pt[2]);
                                    double[] closestPointToIntersectionOnSecondSurface = secondSurface.GetClosestPointOn(pt[0], pt[1], pt[2]);
                                    //myModel.Insert3DSketch();
                                    //myModel.CreatePoint2(pt[0], pt[1], pt[2]);
                                    if (Distance.MyDistanceTwoPoint(firstPoint, secondPoint) > Distance.MyDistanceTwoPoint(firstPoint, pt) &&
                                        Math.Abs(Distance.MyDistanceTwoPoint(closestPointToIntersectionOnFirstSurface, pt)) > 0.0001 && Math.Abs(Distance.MyDistanceTwoPoint(closestPointToIntersectionOnSecondSurface, pt)) > 0.0001)
                                    {
                                        correctIntersection++;
                                        correctIntersectionForPair++;
                                    }
                                    else
                                    {
                                        var      normalFirstFace = (double[])MyNormalInPoint(firstFace, closestPointToIntersectionOnFirstSurface[0], closestPointToIntersectionOnFirstSurface[1], closestPointToIntersectionOnFirstSurface[2]);
                                        double[] dir             =
                                            (double[])MathFunctions.MyNormalization(MathFunctions.MyVectorDifferent(closestPointToIntersectionOnSecondSurface, closestPointToIntersectionOnFirstSurface));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        mySwApplication.SendMsgToUser("Punti intersezione nulli");
                    }
                }
            }
            else
            {
                mySwApplication.SendMsgToUser("Punti nulli");
            }
        }
示例#29
0
        public void AddFeature(SldWorks SwApp, ModelDoc2 SwModel, Point2D P1, Point2D P2)
        {
            if (CheckUsing() == false)
            {
                return;
            }
            SwModel.ClearSelection2(true);
            Helper         helper         = new Helper(SwModel, SwApp);
            SelectionMgr   selectionMgr   = SwModel.SelectionManager;
            SketchManager  sketchManager  = SwModel.SketchManager;
            FeatureManager featureManager = SwModel.FeatureManager;
            const double   Aprox          = 0.0005; // needs to make correct theard
            Sketch         swSketch       = default(Sketch);

            double L = P2.x - P1.x;

            helper.select_feature("RefPlane", 2, false, 0);

            if (P1.x > 0)
            {
                SwModel.CreatePlaneAtOffset(P1.x, false);
            }


            sketchManager.InsertSketch(true);

            // create helix
            sketchManager.CreateCircleByRadius(0, 0, 0, P1.y);
            SwModel.InsertHelix(false, theardCW, false, true, 2, L, theardPinch, 0, 0, 0);
            SwModel.ClearSelection2(true);


            #region //Triangle profile

            if (theardType == (object)"Triangle")
            {
                double XL = (P1.y - theardR) / 2;      // haf of triangle base
                double YL = XL * (double)Math.Sqrt(3); // median of triangle

                helper.select_feature("RefPlane", 1, false, 0);
                sketchManager.InsertSketch(true);
                sketchManager.CreateLine((P1.x - XL + Aprox), P1.y, 0, (P1.x + XL - Aprox), P1.y, 0);
                sketchManager.CreateLine((P1.x - XL + Aprox), P1.y, 0, P1.x, (P1.y - YL), 0);
                sketchManager.CreateLine((P1.x + XL - Aprox), P1.y, 0, P1.x, (P1.y - YL), 0);
            }

            #endregion

            #region //Trapeze profile

            if (theardType == (object)"Trapeze")
            {
                helper.select_feature("RefPlane", 1, false, 0);
                sketchManager.InsertSketch(true);
                double H    = (P1.y - theardR) / 2;            // haf of trapaze top base and heigth
                double ctgA = 1 / Math.Tan(helper.ToRad(105)); // ctg value of bottom base angle
                double A    = 2 * (H - Aprox) + 4 * H * ctgA;

                sketchManager.CreateLine((P1.x - H / 2 + Aprox), P1.y, 0, (P1.x + H / 2 - Aprox), P1.y, 0);
                sketchManager.CreateLine((P1.x - H / 2 + Aprox), P1.y, 0, (P1.x - (A / 4)), P1.y - H, 0);
                sketchManager.CreateLine((P1.x + H / 2 - Aprox), P1.y, 0, (P1.x + (A / 4)), P1.y - H, 0);
                sketchManager.CreateLine((P1.x - (A / 4)), P1.y - H, 0, (P1.x + (A / 4)), P1.y - H, 0);
            }

            #endregion

            swSketch = SwModel.GetActiveSketch2() as Sketch;
            SwModel.EditRebuild3(); // model rebuild needs to make cutsweep feature avaible

            Entity ent = swSketch as Entity;
            ent.Select2(false, 1); // select sketch using mark 1 for sweep cut
            helper.select_feature("Helix", helper.get_features_count("Helix") - 1, true, 4);

            featureManager.InsertCutSwept4(false, true, 0, false, false, 0, 0, false, 0, 0, 0, 0, true, true, 0,
                                           true, true, true, false);

            helper.HidePlanes();
        }
 public PartExportForm(SldWorks iSwApp)
 {
     InitializeComponent();
     Exporter = new ExportHelper(iSwApp);
 }
 internal static bool InitializeSw(bool visible)
 {
     try
     {
         _swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
     }
     catch (Exception)
     {
         _swApp = new SldWorks { Visible = visible };
     }
     return _swApp != null;
 }
示例#32
0
        //Given a MyPattern, it colors the MyPattern faces.
        //The second part draw lines and circle on the model (not very ok)
        public static void MyVisualOutput_Assembly(List <MyPatternOfComponents> myOutPatterns,
                                                   SldWorks mySwApplication, ModelDoc2 SwModel)
        {
            ModelDoc2 myModel = mySwApplication.ActiveDoc;

            double colorRgb1 = 0; //red
            double colorRgb2 = 0; //green
            double colorRgb3 = 0; //blue

            if (myOutPatterns.Count > 0)
            {
                //mySwApplication.SendMsgToUser("num: " + myOutPatterns.Count);
                double step = 1.0 / myOutPatterns.Count;
                double stepLinearTRANSLATION = 1.0 /
                                               (myOutPatterns.FindAll(
                                                    pattern => pattern.typeOfMyPattern == "linear TRANSLATION").ToList().Count +
                                                myOutPatterns.FindAll(
                                                    pattern => pattern.typeOfMyPattern == "TRANSLATION of length 2").ToList().Count);

                double stepLinearROTATION = 1.0 /
                                            (myOutPatterns.FindAll(
                                                 pattern => pattern.typeOfMyPattern == "linear ROTATION").ToList())
                                            .Count;

                double stepcircularTRANSLATION = 1.0 /
                                                 (myOutPatterns.FindAll(
                                                      pattern => pattern.typeOfMyPattern == "circular TRANSLATION").ToList())
                                                 .Count;

                double stepREFLECTION = 1.0 /
                                        (myOutPatterns.FindAll(
                                             pattern => pattern.typeOfMyPattern == "REFLECTION").ToList())
                                        .Count;
                //mySwApplication.SendMsgToUser("step: " + step);

                // If I am in the list of path LINE, I color with the RED range
                // if (myOutPatterns[0].pathOfMyPattern.GetType() == typeof (MyLine))
                //{
                foreach (MyPatternOfComponents pattern in myOutPatterns)
                {
                    colorRgb1 = 0;     //red
                    colorRgb2 = 0;     //green
                    colorRgb3 = 0;     //blue
                    if (pattern.typeOfMyPattern == "linear TRANSLATION" || pattern.typeOfMyPattern == "TRANSLATION of length 2")
                    {
                        colorRgb1 = stepLinearTRANSLATION * (myOutPatterns.IndexOf(pattern) + 1);
                    }
                    else if (pattern.typeOfMyPattern == "linear ROTATION")
                    {
                        colorRgb2 = stepLinearROTATION * (myOutPatterns.IndexOf(pattern) + 1);
                    }
                    else if (pattern.typeOfMyPattern == "circular TRANSLATION")
                    {
                        colorRgb2 = stepcircularTRANSLATION * (myOutPatterns.IndexOf(pattern) + 1);
                    }
                    else if (pattern.typeOfMyPattern == "REFLECTION")
                    {
                        colorRgb3 = stepREFLECTION * (myOutPatterns.IndexOf(pattern) + 1);
                    }
                    //else if (pattern.typeOfMyPattern == "ROTATION")
                    //{
                    //    colorRgb1 = step * (myOutPatterns.IndexOf(pattern) + 0.5);
                    //    colorRgb3 = step * (myOutPatterns.IndexOf(pattern) + 0.5);
                    //}
                    else
                    {
                        colorRgb2 = (myOutPatterns.IndexOf(pattern) + 0.5);
                        colorRgb3 = (myOutPatterns.IndexOf(pattern) + 0.5);
                    }
                    // mySwApplication.SendMsgToUser("COLORE: " + colorRgb1);

                    foreach (var repeatedComponent in pattern.listOfMyRCOfMyPattern)
                    {
                        var currentComp       = repeatedComponent.Component;
                        var componentMaterial = (Array)currentComp.MaterialPropertyValues;

                        if (componentMaterial == null)
                        {
                            componentMaterial = (Array)myModel.MaterialPropertyValues;
                        }

                        componentMaterial.SetValue(colorRgb1, 0);
                        componentMaterial.SetValue(colorRgb2, 1);
                        componentMaterial.SetValue(colorRgb3, 2);

                        repeatedComponent.Component.MaterialPropertyValues = componentMaterial;
                    }

                    //   mySwApplication.SendMsgToUser("ADD pattern on LINE of type " + pattern.typeOfMyPattern);
                }

                //}
                // If I am in the list of path CIRCUMFERENCE, I color with the GREEN range
                // else
                //{
                //foreach (MyPatternOfComponents pattern in myOutPatterns)
                //{
                //    colorRgb2 = step*(myOutPatterns.IndexOf(pattern) + 1);
                //    //mySwApplication.SendMsgToUser("COLORE: " + colorRgb2);

                //    foreach (var repeatedComponent in pattern.listOfMyRCOfMyPattern)
                //    {

                //        var currentComp = repeatedComponent.Component;
                //        var componentMaterial = (Array) currentComp.MaterialPropertyValues;

                //        if (componentMaterial == null)
                //        {
                //            componentMaterial = (Array) myModel.MaterialPropertyValues;
                //        }

                //        componentMaterial.SetValue(colorRgb1, 0);
                //        componentMaterial.SetValue(colorRgb2, 1);
                //        componentMaterial.SetValue(colorRgb3, 2);

                //        repeatedComponent.Component.MaterialPropertyValues = componentMaterial;


                //    }

                //mySwApplication.SendMsgToUser("ADD pattern on CIRCUMFERENCE of type " + pattern.typeOfMyPattern);

                //}
            }
        }
示例#33
0
 /// <summary>
 /// Loads a joint that has already been created
 /// </summary>
 /// <param name="swApp">Solidworks app</param>
 /// <param name="asm">Assembly document this joint and its robot belong to</param>
 /// <param name="swData">StorageModel that this joint is tored in</param>
 /// <param name="path">Path to this joint in the StorageModel</param>
 /// <param name="robot">The Robot model that the joint is in</param>
 public Joint(string path)
 {
     this.swApp = RobotInfo.SwApp;
     this.asmDoc = RobotInfo.AssemDoc;
     this.modelDoc = RobotInfo.ModelDoc;
     this.swData = RobotInfo.SwData;
     this.path = path;
     this.robot = RobotInfo.Robot;
     this.Parent = robot.GetLink(parentId);
     Parent.ChildJoints.Add(this);
     this.Child = robot.GetLink(childId);
     this.Selected = false;
     if(this.Type == null || this.Type.Equals(""))
         this.Type = JointFactory.DefaultJointType;
     RobotInfo.WriteToLogFile("Loading existing joint (Joint)");
     jointSpecifics = JointFactory.GetSpecificJoint(Type, path, this);
     if (swData.GetDouble(path) == 0)
     {
         swData.SetDouble(path, 1);
     }
 }
示例#34
0
        //Given a MyPattern, it colors the MyPattern faces.
        //The second part draw lines and circle on the model (not very ok)
        public static void MyVisualOutput(List <MyPattern> myOutPatterns, SldWorks mySwApplication)
        {
            ModelDoc2 myModel = mySwApplication.ActiveDoc;

            double colorRgb1 = 0;  //red
            double colorRgb2 = 0;  //green
            double colorRgb3 = 0;  //blue

            if (myOutPatterns.Count > 0)
            {
                //mySwApplication.SendMsgToUser("num: " + myOutPatterns.Count);
                double step = 1.0 / myOutPatterns.Count;
                //mySwApplication.SendMsgToUser("step: " + step);

                // If I am in the list of path LINE, I color with the RED range
                if (myOutPatterns[0].pathOfMyPattern.GetType() == typeof(MyLine))
                {
                    foreach (MyPattern pattern in myOutPatterns)
                    {
                        colorRgb1 = step * (myOutPatterns.IndexOf(pattern) + 1);

                        //mySwApplication.SendMsgToUser("COLORE: " + colorRgb1);

                        foreach (MyRepeatedEntity repeatedEntity in pattern.listOfMyREOfMyPattern)
                        {
                            foreach (Face2 face in repeatedEntity.listOfFaces)
                            {
                                var faceMaterial = (Array)face.MaterialPropertyValues;

                                if (faceMaterial == null)
                                {
                                    faceMaterial = (Array)myModel.MaterialPropertyValues;
                                }

                                faceMaterial.SetValue(colorRgb1, 0);
                                faceMaterial.SetValue(colorRgb2, 1);
                                faceMaterial.SetValue(colorRgb3, 2);

                                face.MaterialPropertyValues = faceMaterial;
                                //FolderUtilities.PrintToFile(idNode.ToString(), "colorFace.txt");
                            }
                        }
                    }
                }
                // If I am in the list of path CIRCUMFERENCE, I color with the GREEN range
                else
                {
                    foreach (MyPattern pattern in myOutPatterns)
                    {
                        colorRgb2 = step * (myOutPatterns.IndexOf(pattern) + 1);
                        //mySwApplication.SendMsgToUser("COLORE: " + colorRgb2);

                        foreach (MyRepeatedEntity repeatedEntity in pattern.listOfMyREOfMyPattern)
                        {
                            foreach (Face2 face in repeatedEntity.listOfFaces)
                            {
                                var faceMaterial = (Array)face.MaterialPropertyValues;

                                if (faceMaterial == null)
                                {
                                    faceMaterial = (Array)myModel.MaterialPropertyValues;
                                }

                                faceMaterial.SetValue(colorRgb1, 0);
                                faceMaterial.SetValue(colorRgb2, 1);
                                faceMaterial.SetValue(colorRgb3, 2);

                                face.MaterialPropertyValues = faceMaterial;
                                //FolderUtilities.PrintToFile(idNode.ToString(), "colorFace.txt");
                            }
                        }
                    }
                }
            }

            #region PROVE
            //myModel.Insert3DSketch();
            //myModel.CreateLine2(0, 0, 0, 0.01, 0.01, 0.01);
            //myModel.InsertSketch();
            //myModel.ClearSelection2(true);



            ////myModel.Insert3DSketch();
            ////myModel.CreateCircleByRadius2(0, 0, 0, 0.01);
            ////myModel.InsertSketch();
            ////myModel.ClearSelection2(true);



            //var sketchManager = (SketchManager)myModel.SketchManager;
            //mySwApplication.SendMsgToUser("Pausa");
            //sketchManager.Insert3DSketch(true);
            //myModel.ClearSelection2(true);

            //var sketch = (Sketch)sketchManager.ActiveSketch;
            //mySwApplication.SendMsgToUser("Pausa");
            //if (sketch.SetWorkingPlaneOrientation(0, 0, 0,
            //    0, 1, 0,
            //    0, 0, 1,
            //    1, 0, 0))
            //    //Non disegna la circonferenza richiesta sul piano settato!
            //    //In pratica crea lo schizzo 3D ma poi lo fa sparire dalla tendiana a sinistra.
            //    //Disegna invece la circonferenza sul piano def da:
            //    //(0, 0, 0,
            //    //1, 0, 0,
            //    //0, 0, 1,
            //    //0, 1, 0)... PERCHE QUESTO SI??
            //    //Disegna inoltre crf se non si setta il piano e si passa direttamente
            //    //a sketchManager.CreateCircleByRadius(0, 0, 0, 0.001).
            //{
            //    mySwApplication.SendMsgToUser("Sono TRUE");
            //}
            //else
            //{
            //    mySwApplication.SendMsgToUser("Sono FALSE");
            //}

            //mySwApplication.SendMsgToUser("Pausa");
            //sketchManager.CreateCircleByRadius(0, 0, 0, 0.001);

            //mySwApplication.SendMsgToUser("Pausa");
            //myModel.ClearSelection2(true);
            //myModel.InsertSketch();
            //myModel.ClearSelection2(true);
            #endregion
        }
        //This function takes as input a list of patterns with MyPathGeometricObject circumference,
        //it subdivides the patterns by same number of RE on the pattern, then by angle.
        public static List <List <MyPattern> > GroupFoundPatternsOfTypeCircum(List <MyPattern> listOfPatternsOfTypeCircum, SldWorks mySwApplication)
        {
            var nameFile              = "ComposedPatterns.txt";
            var tolerance             = Math.Pow(10, -6);
            var listOfListsOfPatterns = new List <List <MyPattern> >();

            foreach (var pattern in listOfPatternsOfTypeCircum)
            {
                var indexOfFind = listOfListsOfPatterns.FindIndex(list => (list[0].listOfMyREOfMyPattern.Count ==
                                                                           pattern.listOfMyREOfMyPattern.Count && Math.Abs(list[0].angle - pattern.angle) < tolerance));
                if (indexOfFind != -1)
                {
                    //The list referred to patterns with same RE number and same constant step already exists. I add it to the corresponding list:
                    listOfListsOfPatterns[indexOfFind].Add(pattern);
                }
                else
                {
                    //The list referred to patterns with same RE number and same constant step does not exist yet. I create it:
                    List <MyPattern> newListOfPatterns = new List <MyPattern> {
                        pattern
                    };
                    listOfListsOfPatterns.Add(newListOfPatterns);
                }
            }
            listOfListsOfPatterns.RemoveAll(list => list.Count < 2);

            return(listOfListsOfPatterns);
        }
示例#36
0
        /// <summary>
        /// Units the asmbly string.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <param name="order">The order.</param>
        /// <param name="side">The side.</param>
        /// <param name="widthS">The width s.</param>
        /// <param name="heightS">The lenght s.</param>
        /// <param name="lenghtS">The lenght s.</param>
        /// <param name="frame"></param>
        /// <param name="panels">The panels.</param>
        /// <param name="roofType">Type of the roof.</param>
        /// <param name="section">The section.</param>
        /// <param name="profilOfCascet"></param>
        /// <returns></returns>
        public string UnitAsmblyStr(string size, string order, string side, string widthS, string heightS,
            string lenghtS,
            string frame, string[] panels, string roofType, string section, string profilOfCascet)
        {

            #region Проверка значений

            if (IsConvertToInt(new[] {widthS, heightS, lenghtS}) == false)
            {
                return "";
            }

            #endregion

            #region Basic Parameters

            // Габариты
            var width = GetInt(widthS);
            var height = GetInt(heightS);
            var lenght = GetInt(lenghtS);

            #endregion

            #region Start

            var modelName = profilOfCascet == "150" ? "01-000-500" : "01-000-700";

            var unitAsMmodel = $@"{Settings.Default.SourceFolder}{Unit50FolderS}\{modelName + ".SLDASM"}";

            var newUnit50Name = $"{size} {order} {section}";


            var orderFolder = $@"{Settings.Default.DestinationFolder}\{Unit50Orders}\{size}\{size} {order}";

            CreateDistDirectory(orderFolder, Settings.Default.PdmBaseName);

            var newUnit50Path = $@"{orderFolder}\{newUnit50Name}.SLDASM";

            if (File.Exists(newUnit50Path))
            {
                GetLastVersionPdm(new FileInfo(newUnit50Path).FullName, Settings.Default.TestPdmBaseName);
                _swApp.OpenDoc6(newUnit50Path, (int) swDocumentTypes_e.swDocASSEMBLY,
                    (int) swOpenDocOptions_e.swOpenDocOptions_LoadModel, "00", 0, 0);
                return newUnit50Path;
            }

            GetLatestVersionAsmPdm(unitAsMmodel, Settings.Default.PdmBaseName);

            if (!Warning()) return "";
            var swDoc = _swApp.OpenDoc6(unitAsMmodel, (int) swDocumentTypes_e.swDocASSEMBLY,
                (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0);
            _swApp.Visible = true;
            var swAsm = (AssemblyDoc) swDoc;
            swAsm.ResolveAllLightWeightComponents(false);

            #endregion

            #region Frame

            try
            {
                var profilName = profilOfCascet == "150" ? "01-P150-45-" : "01-P170-50-";
                var deltaForProfil = profilOfCascet == "150" ? 140 : 180;

                //Lenght
                const double step = 100;
                double rivetL;


                var modelLenghtProfil = profilOfCascet == "150" ? "01-002-50" : "01-002-170-45";
                var lenghtProfil = profilOfCascet == "150" ? "01-002-50-27" : "01-002-170-45-3";


                var newName = profilName + (lenght - deltaForProfil);
                var newPartPath = $@"{Settings.Default.DestinationFolder}\{Unit50FolderD}\{newName}.SLDPRT";
                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));
                    swDoc.Extension.SelectByID2(lenghtProfil + "@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm.ReplaceComponents(newPartPath, "", true, true);
                    _swApp.CloseDoc(modelLenghtProfil + ".SLDPRT");
                }
                else if (File.Exists(newPartPath) != true)
                {
                    rivetL = (Math.Truncate((lenght - deltaForProfil - 30)/step) + 1)*1000;
                    SwPartParamsChangeWithNewName(modelLenghtProfil,
                        $@"{Settings.Default.DestinationFolder}\{Unit50FolderD}\{newName}",
                        new[,]
                        {
                            {"D1@Вытянуть1", Convert.ToString(lenght - deltaForProfil)},
                            {"D1@Кривая1", Convert.ToString(rivetL)}
                        },
                        false,
                        null);
                    _swApp.CloseDoc(newName);
                }

                // SwPartSizeChangeWithNewName("01-002-50", "01-P150-45-" + (lenght - 140), "D1@Вытянуть1", lenght - 140);//(Width - 140).ToString()
                // SwPartSizeChangeWithNewName("01-005-50", "01-P252-45-" + (Lenght - 140 + 40).ToString(), "D1@Вытянуть1", Lenght - 140 + 40);//(Width - 140 + 40).ToString()

                //Width
                newName = profilName + (width - deltaForProfil);
                newPartPath = $@"{Settings.Default.DestinationFolder}\{Unit50FolderD}\{newName}.SLDPRT";

                var modelWidthProfil = profilOfCascet == "150" ? "01-003-50" : "01-003-170-45";
                var widthProfil = profilOfCascet == "150" ? "01-003-50-22" : "01-003-170-45-3";

                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));
                    swDoc.Extension.SelectByID2(widthProfil + "@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm.ReplaceComponents(newPartPath, "", true, true);
                    _swApp.CloseDoc(modelWidthProfil + ".SLDPRT");
                }
                else if (File.Exists(newPartPath) != true)
                {
                    rivetL = (Math.Truncate((width - deltaForProfil - 30)/step) + 1)*1000;
                    SwPartParamsChangeWithNewName(modelWidthProfil,
                        $@"{Settings.Default.DestinationFolder}\{Unit50FolderD}\{newName}",
                        new[,]
                        {
                            {"D1@Вытянуть1", Convert.ToString(width - deltaForProfil)},
                            {"D1@Кривая1", Convert.ToString(rivetL)}
                        },
                        false,
                        null);
                    _swApp.CloseDoc(newName);
                }

                //SwPartSizeChangeWithNewName("01-003-50", "01-P150-45-" + (width - 140), "D1@Вытянуть1", width - 140);//"01-P150-45-" + (Lenght - 140).ToString(),

                //Height
                newName = profilName + (height - deltaForProfil);
                newPartPath = $@"{Settings.Default.DestinationFolder}\{Unit50FolderD}\{newName}.SLDPRT";

                var modelHeightProfil = profilOfCascet == "150" ? "01-001-50" : "01-001-170-45";
                var heightProfil = profilOfCascet == "150" ? "01-001-50-23" : "01-001-170-45-3";

                if (File.Exists(new FileInfo(newPartPath).FullName))
                {
                    swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));
                    swDoc.Extension.SelectByID2(heightProfil + "@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm.ReplaceComponents(newPartPath, "", true, true);
                    _swApp.CloseDoc(modelHeightProfil + ".SLDPRT");
                }
                else if (File.Exists(newPartPath) != true)
                {
                    rivetL = (Math.Truncate((height - deltaForProfil - 30)/step) + 1)*1000;
                    SwPartParamsChangeWithNewName(modelHeightProfil,
                        $@"{Settings.Default.DestinationFolder}\{Unit50FolderD}\{newName}",
                        new[,]
                        {
                            {"D1@Вытянуть1", Convert.ToString(height - deltaForProfil)},
                            {"D1@Кривая1", Convert.ToString(rivetL)}
                        },
                        false,
                        null);
                    _swApp.CloseDoc(newName);
                }

                //SwPartSizeChangeWithNewName("01-001-50", "01-P150-45-" + (lenght - 140), "D1@Вытянуть1", lenght - 140);//"01-P150-45-" + (Height - 140).ToString()
                //SwPartSizeChangeWithNewName("01-004-50", "01-P252-45-" + (Height - 140 + 40).ToString(), "D1@Вытянуть1", Height - 140 + 40);//"01-P252-45-" + (Height - 140 + 40).ToString()

                swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));
                swDoc.EditRebuild3();
                swDoc.ForceRebuild3(true);
                swAsm = (AssemblyDoc) swDoc;

                if (side == "левая")
                {
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-1@" + modelName, "COMPONENT", 0, 0, 0, true, 0,
                        null, 0);
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-6@" + modelName, "COMPONENT", 0, 0, 0, true, 0,
                        null, 0);
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-7@" + modelName, "COMPONENT", 0, 0, 0, true, 0,
                        null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-10@" + modelName, "COMPONENT", 0, 0, 0, true,
                        0, null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-4@" + modelName, "COMPONENT", 0, 0, 0, true,
                        0, null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-12@" + modelName, "COMPONENT", 0, 0, 0, true,
                        0, null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-12@" + modelName, "COMPONENT", 0, 0, 0,
                        false, 0, null, 0);
                    swDoc.EditDelete();
                }
                else if (side != "левая")
                {
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-16@" + modelName, "COMPONENT", 0, 0, 0, true, 0,
                        null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-21@" + modelName, "COMPONENT", 0, 0, 0, true,
                        0, null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-22@" + modelName, "COMPONENT", 0, 0, 0, true,
                        0, null, 0);
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-17@" + modelName, "COMPONENT", 0, 0, 0, true, 0,
                        null, 0);
                    swDoc.Extension.SelectByID2("Threaded Rivets с насечкой-23@" + modelName, "COMPONENT", 0, 0, 0, true,
                        0, null, 0);
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-18@" + modelName, "COMPONENT", 0, 0, 0, true, 0,
                        null, 0);
                    swDoc.Extension.SelectByID2("M8-Panel block-one side-18@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swDoc.EditDelete();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Frame");
            }

            #endregion

            #region Roof

            try
            {
                if (!string.IsNullOrEmpty(roofType))
                {
                    swAsm = (AssemblyDoc) swDoc;
                    swAsm.ResolveAllLightWeightComponents(false);
                    Thread.Sleep(5000);

                    //MessageBox.Show("Roof");
                    var roofUnit50 = RoofStr(roofType, Convert.ToString(width), Convert.ToString(lenght), true);
                    // MessageBox.Show("Roof End");
                    swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));

                    swDoc.Extension.SelectByID2("15-01-770-1000-1@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm.ReplaceComponents(roofUnit50, "", false, true);
                    _swApp.CloseDoc(new FileInfo(roofUnit50).Name);
                }
                else
                {
                    swDoc.Extension.SelectByID2("15-01-770-1000-1@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swDoc.EditDelete();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Roof");
            }

            #endregion

            #region Panels

            try
            {
                if (panels[0] != null)
                {

                    #region to delete

                    //{{
                    //    //WxL
                    //    //string panelWxL = Panels50BuildStr("01 - Несъемная (50-Az-Az-MW)", (lenght - 100).ToString(), (width - 100).ToString(), "Az", "Az");
                    //    //_swApp.CloseDoc(panelWxL);
                    //    var panelWxL = Panels50BuildStr(
                    //        typeOfPanel: new[] { "01", "Несъемная" },
                    //        width: Convert.ToString(lenght - 100),
                    //        lenght: Convert.ToString(width - 100),
                    //        materialP1: new[] { materialP1, null, null, null },
                    //        materialP2: new[] { materialP2, null, null, null },
                    //        покрытие: new[] { (string)null, (string)null, (string)null, (string)null, (string)null, (string)null, (string)null },
                    //        onlyPath: true);
                    //    var closedFile = new FileInfo(panelWxL); _swApp.CloseDoc(closedFile.Name);
                    //    //HxL
                    //    //string panelHxL = Panels50BuildStr("01 - Несъемная (50-Az-Az-MW)", (lenght - 100).ToString(), (lenght - 100).ToString(), "Az", "Az");
                    //    //_swApp.CloseDoc(panelHxL);
                    //    var panelHxL = Panels50BuildStr(
                    //        typeOfPanel: new[] { "01", "Несъемная" },
                    //        width: Convert.ToString(lenght - 100),
                    //        lenght: Convert.ToString(lenght - 100),
                    //        materialP1: new[] { materialP1, null, null, null },
                    //        materialP2: new[] { materialP2, null, null, null },
                    //        покрытие: new[] { (string)null, (string)null, (string)null, (string)null, (string)null, (string)null, (string)null },
                    //        onlyPath: true);
                    //    closedFile = new FileInfo(panelHxL); _swApp.CloseDoc(closedFile.Name);
                    //    var panelHxL04 = Panels50BuildStr(
                    //        typeOfPanel: typeOfPanel,
                    //        width: Convert.ToString(lenght - 100),
                    //        lenght: Convert.ToString(lenght - 100),
                    //        materialP1: new[] { materialP1, null, null, null },
                    //        materialP2: new[] { materialP2, null, null, null },
                    //        покрытие: new[] { (string)null, (string)null, (string)null, (string)null, (string)null, (string)null, (string)null },
                    //        onlyPath: true);
                    //    closedFile = new FileInfo(panelHxL04); _swApp.CloseDoc(closedFile.Name);

                    #endregion

                    swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));

                    var panelWxL = panels[0];
                    var panelHxL = panels[1];
                    var panelHxL04 = panels[2];

                    var sidePanelL = panelHxL;
                    var sidePanelR = panelHxL04;

                    if (side == "левая")
                    {
                        sidePanelL = panelHxL04;
                        sidePanelR = panelHxL;
                    }

                    swDoc.Extension.SelectByID2("02-01-650-670-50-Az-Az-MW-4@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swAsm.ReplaceComponents(panelWxL, "", false, true);
                    swDoc.Extension.SelectByID2("02-01-650-670-50-Az-Az-MW-5@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swAsm.ReplaceComponents(panelWxL, "", false, true);


                    swDoc.Extension.SelectByID2("02-01-650-625-50-Az-Az-MW-6@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swAsm.ReplaceComponents(sidePanelL, "", false, true);
                    swDoc.Extension.SelectByID2("02-04-650-625-50-Az-Az-MW-5@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swAsm.ReplaceComponents(sidePanelR, "", false, true);
                }
                else
                {
                    //  MessageBox.Show("delete", "panelWxL\n" + panels[0]);

                    swDoc.Extension.SelectByID2("02-01-650-670-50-Az-Az-MW-4@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swDoc.EditDelete();
                    swDoc.Extension.SelectByID2("02-01-650-670-50-Az-Az-MW-5@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swDoc.EditDelete();
                    swDoc.Extension.SelectByID2("02-01-650-625-50-Az-Az-MW-6@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swDoc.EditDelete();
                    swDoc.Extension.SelectByID2("02-04-650-625-50-Az-Az-MW-5@" + modelName, "COMPONENT", 0, 0, 0, false,
                        0, null, 0);
                    swDoc.EditDelete();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Panels");
            }

            #endregion

            #region Монтажная рама

            try
            {
                if (frame != "")
                {
                    swAsm = (AssemblyDoc) swDoc;
                    swAsm.ResolveAllLightWeightComponents(true);
                    swDoc = ((ModelDoc2) (_swApp.ActivateDoc2(modelName + ".SLDASM", true, 0)));
                    swDoc.Extension.SelectByID2("10-2-1300-1150-1@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm.ReplaceComponents(frame, "", false, true);
                    _swApp.CloseDoc(new FileInfo(frame).Name);
                }
                else
                {
                    swDoc.Extension.SelectByID2("10-2-1300-1150-1@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swDoc.EditDelete();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Монтажная рама");
            }

            #endregion

            #region Омеги

            ////Погашение вертикальной омеги
            //swDoc.Extension.SelectByID2("Омега вертикальная зеркалка", "COMPPATTERN", 0, 0, 0, false, 0, null, 0);
            //swDoc.EditSuppress2();
            //boolstatus = swDoc.Extension.SelectByID2("Омега вертикальная", "FTRFOLDER", 0, 0, 0, false, 0, null, 0);
            //swDoc.EditSuppress2();
            ////Погашение горизонтальной омеги
            //swDoc.Extension.SelectByID2("Омега горизонтальная зеркальное", "COMPPATTERN", 0, 0, 0, false, 0, null, 0);
            //swDoc.EditSuppress2();
            //boolstatus = swDoc.Extension.SelectByID2("Омега горизонтальная", "FTRFOLDER", 0, 0, 0, false, 0, null, 0);
            //swDoc.EditSuppress2();

            #endregion

            #region COMPPATTERN

            swDoc.Extension.SelectByID2("DerivedCrvPattern1", "COMPPATTERN", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("DerivedCrvPattern2", "COMPPATTERN", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("DerivedCrvPattern3", "COMPPATTERN", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Омега вертикальная зеркалка", "COMPPATTERN", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Омега горизонтальная зеркальное", "COMPPATTERN", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Омега горизонтальная зеркальное", "COMPPATTERN", 0, 0, 0, false, 0, null, 0);
            swDoc.EditDelete();
            swDoc.Extension.SelectByID2("Уголок 901.31.209", "FTRFOLDER", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Косынка ВНС-901.31.126", "FTRFOLDER", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Омега вертикальная", "FTRFOLDER", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Омега горизонтальная", "FTRFOLDER", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("Омега горизонтальная", "FTRFOLDER", 0, 0, 0, false, 0, null, 0);
            swDoc.EditDelete();
            swDoc.Extension.SelectByID2("ВНС-901.31.209-1@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-2@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-3@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-4@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-5@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-6@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-7@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.209-8@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-1@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-2@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-3@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-4@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-5@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-6@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-7@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.126-8@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("01-004-50-1@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-1@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-2@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-3@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-4@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("01-005-50-3@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-9@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-10@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-13@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-14@" + modelName, "COMPONENT", 0, 0, 0, true, 0, null, 0);
            swDoc.Extension.SelectByID2("ВНС-901.31.125-14@" + modelName, "COMPONENT", 0, 0, 0, false, 0, null, 0);
            swDoc.EditDelete();

            #endregion

            #region to delete

            //swDoc.Extension.SelectByID2("Coil-3@01-000-500", "COMPONENT", 0, 0, 0, false, 0, null, 0);
            //var myModelView = ((ModelView)(swDoc.ActiveView));
            //myModelView.RotateAboutCenter(0.047743940985476567, 0.42716619534422462);
            //swAsm.ReplaceComponents("C:\\Tets_debag\\Frameless Besing\\16-AV04-2H.SLDASM", "", false, true);

            #endregion

            #region  Сохранение

            _swApp.IActivateDoc2(modelName + ".SLDASM", false, 0);
            swDoc = ((ModelDoc2) (_swApp.ActiveDoc));
            swDoc.ForceRebuild3(true);
            swDoc.SaveAs2(newUnit50Path, (int) swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);

            //swDoc.SaveAs2(String.Format(@"{0}\{1}\{2}.SLDASM", Settings.Default.DestinationFolder, Unit50Folder, newUnit50Name), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
            NewComponents.Add(new FileInfo(newUnit50Path));

            _swApp.CloseDoc(new FileInfo(newUnit50Path).Name);
            //_swApp.ExitApp();
            _swApp = null;
            CheckInOutPdm(NewComponents, true, Settings.Default.TestPdmBaseName);
                //.OrderBy(x => x.Length).ToList(), true, Settings.Default.TestPdmBaseName);

            #region to delete

            //            var createdFileInfosM = "";
            //            var count = 0;

            //            foreach (var fileInfo in NewComponents.OrderByDescending(x => x.Length).ToList())
            //            {
            //                count += 1;
            //                var fileSize = fileInfo.Length.ToString();
            //                if (fileInfo.Length >= (1 << 30))
            //                    fileSize = String.Format("{0}Gb", fileInfo.Length >> 30);
            //                else if (fileInfo.Length >= (1 << 20))
            //                    fileSize = String.Format("{0}Mb", fileInfo.Length >> 20);
            //                else if (fileInfo.Length >= (1 << 10))
            //                    fileSize = String.Format("{0}Kb", fileInfo.Length >> 10);
            //                var extension = " Деталь - ";
            //                if (Path.GetFileNameWithoutExtension(fileInfo.FullName).ToUpper() == ".SLDASM")
            //                {
            //                    extension = " Сборка - ";
            //                }
            //                createdFileInfosM = createdFileInfosM + @"
            //" + count + ". " + extension + fileInfo.Name + " - " + fileSize;
            //            }
            //            MessageBox.Show(createdFileInfosM, "Созданы следующие файлы");

            #endregion

            return newUnit50Path;

            #endregion
        }
示例#37
0
        public static bool IsRotationTwoPatterns(MyPattern firstMyPattern, MyPattern secondMyPattern, double teta,
                                                 double[] axisDirection, MyVertex circumCenter, SldWorks SwApplication, ref StringBuilder fileOutput)
        {
            //check of the length correspondence:
            var firstPatternLength  = firstMyPattern.listOfMyREOfMyPattern.Count;
            var secondPatternLength = secondMyPattern.listOfMyREOfMyPattern.Count;

            if (firstPatternLength != secondPatternLength)
            {
                return(false);
            }

            //KLdebug.Print("La 0^ RE del 1° pattern è compatibile con la 0^ RE del 2° pattern? " +
            //    IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
            //    secondMyPattern.listOfMyREOfMyPattern[0], teta, axisDirection, circumCenter), nameFile);
            //KLdebug.Print("La 0^ RE del 1° pattern è compatibile con la (n-1)^ RE del 2° pattern? " +
            //    IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
            //    secondMyPattern.listOfMyREOfMyPattern[secondPatternLength - 1], teta, axisDirection, circumCenter), nameFile);

            if (PartUtilities.GeometryAnalysis.IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
                                                               secondMyPattern.listOfMyREOfMyPattern[0], teta, axisDirection, circumCenter) ||
                PartUtilities.GeometryAnalysis.IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
                                                               secondMyPattern.listOfMyREOfMyPattern[secondPatternLength - 1], teta, axisDirection, circumCenter))
            {
                return(true);
            }
            return(false);
        }
示例#38
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
                }
示例#39
0
        /////

        internal static HelperResult processModel(SldWorks swApp, FileObj file, BindingList <PropertyObject> prop_list, PropProcessFlag flag, CancellationToken cancellationToken)
        {
            if (swApp == null)
            {
                return(HelperResult.SLDWORKS_NOT_RUNNING);
            }

            Console.WriteLine("Helper.processModel");

            int Warning = 0;
            int Error   = 0;

            try
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    file.Note = "Cancel";
                    return(HelperResult.CANCELED);
                }

                if (file.Read_only)
                {
                    file.Note = "Skiped (Read only!)";
                    return(HelperResult.SKIPED);
                }

                ModelDoc2 swDoc = swApp.OpenDoc6(file.PathToFile, (int)file.SwType_e, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Error, ref Warning);

                if (Error != 0 || swDoc == null)
                {
                    file.Note = "Error to open file";
                    return(HelperResult.OPEN_ERROR);
                }

                //*  //this code error
                if (file.SwType_e == swDocumentTypes_e.swDocASSEMBLY || file.SwType_e == swDocumentTypes_e.swDocPART)
                {
                    file.ConfigNames.AddRange(swDoc.GetConfigurationNames());
                    if (!file.ConfigNames.Any())
                    {
                        swApp.QuitDoc(swDoc.GetTitle());
                        swDoc     = null;
                        file.Note = "Skiped (Unknown error)";
                        return(HelperResult.UNKNOWN);
                    }
                }

                //*/

                if ((flag & PropProcessFlag.MAIN_CUSTOM) == PropProcessFlag.MAIN_CUSTOM)
                {
                    try
                    {
                        CustomPropertyManager manager = swDoc.Extension.CustomPropertyManager[""];
                        foreach (PropertyObject property in prop_list)
                        {
                            Console.WriteLine("field={0},type={1},value={2}", property.FieldName, property.FieldType, property.Value);
                            int ret = manager.Add3(property.FieldName, (int)property.FieldType, property.Value, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue);
                            if (ret != 0)
                            {
                                file.Note = "Error to add, err num = " + ret;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("error in add method" + ex.Message);
                        file.Note = "error(" + ex.Message + ")";
                        //throw ex;
                    }
                }

                if (((flag & PropProcessFlag.CONFIG_CUSTOM) == PropProcessFlag.CONFIG_CUSTOM) && file.ConfigNames.Any())
                {
                    try
                    {
                        foreach (string conf in file.ConfigNames)
                        {
                            Console.WriteLine(conf);
                            CustomPropertyManager manager = swDoc.Extension.CustomPropertyManager[conf];
                            foreach (PropertyObject property in prop_list)
                            {
                                string value   = property.Value;
                                string pattern = @"[^@]+";

                                MatchCollection matches = Regex.Matches(value, pattern);

                                if (matches.Count >= 3)
                                {
                                    property.Value = Regex.Replace(value, matches[matches.Count - 2].Value, conf);
                                }

                                Console.WriteLine("field={0},type={1},value={2},config{3}", property.FieldName, property.FieldType, property.Value, conf);
                                int ret = manager.Add3(property.FieldName, (int)property.FieldType, property.Value, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue);
                                if (ret != 0)
                                {
                                    file.Note = "Error to add, err num = " + ret;
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("error in add method" + ex.Message);
                        file.Note = "error(" + ex.Message + ")";
                        //throw ex;
                    }
                }

                file.Note = "Done";
                swDoc.SaveSilent();
                swApp.QuitDoc(swDoc.GetTitle());
                swDoc = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
            return(HelperResult.SUCCESS);
        }
示例#40
0
        /// <summary>
        /// Called whin this add in is unloaded by solidworks.
        /// Disposes of all resources allocated during runtime.
        /// </summary>
        /// <returns></returns>
        public bool DisconnectFromSW()
        {
            try
            {
                //Release static pointers
                cmdMgr = null;
                currentRobot = null;
                currentDoc = null;

                //Release the interface to Solidworks
                System.Runtime.InteropServices.Marshal.ReleaseComObject(iSwApp);
                iSwApp = null;

                //Tell CLR to reclaim all resources used by this add in
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
示例#41
0
        public static bool KLFindPaths_Assembly(MyMatrAdj matrAdjToSee, List <MyRepeatedComponent> listOfComponents, List <MyVertex> listOfOrigins,
                                                ref StringBuilder fileOutput, out List <MyPathOfPoints> listOfPathsOfPoints, out bool onlyShortPaths,
                                                ref bool toleranceOk, ref List <MyMatrAdj> listOfMatrAdj,
                                                ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo, ModelDoc2 SwModel, SldWorks SwApplication)
        {
            int  n = matrAdjToSee.matr.GetLength(0);
            bool longestPattern             = false;
            var  listOfIndicesOfLongestPath = new List <int>();
            //to keep in mind the index of the LongestPath if it is found during the process: I can't delete it from the list
            //immediately because I need it to remember the points I have already passed through.
            //Then at the end I delete this path from the list because it is geometrically verified in the process
            //(and if I have to delete it, it means that is not a real geometric pattern).
            var listOfPaths = new List <MyPathOfPoints>();

            List <int> listOfExtremePoints = new List <int>(); //list of Extreme points
            List <int> listOfSimplePoints  = new List <int>(); //list of Simple points
            List <int> listOfMBPoints      = new List <int>(); //list of Multibranch points

            // We classify the points involved in the current adjacency matrix:
            Part.PathCreation_Part.Functions.ClassifyComponents(matrAdjToSee, n, ref listOfExtremePoints, ref listOfSimplePoints, ref listOfMBPoints);
            //Work copies of the point lists:
            List <int> listOfSimplePoints_Copy = new List <int>(listOfSimplePoints);
            List <int> listOfMBPoints_Copy     = new List <int>(listOfMBPoints);

            List <int> listOfPenultimate = new List <int>();
            List <int> listOfLast        = new List <int>();


            while (listOfMBPoints_Copy.Count > 0)
            {
                int startPointInd = listOfMBPoints_Copy[0];
                fileOutput.AppendLine("\n StartPoint MB:" + startPointInd);

                KLOnePointGivenPaths_Assembly(matrAdjToSee, n, startPointInd, listOfComponents,
                                              listOfOrigins, listOfExtremePoints, ref listOfSimplePoints_Copy, listOfMBPoints,
                                              ref longestPattern, ref listOfPaths, ref listOfPenultimate, ref listOfLast, ref fileOutput,
                                              ref toleranceOk, ref listOfMatrAdj, ref listOfOutputPattern, ref listOfOutputPatternTwo,
                                              ref listOfIndicesOfLongestPath, SwModel, SwApplication);

                if (toleranceOk == false)
                {
                    fileOutput.AppendLine("\n \n WARNING: the program has been interrupted.");
                    fileOutput.AppendLine("The tolerance level is too rough: put a lower tolerance.");
                    listOfPathsOfPoints = null;
                    onlyShortPaths      = false;
                    return(false);
                }
                if (longestPattern == true)
                {
                    fileOutput.AppendLine("\n LongestPattern = true");
                    listOfPathsOfPoints = listOfPaths;
                    onlyShortPaths      = false;
                    return(true);
                }
                listOfMBPoints_Copy.Remove(startPointInd);
            }

            //At this point we exit from WHILE because ListOfMBPoints_copy.Count == 0:

            //now the MB points that could be StartPoint are finished or they have never existed
            if (listOfMBPoints.Count == 0 && listOfSimplePoints.Count > 0)
            // i.e. MB points have never existed (never entered the WHILE cycle)
            {
                // and there exists at connected component of at least 3 points (-> there esists a simple point)
                //I must start the "expansion" from a simple point!
                fileOutput.AppendLine("Non esistono MB points.");
                fileOutput.AppendLine("");

                var startPointInd = listOfSimplePoints[0]; //I take the first Simple point of the list

                KLOnePointGivenPaths_Assembly(matrAdjToSee, n, startPointInd, listOfComponents,
                                              listOfOrigins, listOfExtremePoints,
                                              ref listOfSimplePoints_Copy, listOfMBPoints, ref longestPattern, ref listOfPaths,
                                              ref listOfPenultimate, ref listOfLast, ref fileOutput, ref toleranceOk,
                                              ref listOfMatrAdj, ref listOfOutputPattern, ref listOfOutputPatternTwo, ref listOfIndicesOfLongestPath,
                                              SwModel, SwApplication);

                if (toleranceOk == false)
                {
                    fileOutput.AppendLine("\n \n WARNING: the program has been interrupted.");
                    listOfPathsOfPoints = null;
                    onlyShortPaths      = false;
                    return(false);
                }
                if (longestPattern == true)
                {
                    fileOutput.AppendLine("\n LongestPattern = true");
                    listOfPathsOfPoints = listOfPaths;
                    onlyShortPaths      = false;
                    return(true);
                }
            }
            else
            //here there are 3 cases: T+F I have to exit because I only have connected components of 2 centroids;
            //F+T and F+F I am sure I have at least a path created (penultimate points set exists), there is nothing to do in this case.
            {
                if (listOfMBPoints.Count == 0 && listOfSimplePoints.Count == 0) //T+F
                {
                    listOfPathsOfPoints = null;
                    onlyShortPaths      = true;
                    return(false);
                }
            }
            fileOutput.AppendLine("");
            fileOutput.AppendLine("Lista dei penultimi punti alla fine dei MB come StartPoint:");
            foreach (int ind in listOfPenultimate)
            {
                fileOutput.AppendLine("* " + ind);
            }

            //At this point at least one path has been created. The list of penultimate point is surely not void.

            //I remove all Simple points I already passed through up to now.
            listOfSimplePoints_Copy.RemoveAll(
                point => listOfPaths.FindIndex(pathObject => pathObject.path.Contains(point)) != -1);

            fileOutput.AppendLine("");
            fileOutput.AppendLine("Lista Simple Point per cui non si è ancora passati:");
            foreach (int ind in listOfSimplePoints_Copy)
            {
                fileOutput.AppendLine("* " + ind);
            }

            // Now, if there is a penultimate point available in the list I use it as StartPoint
            // else I use a Simple Point not belonging to any path (the point is in ListOfSimplePoints_copy)

            int numOfPenultimate = listOfPenultimate.Count;

            fileOutput.AppendLine("");
            fileOutput.AppendLine("Numero di penultimi punti: " + numOfPenultimate);
            int numOfSimple = listOfSimplePoints_Copy.Count;

            fileOutput.AppendLine("");
            fileOutput.AppendLine("Numero di Simple punti in cui non si è ancora passati: " + numOfPenultimate + numOfSimple);

            while (numOfPenultimate + numOfSimple > 0)
            {
                if (numOfPenultimate > 0)
                {
                    // I look for a path with the first available "penultimate point" as StartPoint and I move towards of the relative "last point"
                    fileOutput.AppendLine(" uso un penultimo punto: " + listOfPenultimate[0] + " verso " +
                                          listOfLast[0]);
                    int startPointInd  = listOfPenultimate[0];
                    int secondPointInd = listOfLast[0];

                    KLTwoPointsGivenPaths_Assembly(matrAdjToSee, n, startPointInd, secondPointInd, listOfComponents,
                                                   listOfOrigins, listOfExtremePoints, ref listOfSimplePoints_Copy, listOfMBPoints,
                                                   ref longestPattern, ref listOfPaths, ref listOfPenultimate, ref listOfLast, ref fileOutput,
                                                   ref toleranceOk, ref listOfMatrAdj, ref listOfOutputPattern, ref listOfOutputPatternTwo,
                                                   ref listOfIndicesOfLongestPath, SwModel, SwApplication);

                    listOfPenultimate.Remove(startPointInd);
                    listOfLast.Remove(secondPointInd);
                }
                else // => NumOfSimple > 0
                {
                    fileOutput.AppendLine(" uso un Simple punto: " + listOfSimplePoints_Copy[0]);
                    var startPointInd = listOfSimplePoints_Copy[0];

                    KLOnePointGivenPaths_Assembly(matrAdjToSee, n, startPointInd, listOfComponents,
                                                  listOfOrigins, listOfExtremePoints,
                                                  ref listOfSimplePoints_Copy, listOfMBPoints, ref longestPattern, ref listOfPaths,
                                                  ref listOfPenultimate, ref listOfLast, ref fileOutput, ref toleranceOk,
                                                  ref listOfMatrAdj, ref listOfOutputPattern, ref listOfOutputPatternTwo,
                                                  ref listOfIndicesOfLongestPath, SwModel, SwApplication);
                }

                //Check if tolerance level is ok:
                if (toleranceOk == false)
                {
                    fileOutput.AppendLine("\n \n WARNING: the program has been interrupted.");
                    fileOutput.AppendLine("The tolerance level is too rough: put a lower tolerance.");
                    listOfPathsOfPoints = null;
                    onlyShortPaths      = false;
                    return(false);
                }
                //Check if longestPattern == true:
                if (longestPattern == true)
                {
                    fileOutput.AppendLine("\n LongestPattern = true");
                    listOfPathsOfPoints = listOfPaths;
                    onlyShortPaths      = false;
                    return(true);
                }

                //I update the list of Simple points I have not passed through yet:
                listOfSimplePoints_Copy.RemoveAll(point => listOfPaths[listOfPaths.Count - 1].path.Contains(point));
                numOfSimple      = listOfSimplePoints_Copy.Count;
                numOfPenultimate = listOfPenultimate.Count;
            }


            //Last searching: I go through the branches of MB satisfying some characteristics..
            Part.PathCreation_Part.Functions.AddPathsFromNewCheckOfMB(matrAdjToSee, listOfOrigins, ref listOfPaths, listOfExtremePoints,
                                                                      listOfMBPoints, ref fileOutput, ref toleranceOk);

            if (toleranceOk == false)
            {
                fileOutput.AppendLine("\n \n WARNING: the program has been interrupted.");
                fileOutput.AppendLine("The tolerance level is too rough: put a lower tolerance.");
                listOfPathsOfPoints = null;
                onlyShortPaths      = false;
                return(false);
            }

            //I remove the longestPath, which was not geometrically verified but its path was kept in memory
            //not to find it again during the process (in fact tht process, whenever it finds a new seed path
            //of 3 centroids, verifies if a path containing these 3 centroids already exists):
            //listOfPaths.RemoveAt(listOfIndicesOfLongestPath);
            //            fileOutput.AppendLine("Numero di path prima della cancellazione dei longestPattern= " + listOfPaths.Count);
            listOfPaths.RemoveAll(path => listOfIndicesOfLongestPath.Contains(listOfPaths.IndexOf(path)));
            //            fileOutput.AppendLine("Numero di path dopo della cancellazione dei longestPattern= " + listOfPaths.Count);

            // I order the list of MyPathOfPoints by decreasing order respect to the length of the path,
            // if length is the same, first line and then circumference.
            listOfPaths =
                listOfPaths.OrderByDescending(x => x.path.Count)
                .ThenBy(y => y.pathGeometricObject.GetType() == typeof(MyLine) ? 0 : 1)
                .ToList();
            listOfPathsOfPoints = listOfPaths;
            onlyShortPaths      = false;
            return(false);
        }
示例#42
0
        /// <summary>
        /// Deletes the prop from the SW doc, assigning the SwApp object.
        /// </summary>
        /// <param name="sw"></param>
        public void Del(SldWorks sw)
        {
            if (sw != null) {
            SwApp = sw;
            ModelDoc2 md = (ModelDoc2)sw.ActiveDoc;
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

            CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
            CustomPropertyManager scpm;
            if (cf != null) {
              scpm = md.Extension.get_CustomPropertyManager(cf.Name);
            } else {
              scpm = md.Extension.get_CustomPropertyManager(string.Empty);
            }

            int res;

            if (Global)
              res = gcpm.Delete2(Name);
            else
              res = scpm.Delete2(Name);
              } else {
            throw new NullReferenceException("sw is null");
              }
        }
示例#43
0
        public static bool samePlane(Face2 firstFace, Face2 secondFace, SldWorks swApp)
        {
            var firstSurf  = (Surface)firstFace.GetSurface();
            var secondSurf = (Surface)secondFace.GetSurface();

            var firstParameters  = (Array)firstSurf.PlaneParams;
            var secondParameters = (Array)secondSurf.PlaneParams;

            var firstNormal = new double[3];
            var firstPoint  = new double[3];

            var secondNormal = new double[3];
            var secondPoint  = new double[3];

            Array.Copy(firstParameters, 0, firstNormal, 0, 3);
            Array.Copy(firstParameters, 3, firstPoint, 0, 3);

            Array.Copy(secondParameters, 0, secondNormal, 0, 3);
            Array.Copy(secondParameters, 3, secondPoint, 0, 3);

            if (!firstFace.FaceInSurfaceSense())
            {
                firstNormal.SetValue(-(double)firstNormal.GetValue(0), 0);
                firstNormal.SetValue(-(double)firstNormal.GetValue(1), 1);
                firstNormal.SetValue(-(double)firstNormal.GetValue(2), 2);
            }

            if (!secondFace.FaceInSurfaceSense())
            {
                secondNormal.SetValue(-(double)secondNormal.GetValue(0), 0);
                secondNormal.SetValue(-(double)secondNormal.GetValue(1), 1);
                secondNormal.SetValue(-(double)secondNormal.GetValue(2), 2);
            }

            var results     = Math.Abs(Matrix.InnerProduct(firstNormal, secondNormal) - 1);
            var normalPrint = String.Format("{0} {1} {2} --- {3} {4} {5} = {6}",
                                            firstNormal[0], firstNormal[1], firstNormal[2],
                                            secondNormal[0], secondNormal[1], secondNormal[2], results);

            var firstEquation = new double[4]
            {
                (double)firstNormal.GetValue(0), (double)firstNormal.GetValue(1), (double)firstNormal.GetValue(2),
                -(double)firstNormal.GetValue(0) * (double)firstPoint.GetValue(0) -
                (double)firstNormal.GetValue(1) * (double)firstPoint.GetValue(1) -
                (double)firstNormal.GetValue(2) * (double)firstPoint.GetValue(2),
            };
            var secondEquation = new double[4]
            {
                (double)secondNormal.GetValue(0), (double)secondNormal.GetValue(1), (double)secondNormal.GetValue(2),
                -(double)secondNormal.GetValue(0) * (double)secondPoint.GetValue(0) -
                (double)secondNormal.GetValue(1) * (double)secondPoint.GetValue(1) -
                (double)secondNormal.GetValue(2) * (double)secondPoint.GetValue(2),
            };


            var equationPrint = String.Format("Eq: {0}x {1}y {2}z = {3}",
                                              firstEquation[0], firstEquation[1], firstEquation[2], firstEquation[3]);

            /*
             * if (Math.Abs(Accord.Math.Matrix.InnerProduct(firstNormal, secondNormal) - 1) < 0.001)
             * {
             *  swApp.SendMsgToUser("Normale uguale");
             *  return false;
             * }
             */
            //return firstEquation.Equals(secondFace);
            if (Math.Abs(firstEquation[0] - secondEquation[0]) < 0.01 &&
                Math.Abs(firstEquation[1] - secondEquation[1]) < 0.01 &&
                Math.Abs(firstEquation[2] - secondEquation[2]) < 0.01 &&
                Math.Abs(firstEquation[3] - secondEquation[3]) < 0.01)
            {
                swApp.SendMsgToUser("Equazione uguale");
                return(true);
            }
            return(false);
        }
示例#44
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);
            }

            //查询参数
            KCJDB800 item = (KCJDB800)objKCJDB800Service.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}-3"));
                    swComp.SetSuppression2(2);                                           //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-7"));
                    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@Distance31").SystemValue     = item.FCSideLeft / 1000m;
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-3"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-7"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩
                    swFeat = swAssy.FeatureByName("LocalLPattern4");
                    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压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-7"));
                    swComp.SetSuppression2(2);                                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern5");
                    swFeat.SetSuppression2(1, 2, configNames);                 //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern5").SystemValue = fcNo; //D1阵列数量,D3阵列距离
                    swModel.Parameter("D1@Distance34").SystemValue     = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-9"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern3");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1"));
                    swComp.SetSuppression2(2);                                 //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-9"));
                    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@Distance33").SystemValue     = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m;
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-7"));
                    swComp.SetSuppression2(0);                 //2解压缩,0压缩.
                    swFeat = swAssy.FeatureByName("LocalLPattern5");
                    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-]{}-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(); //打开零件
                        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;
                        }
                    }
                    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压缩.
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-4"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;

                case "RIGHT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-4"));
                    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-]{}-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(); //打开零件
                        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;
                        }
                    }
                    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压缩.
                    }
                    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-]{}-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(); //打开零件
                        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;
                        }
                    }
                    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压缩.
                    }
                    //重命名装配体内部
                    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-]{}-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(); //打开零件
                        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;
                        }
                    }
                    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压缩.
                    }
                    break;

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-4"));
                    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, "FNCE0109[BP-]{}-4"));
                    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 = "FNCE0115[KCJDB800-" + tree.Module + "]{" + (int)item.Length + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0115-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压缩
                        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 = "FNCE0115[KCJDB800-" + tree.Module + "]{" + (int)item.Length + "}";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0115-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压缩
                        swPart.Parameter("D4@Sketch1").SystemValue = item.ExRightDis / 1000m;
                        swPart.Parameter("D2@Sketch1").SystemValue = item.ExLength / 1000m;
                        swPart.Parameter("D1@Sketch1").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("D2@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@Sketch10").SystemValue = item.ANDetectorDis2 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 2)
                                {
                                    swPart.Parameter("D2@Sketch10").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D2@Sketch10").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 2)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC3");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D3@Sketch11").SystemValue = item.ANDetectorDis3 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 3)
                                {
                                    swPart.Parameter("D1@Sketch11").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D1@Sketch11").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 3)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC4");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D2@Sketch12").SystemValue = item.ANDetectorDis4 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 4)
                                {
                                    swPart.Parameter("D3@Sketch12").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D3@Sketch12").SystemValue = 175m / 1000m;
                                }
                            }
                            if (item.ANDetectorNo > 4)
                            {
                                swFeat = swComp.FeatureByName("ANDTEC5");
                                swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                                swPart.Parameter("D3@Sketch13").SystemValue = item.ANDetectorDis5 / 1000m;
                                if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 5)
                                {
                                    swPart.Parameter("D1@Sketch13").SystemValue = 195m / 1000m;
                                }
                                else
                                {
                                    swPart.Parameter("D1@Sketch13").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压缩
                            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压缩
                        }

                        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, "FNCE0116-1"));
                swPart = swComp.GetModelDoc2();//打开零件
                swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m;
                swFeat = swComp.FeatureByName("FC SUPPORT");
                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                swFeat = swComp.FeatureByName("FC SUPPORT B");
                swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                swFeat = swComp.FeatureByName("JAP LED M8");
                if (item.Japan == "YES")
                {
                    swFeat.SetSuppression2(1, 2, configNames);                      //参数1:1解压,0压缩
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                }
                swFeat = swComp.FeatureByName("LIGHT T8");
                if (item.LightType == "T8")
                {
                    swFeat.SetSuppression2(1, 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, "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-7"));
                    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-7"));
                    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的使用
            }
        }
示例#45
0
        //The following runs when a new instance of the class is created
        public URDFExporterPM(SldWorks swAppPtr)
        {
            swApp = swAppPtr;
            ActiveSWModel = swApp.ActiveDoc;
            Exporter = new URDFExporter(swApp);
            Exporter.mRobot = new robot();
            Exporter.mRobot.name = ActiveSWModel.GetTitle();

            linksToVisit = new List<link>();
            docMenu = new ContextMenuStrip();

            string PageTitle = null;
            string caption = null;
            string tip = null;
            long options = 0;
            int longerrors = 0;
            int controlType = 0;
            int alignment = 0;
            string[] listItems = new string[4];

            ActiveSWModel.ShowConfiguration2("URDF Export");

            #region Create and instantiate components of PM page
            //Set the variables for the page
            PageTitle = "URDF Exporter";
            //options = (int)swPropertyManagerButtonTypes_e.swPropertyManager_OkayButton + (int)swPropertyManagerButtonTypes_e.swPropertyManager_CancelButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_PushpinButton;
            options = (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_OkayButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_CancelButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_HandleKeystrokes;

            //Create the PropertyManager page
            pm_Page = (PropertyManagerPage2)swApp.CreatePropertyManagerPage(PageTitle, (int)options, this, ref longerrors);

            //Make sure that the page was created properly
            if (longerrors == (int)swPropertyManagerPageStatus_e.swPropertyManagerPage_Okay)
            {
                setupPropertyManagerPage(ref caption, ref tip, ref options, ref controlType, ref alignment);
            }

            else
            {
                //If the page is not created
                System.Windows.Forms.MessageBox.Show("An error occurred while attempting to create the " + "PropertyManager Page");
            }

            #endregion
        }
        private void button_create_Geom_Click(object sender, RoutedEventArgs e)
        {
            #region a test example, not important
            m         = 9;
            width     = 8 / 1000.0;
            thickness = 1 / 1000.0;
            l1        = 30 / 1000.0;
            l2        = 16 / 1000.0;
            l3        = 21 / 1000.0;
            F1        = 1;
            F2        = 37;
            F3        = 49;

            l4          = l2;
            l1_         = l1 - 2 * width;
            l2_         = l2;
            l3_         = l3 + 2 * width;
            l4_         = l4;
            cell_length = l1 + l3;
            cell_height = l2 + width;
            #endregion

            Count = int.Parse(textBox_count.Text);
            Random randomSeed       = new Random();
            Random random_m         = new Random(randomSeed.Next());
            Random random_width     = new Random(randomSeed.Next());
            Random random_thickness = new Random(randomSeed.Next());
            Random random_l1        = new Random(randomSeed.Next());
            Random random_l2        = new Random(randomSeed.Next());
            Random random_l3        = new Random(randomSeed.Next());
            Random random_F1        = new Random(randomSeed.Next());
            Random random_F2        = new Random(randomSeed.Next());
            Random random_F3        = new Random(randomSeed.Next());

            for (int j = 0; j < Count; j++)
            {
                Console.WriteLine(string.Format("---------------------------------now No.{0}", j));

                #region generate random Data
                try
                {
                    /* change to double
                     * ran_m = random_m.Next(int.Parse(textBox_hm_cells_min.Text), int.Parse(textBox_hm_cellls_max.Text));
                     * ran_width = random_width.Next(int.Parse(textBox_width_min.Text), int.Parse(textBox_width_max.Text));
                     * ran_thickness = random_thickness.Next(int.Parse(textBox_thickness_min.Text), int.Parse(textBox_thickness_max.Text));
                     * ran_l1 = random_l1.Next(int.Parse(textBox_l1_min.Text), int.Parse(textBox_l1_max.Text));
                     * ran_l2 = random_l2.Next(int.Parse(textBox_l2_min.Text), int.Parse(textBox_l2_max.Text));
                     * ran_l3 = random_l3.Next(int.Parse(textBox_l3_min.Text), int.Parse(textBox_l3_max.Text));
                     * ran_F1 = random_F1.Next(int.Parse(textBox_F1_min.Text), int.Parse(textBox_F1_max.Text));
                     * ran_F2 = random_F2.Next(int.Parse(textBox_F2_min.Text), int.Parse(textBox_F2_max.Text));
                     * ran_F3 = random_F3.Next(int.Parse(textBox_F3_min.Text), int.Parse(textBox_F3_max.Text));
                     */
                    ran_m         = random_m.Next(int.Parse(textBox_hm_cells_min.Text), int.Parse(textBox_hm_cellls_max.Text));
                    ran_width     = random_width.NextDouble() * (int.Parse(textBox_width_max.Text) - int.Parse(textBox_width_min.Text)) + double.Parse(textBox_width_min.Text);
                    ran_thickness = random_thickness.NextDouble() * (int.Parse(textBox_thickness_max.Text) - int.Parse(textBox_thickness_min.Text)) + double.Parse(textBox_thickness_min.Text);
                    ran_l1        = random_l1.NextDouble() * (int.Parse(textBox_l1_max.Text) - int.Parse(textBox_l1_min.Text)) + double.Parse(textBox_l1_min.Text);
                    ran_l2        = random_l2.NextDouble() * (int.Parse(textBox_l2_max.Text) - int.Parse(textBox_l2_min.Text)) + double.Parse(textBox_l2_min.Text);
                    ran_l3        = random_l3.NextDouble() * (int.Parse(textBox_l3_max.Text) - int.Parse(textBox_l3_min.Text)) + double.Parse(textBox_l3_min.Text);
                    ran_F1        = random_F1.NextDouble() * (int.Parse(textBox_F1_max.Text) - int.Parse(textBox_F1_min.Text)) + double.Parse(textBox_F1_min.Text);
                    ran_F2        = random_F2.NextDouble() * (int.Parse(textBox_F2_max.Text) - int.Parse(textBox_F2_min.Text)) + double.Parse(textBox_F2_min.Text);
                    ran_F3        = random_F3.NextDouble() * (int.Parse(textBox_F3_max.Text) - int.Parse(textBox_F3_min.Text)) + double.Parse(textBox_F3_min.Text);
                }
                catch (Exception)
                {
                    Console.WriteLine("Input Format Error");
                    return;
                }


                m         = ran_m;
                width     = (double)(ran_width / 1000.0);
                thickness = (double)(ran_thickness / 1000.0);
                l1        = (double)(ran_l1 / 1000.0);
                l2        = (double)(ran_l2 / 1000.0);
                l3        = (double)(ran_l3 / 1000.0);

                F1 = (double)ran_F1;
                F2 = (double)ran_F2;
                F3 = (double)ran_F3;
                F3 = 0;

                l4          = l2;
                l1_         = l1 - 2 * width;
                l2_         = l2;
                l3_         = l3 + 2 * width;
                l4_         = l4;
                cell_length = l1 + l3;
                cell_height = l2 + width;


                #endregion



                Console.WriteLine(string.Format("{0},{1},{2},{3},{4},{5}", m, width, thickness, l1, l2, l3));

                #region geometrie
                Console.WriteLine("Start creating new Germetrie");

                try
                {
                    swModel = swApp.NewPart();
                }
                catch (Exception)
                {
                    Console.WriteLine("starting SolidWorks");
                    try
                    {
                        swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
                    }
                    catch (Exception)
                    {
                        swApp         = new SldWorks();
                        swApp.Visible = false;
                    }

                    //get MaterialLib
                    strMaterialLib = swApp.GetExecutablePath() + "\\lang\\english\\sldmaterials\\solidworks materials.sldmat";

                    Console.WriteLine("SolidWorks successfully started");
                    j--;
                    continue;
                }

                swModel.Extension.SelectByID("前视基准面", "PLANE", 0, 0, 0, false, 1, null);
                swModel.InsertSketch2(true);
                #region sketch
                for (int i = 0; i < m; i++)
                {
                    if (i == 0)
                    {
                        swModel.SketchManager.CreateLine(0, 0, 0, l1 - width, 0, 0);
                        swModel.SketchManager.CreateLine(l1 - width, 0, 0, l1 - width, -l2, 0);
                        swModel.SketchManager.CreateLine(l1 - width, -l2, 0, l1 + l3 - width, -l2, 0);
                        swModel.SketchManager.CreateLine(l1 + l3 - width, -l2, 0, l1 + l3 - width, 0, 0);

                        swModel.SketchManager.CreateLine(0, 0, 0, 0, -width, 0);
                        swModel.SketchManager.CreateLine(0, -width, 0, l1_, -width, 0);
                        swModel.SketchManager.CreateLine(l1_, -width, 0, l1_, -(width + l2_), 0);
                        swModel.SketchManager.CreateLine(l1_, -(width + l2_), 0, l1_ + l3_, -(width + l2_), 0);
                        swModel.SketchManager.CreateLine(l1_ + l3_, -(width + l2_), 0, l1_ + l3_, -width, 0);
                    }
                    else
                    {
                        x_o  = i * cell_length - width;
                        y_o  = 0;
                        x_o_ = x_o + width;
                        y_o_ = y_o - width;

                        swModel.SketchManager.CreateLine(x_o, y_o, 0, x_o + l1, 0, 0);
                        swModel.SketchManager.CreateLine(x_o + l1, 0, 0, x_o + l1, -l2, 0);
                        swModel.SketchManager.CreateLine(x_o + l1, -l2, 0, x_o + l1 + l3, -l2, 0);
                        swModel.SketchManager.CreateLine(x_o + l1 + l3, -l2, 0, x_o + l1 + l3, 0, 0);

                        swModel.SketchManager.CreateLine(x_o_, y_o_, 0, x_o_ + l1_, y_o_, 0);
                        swModel.SketchManager.CreateLine(x_o_ + l1_, y_o_, 0, x_o_ + l1_, y_o_ - l2_, 0);
                        swModel.SketchManager.CreateLine(x_o_ + l1_, y_o_ - l2_, 0, x_o_ + l1_ + l3_, y_o_ - l2_, 0);
                        swModel.SketchManager.CreateLine(x_o_ + l1_ + l3_, y_o_ - l2_, 0, x_o_ + l1_ + l3_, y_o_, 0);
                    }
                }
                swModel.SketchManager.CreateLine(x_o_ + l1_ + l3_, y_o_, 0, x_o_ + l1_ + l3_, 0, 0);
                swModel.SketchManager.CreateLine(x_o_ + l1_ + l3_, 0, 0, x_o + l1 + l3, 0, 0);

                #endregion
                swModel.FeatureManager.FeatureExtrusion2(
                    true, false, false, 0, 0, thickness, 0, false, false, false, false, 0, 0, false, false, false, false, true, true, true, 0, 0, true
                    );

                swModel.SaveAsSilent("D:\\TUD\\7.Semeter\\SA\\SA_code\\c#\\W_Form_analyse_get_TrainingDaten\\Geometrie.sldprt", true);
                swApp.CloseAllDocuments(true);
                swApp.OpenDoc("D:\\TUD\\7.Semeter\\SA\\SA_code\\c#\\W_Form_analyse_get_TrainingDaten\\Geometrie.sldprt", (int)swOpenDocOptions_e.swOpenDocOptions_Silent);
                Console.WriteLine("Geometrie success");


                #endregion

                #region simulaiton
                string path_to_cosworks_dll = @"C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\Simulation\cosworks.dll";
                errors       = swApp.LoadAddIn(path_to_cosworks_dll);
                COSMOSObject = (CwAddincallback)swApp.GetAddInObject("SldWorks.Simulation");
                try
                {
                    COSMOSWORKS = (CosmosWorks)COSMOSObject.CosmosWorks;
                }
                catch (Exception)
                {
                    Console.WriteLine("something wrong in Simulaiton Add In, start a new one");
                    continue;
                }


                COSMOSWORKS = COSMOSObject.CosmosWorks;
                //Get active document
                ActDoc = (CWModelDoc)COSMOSWORKS.ActiveDoc;

                //Create new static study
                StudyMngr = (CWStudyManager)ActDoc.StudyManager;
                Study     = (CWStudy)StudyMngr.CreateNewStudy("static study", (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeStatic, 0, out errCode);

                //Add materials
                SolidMgr  = Study.SolidManager;
                SolidComp = SolidMgr.GetComponentAt(0, out errCode);
                SolidBody = SolidComp.GetSolidBodyAt(0, out errCode);
                intStatus = SolidBody.SetLibraryMaterial(strMaterialLib, "AISI 1020");

                //fixed restraints
                LBCMgr = Study.LoadsAndRestraintsManager;

                swModel = (ModelDoc2)swApp.ActiveDoc;
                swModel.ShowNamedView2("", (int)swStandardViews_e.swIsometricView);

                selectionMgr = (SelectionMgr)swModel.SelectionManager;
                isSelected   = swModel.Extension.SelectByID2("", "FACE", 0, -width / 2.0, thickness / 2.0, false, 0, null, 0);
                if (isSelected)
                {
                    object      selectedFace = (object)selectionMgr.GetSelectedObject6(1, -1);
                    object[]    fixedFaces   = { selectedFace };
                    CWRestraint restraint    = (CWRestraint)LBCMgr.AddRestraint((int)swsRestraintType_e.swsRestraintTypeFixed, fixedFaces, null, out errCode);
                }
                swModel.ClearSelection2(true);

                //add force
                selectionMgr = (SelectionMgr)swModel.SelectionManager;
                isSelected   = swModel.Extension.SelectByID2("", "FACE", x_o + l1 + l3 + (width / 2.0), 0, thickness / 2.0, false, 0, null, 0);
                if (isSelected)
                {
                    object   selectedFace = (object)selectionMgr.GetSelectedObject6(1, -1);
                    object[] forceAdd     = { selectedFace };
                    selectionMgr = (SelectionMgr)swModel.SelectionManager;
                    swModel.Extension.SelectByID2("", "FACE", x_o + l1 + l3 + width, -(l4 + width) / 2.0, thickness / 2.0, false, 0, null, 0);
                    object   selectedFaceToForceDir = (object)selectionMgr.GetSelectedObject6(1, -1);
                    double[] distValue  = null;
                    double[] forceValue = null;
                    double[] Force      = { F2, F3, F1 };
                    cwForce = (CWForce)LBCMgr.AddForce3((int)swsForceType_e.swsForceTypeForceOrMoment, (int)swsSelectionType_e.swsSelectionFaceEdgeVertexPoint,
                                                        2, 0, 0, 0,
                                                        (distValue),
                                                        (forceValue),
                                                        false, true,
                                                        (int)swsBeamNonUniformLoadDef_e.swsTotalLoad,
                                                        0, 7, 0.0,
                                                        Force,
                                                        false, false,
                                                        (forceAdd),
                                                        (selectedFaceToForceDir),
                                                        false, out errCode); //i have tried to figure out these arguments for one day, keep them and dont't change them.
                                                                             //the way to check cwForce : cwForce.GetForceComponentValues()
                                                                             //ForceComponet: [int b1, // 1 if x-direction hat Force-komponent, else 0
                                                                             //                int b2, // 1 if y-direction hat Force-komponent, else 0
                                                                             //                int b3, // 1 if z-direction hat Force-komponent, else 0
                                                                             //                double d1, // Force-komponent in x
                                                                             //                double d2, // Force-komponent in y
                                                                             //                double d3 // Force-komponent in z
                                                                             //                          ]
                                                                             //PS: the definition of xyz seems like not the same as the global XYZ system in SW.
                    swModel.ClearSelection2(true);

                    //meshing
                    CWMesh CWMeshObj = default(CWMesh);
                    CWMeshObj            = Study.Mesh;
                    CWMeshObj.MesherType = (int)swsMesherType_e.swsMesherTypeStandard;
                    CWMeshObj.Quality    = (int)swsMeshQuality_e.swsMeshQualityDraft;
                    errCode   = Study.CreateMesh(0, MeshEleSize, MeshTol);
                    CWMeshObj = null;

                    //run analysis
                    errCode = Study.RunAnalysis();
                    if (errCode != 0)
                    {
                        Console.WriteLine(string.Format("RunAnalysis errCode = {0}", errCode));
                        Console.WriteLine(string.Format("RunAnalysis failed"));



                        swApp.CloseAllDocuments(true);
                        errors = swApp.UnloadAddIn(path_to_cosworks_dll);
                        Console.WriteLine(string.Format("ready to start a new one"));
                        continue;
                    }
                    Console.WriteLine("RunAnalysis successed, ready to get results");

                    //get results
                    CWFeatobj = Study.Results;
                    //get max von Mieses stress
                    Stress = (object[])CWFeatobj.GetMinMaxStress((int)swsStressComponent_e.swsStressComponentVON,
                                                                 0, 0, null,
                                                                 (int)swsStrengthUnit_e.swsStrengthUnitNewtonPerSquareMillimeter,
                                                                 out errCode);
                    maxStress = (float)Stress[3]; //Stress: {node_with_minimum_stress, minimum_stress, node_with_maximum_stress, maximum_stress}
                    Console.WriteLine(maxStress);

                    /*
                     * if (maxStress >= 351.6)
                     * {
                     *  Console.WriteLine("out of yield stress, start a new example");
                     *  errors = swApp.UnloadAddIn(path_to_cosworks_dll);
                     *  swApp.CloseAllDocuments(true);
                     *  j--;
                     *  continue;
                     * }
                     */
                    //get max URES displacement
                    Disp = (object[])CWFeatobj.GetMinMaxDisplacement((int)swsDisplacementComponent_e.swsDisplacementComponentURES,
                                                                     0, null,
                                                                     (int)swsLinearUnit_e.swsLinearUnitMillimeters,
                                                                     out errCode);
                    maxDisp   = (float)Disp[3]; //Disp: {node_with_minimum_displacement, minimum_displacement, node_with_maximum_displacement, maximum_displacement}
                    CWFeatobj = null;
                    Console.WriteLine(string.Format("max Displacement: {0:f4} mm", maxDisp));


                    //output to Excel
                    exlSheet.Cells[j + 2, 1]  = m;
                    exlSheet.Cells[j + 2, 2]  = width * 1000;
                    exlSheet.Cells[j + 2, 3]  = thickness * 1000;
                    exlSheet.Cells[j + 2, 4]  = l1 * 1000;
                    exlSheet.Cells[j + 2, 5]  = l2 * 1000;
                    exlSheet.Cells[j + 2, 6]  = l3 * 1000;
                    exlSheet.Cells[j + 2, 7]  = F1;
                    exlSheet.Cells[j + 2, 8]  = F2;
                    exlSheet.Cells[j + 2, 9]  = F3;
                    exlSheet.Cells[j + 2, 10] = maxStress;
                    exlSheet.Cells[j + 2, 11] = maxDisp;
                    if (j % 5 == 0)
                    {
                        exlBook.Save();//C:\Users\Zhao\Documents\工作簿1.xlsx
                    }

                    errors = swApp.UnloadAddIn(path_to_cosworks_dll);
                    swApp.CloseAllDocuments(true);
                }
                #endregion
            }
            exlBook.SaveCopyAs("D:\\TUD\\7.Semeter\\SA\\SA_code\\c#\\W_Form_analyse_get_TrainingDaten\\W_Form_simulationDaten_" + GetTimeStamp() + "_F3=0" + ".xlsx");
            exlBook.Save();//C:\Users\zhaojie\Documents\工作簿1.xlsx
            exlApp.Quit();
        }
示例#47
0
        /// <summary>
        /// Called when this add in is loaded by solidworks.
        /// Allocates necessary resources for runtime.
        /// </summary>
        /// <param name="ThisSW">An instance of ISldWorks used to interact with the Solidworks application.</param>
        /// <param name="cookie">ID of this addin in the current Solidworks environment</param>
        /// <returns></returns>
        public bool ConnectToSW(object ThisSW, int cookie)
        {
            iSwApp = (SldWorks)ThisSW;
            addinID = cookie;
            RobotInfo.ClearLog();
            try
            {
                //Setup callbacks
                iSwApp.SetAddinCallbackInfo(0, this, addinID);

                Storage.StorageModel.DefineAttributes(iSwApp);

                //Setup the command managers
                cmdMgr = new CommandManager(iSwApp);

                AttachmentFactory.InitializeFactory();

                //Setup the document Manager
                iSwApp.ActiveDocChangeNotify += new DSldWorksEvents_ActiveDocChangeNotifyEventHandler(OnDocChange);

            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
示例#48
0
        private const string ШаблонЧертежаРазверткиВнеХранилища = "flattpattern.drwdot";//@"C:\flattpattern.drwdot";

        public void CreateFlattPatternUpdateCutlistAndEdrawing()
        {

            #region Сбор информации по детали и сохранение разверток

            //SldWorks swApp = null;
            try
            {
                var swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
                swApp = new SldWorks { Visible = true };

                IModelDoc2 swModel = swApp.IActiveDoc2;
                swModel.Extension.ViewDisplayRealView = false;

                if (!IsSheetMetalPart((IPartDoc)swModel))
                {
                    MessageBox.Show("Деталь не из листового материала");
                }

                string[] swModelConfNames;


                var activeconfiguration = (Configuration)swModel.GetActiveConfiguration();
                swModelConfNames = (string[])swModel.GetConfigurationNames();


                var swModelConfNames2 = (string[])swModel.GetConfigurationNames();

                try
                {
                    foreach (var configName in from name in swModelConfNames2
                                               let config = (Configuration)swModel.GetConfigurationByName(name)
                                               where !config.IsDerived()
                                               select name)
                    {
                        swModel.ShowConfiguration2(configName);
                        swModel.EditRebuild3();

                        FileInfo template = null;

                        try
                        {
                            template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища);
                            //MessageBox.Show(template.FullName);

                            Thread.Sleep(1000);
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.ToString());
                            template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища);
                            Thread.Sleep(1000);

                        }
                        finally
                        {
                            if (template == null)
                            {
                                template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища);
                            }
                        }

                        //MessageBox.Show(template.FullName);

                        var swDraw = (DrawingDoc)swApp.INewDocument2(template.FullName, (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594);

                        swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, false);

                        ((IModelDoc2)swDraw).ForceRebuild3(true);


                        #region Разгибание всех сгибов

                        try
                        {
                            swModel.EditRebuild3();
                            var swPart = (IPartDoc)swModel;

                            Feature swFeature = swPart.FirstFeature();
                            const string strSearch = "FlatPattern";
                            while (swFeature != null)
                            {
                                var nameTypeFeature = swFeature.GetTypeName2();

                                if (nameTypeFeature == strSearch)
                                {
                                    swFeature.Select(true);
                                    swPart.EditUnsuppress();

                                    Feature swSubFeature = swFeature.GetFirstSubFeature();
                                    while (swSubFeature != null)
                                    {
                                        var nameTypeSubFeature = swSubFeature.GetTypeName2();

                                        if (nameTypeSubFeature == "UiBend")
                                        {
                                            swFeature.Select(true);
                                            swPart.EditUnsuppress();
                                            swModel.EditRebuild3();

                                            try
                                            {
                                                swSubFeature.SetSuppression2(
                                                    (int)swFeatureSuppressionAction_e.swUnSuppressFeature,
                                                    (int)swInConfigurationOpts_e.swAllConfiguration,
                                                    swModelConfNames2);
                                            }
                                            catch (Exception){}

                                        }
                                        swSubFeature = swSubFeature.GetNextSubFeature();
                                    }
                                }
                                swFeature = swFeature.GetNextFeature();
                            }
                            swModel.EditRebuild3();
                        }

                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message);
                        }

                        #endregion

                        swModel.ForceRebuild3(false);

                        var thikness = GetFromCutlist(swModel, "Толщина листового металла");

                        var errors = 0;
                        var warnings = 0;
                        var newDxf = (IModelDoc2)swDraw;
                        try
                        {
                            Directory.CreateDirectory("C:\\Dxf\\");
                        }
                        catch (Exception){}

                        newDxf.Extension.SaveAs(
                            "C:\\Dxf\\" + Path.GetFileNameWithoutExtension(swModel.GetPathName()) + "-" + configName + "-" + thikness + ".dxf",
                            (int)swSaveAsVersion_e.swSaveAsCurrentVersion,
                            (int)swSaveAsOptions_e.swSaveAsOptions_UpdateInactiveViews, null, ref errors, ref warnings);

                        swApp.CloseDoc(Path.GetFileName(newDxf.GetPathName()));
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }

                try
                {
                    swModel.ShowConfiguration2(activeconfiguration.Name);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }

                #endregion
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
示例#49
0
        /// <summary>
        /// Constructor for setting up the link property manager page
        /// </summary>
        /// <param name="robot">The robot model</param>
        /// <param name="link">The link that will be edited</param>
        /// <param name="document">Active assembly document</param>
        /// <param name="swApp">The solidworks app</param>
        public LinkPMPage(RobotModel robot, AssemblyDoc document, SldWorks swApp, int type)
        {
            //Validate parameters
            if (robot == null)
                throw new ProgramErrorException("Tried to create a LinkEditorPMPage with a null robot model.");
            if (document == null)
                throw new ProgramErrorException("Tried to create a LinkEditorPMPage with a null assembly document.");
            if (swApp == null)
                throw new ProgramErrorException("Tried to create a LinkEditorPMPage with a null solidworks application interface.");

            //Initialize fields
            this.robot = robot;
            this.swApp = swApp;
            this.linksColored = false;
            currentModelConfig = type;

            //AssemblyDoc inherits ModelDoc2 but the relationship dosn't carry through the COM interface
            //Having two fields prevents having to cast half of the time
            modelDoc = (ModelDoc2)document;
            assemblyDoc = document;

            //Setup the page, its controls and their visual layout
            SetupPage();
        }
示例#50
0
 public void SetSwApp(SldWorks swApp)
 {
     this.swApp = swApp;
 }
示例#51
0
        /// <summary>
        /// Directly draws from SW, assinging SwApp.
        /// </summary>
        /// <param name="sw">SwApp</param>
        public void Get(SldWorks sw)
        {
            if (sw != null) {
            this.SwApp = sw;
            ModelDoc2 md = (ModelDoc2)sw.ActiveDoc;
            Configuration cf = md.ConfigurationManager.ActiveConfiguration;

            CustomPropertyManager gcpm = md.Extension.get_CustomPropertyManager(string.Empty);
            CustomPropertyManager scpm;

            bool wasResolved;
            bool useCached = false;
            string tempval = string.Empty;
            string tempresval = string.Empty;

            if (cf != null) {
              scpm = md.Extension.get_CustomPropertyManager(cf.Name);
            } else {
              scpm = md.Extension.get_CustomPropertyManager(string.Empty);
            }

            if (SWCustPropMgr != null) {
              scpm = SWCustPropMgr;
            }

            int res;

            if (this.Global) {
              res = gcpm.Get5(this.Name, useCached, out tempval, out tempresval, out wasResolved);
              if (wasResolved) {
            Value = tempval;
            ResValue = tempresval;
            Type = (swCustomInfoType_e)gcpm.GetType2(this.Name);
              }

              if (Type == swCustomInfoType_e.swCustomInfoNumber && Name.ToUpper().Contains("OVER"))
            Type = swCustomInfoType_e.swCustomInfoDouble;
            } else {
              res = scpm.Get5(Name, useCached, out tempval, out tempresval, out wasResolved);
              if (wasResolved) {
            Value = tempval;
            ResValue = tempresval;
            Type = (swCustomInfoType_e)scpm.GetType2(this.Name);
              }
            }
              } else {
            throw new NullReferenceException("sw is null");
              }
        }
示例#52
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);
            }

            //查询参数
            LLKS item = (LLKS)objLLKSService.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 sideLength  = (item.Length - 17m - item.LongGlassNo * 1175m - item.ShortGlassNo * 575m) / 2;//长玻璃1158+17,558+17
            int     longGlassNo = item.LongGlassNo;

            while (sideLength < 29m)
            {
                sideLength = sideLength + 1175m / 2m;//如果侧板太短,则减一块玻璃
                longGlassNo--;
            }

            try
            {
                //----------Top Level----------
                swModel.Parameter("D1@Distance3").SystemValue = item.Length / 1000m;
                //----------边缘板----------
                //重命名装配体内部
                compReName = "FNCL0025[LLKS-" + tree.Module + "]{" + (int)sideLength + "}";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0025[LLKS-]{}-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 = sideLength / 1000m;
                }

                //----------长玻璃----------
                if (longGlassNo > 0)
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600010-7"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600010-7"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }
                swFeat = swAssy.FeatureByName("LocalLPattern1");
                if (longGlassNo > 1)
                {
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern1").SystemValue = longGlassNo;
                }
                else
                {
                    swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                }
                //----------短玻璃----------
                if (item.ShortGlassNo > 0)
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600011-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-6"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600011-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-6"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }
                swFeat = swAssy.FeatureByName("LocalLPattern2");
                if (item.ShortGlassNo > 1)
                {
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern2").SystemValue = item.ShortGlassNo;
                }
                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的使用
            }
        }
 /*bool firstRotPoint;
 MathPoint startPoint;
 MathPoint endPoint;
 */
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="att">The attachment to be used</param>
 /// <param name="swApp">The Solidworks App</param>
 public AttachmentPMPage(DirectionalAttachment att, SldWorks swApp)
 {
     currentAttachment = att;
     this.swApp = swApp;
     modelDoc = swApp.ActiveDoc;
     swModeler = swApp.GetModeler();
     SetupPage();
 }
示例#54
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);
            }

            //查询参数
            LKASPEC item = (LKASPEC)objLKASPECService.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----------
                //----------侧板----------
                switch (item.SidePanel)
                {
                case "LEFT":
                case "RIGHT":
                    //重命名装配体内部
                    compReName = "FNCL0018[LKEC-" + tree.Module + "]{255}(" + (int)(item.Height - 5m) + ")";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0032[LKEC-]{255}()-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("D1@Sketch1").SystemValue = (item.Height - 5m) / 1000m;
                        swComp = swAssy.GetComponentByName(compReName + "-4");
                        swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0016[LKRP-S]{80}-6"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0016[LKRP-S]{80}-7"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0017[LKRP-T]{250}-3"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

                case "MIDDLE":
                    //重命名装配体内部
                    compReName = "FNCL0032[LKEC-" + tree.Module + "]{255}(" + (int)(item.Height - 5m) + ")";
                    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(0);     //2解压缩,0压缩.
                        swComp = swAssy.GetComponentByName(compReName + "-4");
                        swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    }
                    else
                    {
                        swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0032[LKEC-]{255}()-3"));
                        swComp.SetSuppression2(0);     //2解压缩,0压缩.
                        swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0032[LKEC-]{255}()-4"));
                        swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0016[LKRPS]{80}-6"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0016[LKRPS]{80}-7"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0017[LKRPT]{250}-3"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

                default:
                    //重命名装配体内部
                    compReName = "FNCL0032[LKEC-" + tree.Module + "]{255}(" + (int)(item.Height - 5m) + ")";
                    status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0032[LKEC-]{255}()-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("D1@Sketch1").SystemValue = (item.Height - 5m) / 1000m;
                        swComp = swAssy.GetComponentByName(compReName + "-2");
                        swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    }
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0016[LKRPS]{80}-6"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0016[LKRPS]{80}-7"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0017[LKRPT]{250}-3"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }


                //----------灯腔主体----------
                //重命名装配体内部
                compReName = "FNCL0002[LKASPEC-" + tree.Module + "]{" + (int)item.Length + "}";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0002-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;
                    swPart.Parameter("D7@Kante-Lasche1").SystemValue = item.Height / 1000m;
                    swFeat = swComp.FeatureByName("Cut-Extrude2");
                    if (item.Japan == "YES")
                    {
                        swFeat.SetSuppression2(0, 2, configNames);                      //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(1, 2, configNames);  //参数1:1解压,0压缩
                    }
                    swFeat = swComp.FeatureByName("LIGHT T8");
                    if (item.LightType == "T8")
                    {
                        swFeat.SetSuppression2(1, 2, configNames);                         //参数1:1解压,0压缩
                    }
                    else
                    {
                        swFeat.SetSuppression2(0, 2, configNames);  //参数1:1解压,0压缩
                    }
                }
                if (item.Japan == "YES")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-1"));
                    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-1"));
                    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的使用
            }
        }
        public static void FindComposedPatterns(List <MyGroupingSurfaceForPatterns> listOfGroupingSurfaceForPatterns,
                                                out List <MyComposedPattern> listOfOutputComposedPattern,
                                                out List <MyComposedPattern> listOfOutputComposedPatternTwo, ModelDoc2 SwModel,
                                                SldWorks mySwApplication, ref StringBuilder fileOutput)

        {
            var toleranceOk              = true;
            var listOfComposedPattern    = new List <MyComposedPattern>();
            var listOfComposedPatternTwo = new List <MyComposedPattern>();

            //For each MyGroupingSurfaceForPatterns
            while (listOfGroupingSurfaceForPatterns.Count > 0 && toleranceOk)
            {
                var currentGroupingSurfaceForPatterns = new MyGroupingSurfaceForPatterns(
                    listOfGroupingSurfaceForPatterns[0].groupingSurface,
                    listOfGroupingSurfaceForPatterns[0].listOfPatternsLine,
                    listOfGroupingSurfaceForPatterns[0].listOfPatternsCircum);
                listOfGroupingSurfaceForPatterns.RemoveAt(0);

                fileOutput.AppendLine("");
                fileOutput.AppendLine("NUOVA SURFACE OF TYPE: " + currentGroupingSurfaceForPatterns.groupingSurface.Identity());
                fileOutput.AppendLine("(Al momento sono rimaste ancora " + listOfGroupingSurfaceForPatterns.Count +
                                      " superfici (oltre questa).)");

                // >>>>>>> LINEAR CASE:
                //first I group patterns by same length and same distance:
                var listOfListsOfCoherentPatternsLine = GroupFoundPatternsOfTypeLine(
                    currentGroupingSurfaceForPatterns.listOfPatternsLine, mySwApplication);
                if (listOfListsOfCoherentPatternsLine.Count == 0)
                {
                }

                //Then I group coherent patterns in subgroups of parallel patterns:
                foreach (var list in listOfListsOfCoherentPatternsLine)
                {
                    //Grouping in lists of parallel patterns
                    var listOfListsOfParallelPatterns = GroupPatternsInParallel(list);
                    var numOfListsOfParallelPatterns  = listOfListsOfParallelPatterns.Count;

                    if (list.Count == 2)
                    {
                        //I verify if a composed pattern with these 2 patterns has already been created
                        //in another GS:
                        if (ComposedPatternOfLength2AlreadyExists(listOfComposedPatternTwo, list) == false)
                        {
                            //if a composed pattern does not exist yet AND
                            //the 2 patterns are not parallel, I verify if it is REFLECTION:
                            if (numOfListsOfParallelPatterns == 0)
                            {
                                if (IsReflectionTwoPatterns(list[0], list[1]))
                                {
                                    var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                    BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                     ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                     ref listOfGroupingSurfaceForPatterns, list);
                                }
                            }
                            else
                            //if a composed pattern does not exist yet AND
                            //the 2 patterns are parallel, I verify if it is TRANSLARION:
                            {
                                if (IsTranslationTwoPatterns(list[0], list[1]))
                                {
                                    var typeOfNewComposedPattern = "Composed TRANSLATION of length 2";
                                    BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                     ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                     ref listOfGroupingSurfaceForPatterns, list);
                                }
                                else
                                {
                                    if (IsReflectionTwoPatterns(list[0], list[1]))
                                    {
                                        var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                        BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                         ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                         ref listOfGroupingSurfaceForPatterns, list);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (var listOfParallelPatterns in listOfListsOfParallelPatterns)
                        {
                            if (listOfParallelPatterns.Count == 2)
                            {
                                //I verify if a composed pattern with these 2 patterns has already been created
                                //in another GS:
                                if (ComposedPatternOfLength2AlreadyExists(listOfComposedPatternTwo, list))
                                {
                                }
                                else
                                {
                                    if (IsTranslationTwoPatterns(listOfParallelPatterns[0], listOfParallelPatterns[1]))
                                    {
                                        var typeOfNewComposedPattern = "Composed TRANSLATION of length 2";
                                        BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                         ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                         ref listOfGroupingSurfaceForPatterns, listOfParallelPatterns);
                                    }
                                    else
                                    {
                                        if (IsReflectionTwoPatterns(list[0], list[1]))
                                        {
                                            var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                            BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                             ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                             ref listOfGroupingSurfaceForPatterns, list);
                                        }
                                    }
                                }
                            }
                            else //(listOfParallelPatterns.Count > 2)
                            {
                                var listOfPatternCentroids = listOfParallelPatterns.Select(pattern => pattern.patternCentroid).ToList();
                                fileOutput.AppendLine("");
                                fileOutput.AppendLine("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:");
                                var listOfMyMatrAdj = Functions.CreateMatrAdj(listOfPatternCentroids, ref fileOutput);

                                var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                                while (listOfMyMatrAdj.Count > 0 && maxPath == false && toleranceOk)
                                {
                                    var currentMatrAdj = new MyMatrAdj(listOfMyMatrAdj[0].d, listOfMyMatrAdj[0].matr,
                                                                       listOfMyMatrAdj[0].nOccur);
                                    listOfMyMatrAdj.Remove(listOfMyMatrAdj[0]);
                                    //NOTA: forse la mia MatrAdj non deve essere rimossa ma conservata,
                                    //soprattutto nel caso in cui si presenta onlyShortPath = true
                                    //(non avrebbe senso cancellarla, ma conservarla per la ricerca di path
                                    //di 2 RE).
                                    List <MyPathOfPoints> listOfPathsOfCentroids;
                                    bool onlyShortPaths;
                                    maxPath = PathCreation_Part_ComposedPatterns.Functions.FindPaths_ComposedPatterns(currentMatrAdj,
                                                                                                                      listOfParallelPatterns,
                                                                                                                      ref fileOutput, out listOfPathsOfCentroids, out onlyShortPaths, ref toleranceOk,
                                                                                                                      ref listOfMyMatrAdj,
                                                                                                                      ref listOfGroupingSurfaceForPatterns, ref listOfComposedPattern,
                                                                                                                      ref listOfComposedPatternTwo, mySwApplication);
                                    //fileOutput.AppendLine("listOfPathOfCentroids.Count = " + listOfPathOfCentroids.Count, nameFile);

                                    if (toleranceOk)
                                    {
                                        if (listOfPathsOfCentroids != null)
                                        {
                                            if (maxPath == false)
                                            {
                                                if (onlyShortPaths == false)
                                                {
                                                    GetComposedPatternsFromListOfPathsLine(listOfPathsOfCentroids,
                                                                                           listOfParallelPatterns,
                                                                                           ref listOfMyMatrAdj, ref listOfGroupingSurfaceForPatterns,
                                                                                           ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication, ref fileOutput);
                                                }
                                                else
                                                {
                                                    //non faccio niente e li rimetto in gioco per
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //Now coherent linear patterns that have not been set in a composed pattern yet
                        //are examined to see if they consitute any rotation composed pattern:

                        list.RemoveAll(
                            pattern =>
                            listOfComposedPattern.FindIndex(
                                composedPattern =>
                                composedPattern.listOfMyPattern.FindIndex(
                                    patternInComposedPattern =>
                                    patternInComposedPattern.idMyPattern == pattern.idMyPattern) != -1) != -1);
                        if (list.Count != 0)
                        {
                            if (list.Count == 2)
                            {
                                //  >>> POSSIBLE REFLECTION CAN EXIST

                                //I verify if a composed pattern with these 2 patterns has already been created
                                //in another GS:
                                if (ComposedPatternOfLength2AlreadyExists(listOfComposedPatternTwo, list))
                                {
                                }
                                else
                                {
                                    if (IsReflectionTwoPatterns(list[0], list[1]))
                                    {
                                        var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                        BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                         ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                         ref listOfGroupingSurfaceForPatterns, list);
                                    }
                                }
                            }
                            else
                            {
                                var listOfPatternCentroids1 = list.Select(pattern => pattern.patternCentroid).ToList();
                                fileOutput.AppendLine("");
                                fileOutput.AppendLine("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:");
                                var listOfMyMatrAdj1 = Functions.CreateMatrAdj(listOfPatternCentroids1, ref fileOutput);

                                var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                                while (listOfMyMatrAdj1.Count > 0 && maxPath == false && toleranceOk)
                                {
                                    var currentMatrAdj = new MyMatrAdj(listOfMyMatrAdj1[0].d, listOfMyMatrAdj1[0].matr,
                                                                       listOfMyMatrAdj1[0].nOccur);
                                    listOfMyMatrAdj1.Remove(listOfMyMatrAdj1[0]);
                                    //NOTA: forse la mia MatrAdj non deve essere rimossa ma conservata,
                                    //soprattutto nel caso in cui si presenta onlyShortPath = true
                                    //(non avrebbe senso cancellarla, ma conservarla per la ricerca di path
                                    //di 2 RE).
                                    List <MyPathOfPoints> listOfPathsOfCentroids1;
                                    bool onlyShortPaths1;

                                    var maxPath1 = PathCreation_Part_ComposedPatterns.Functions.FindPaths_ComposedPatterns(currentMatrAdj,
                                                                                                                           list, ref fileOutput, out listOfPathsOfCentroids1, out onlyShortPaths1,
                                                                                                                           ref toleranceOk, ref listOfMyMatrAdj1, ref listOfGroupingSurfaceForPatterns,
                                                                                                                           ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication);

                                    if (toleranceOk)
                                    {
                                        if (listOfPathsOfCentroids1 != null)
                                        {
                                            //I ignore every linear path (I look for composed rotational patterns now):
                                            var listOfCircularPaths =
                                                listOfPathsOfCentroids1.FindAll(
                                                    path =>
                                                    path.pathGeometricObject.GetType() == typeof(MyCircumForPath))
                                                .ToList();

                                            if (maxPath1 == false)
                                            {
                                                if (onlyShortPaths1 == false)
                                                {
                                                    GetComposedPatternsFromListOfPathsLine(listOfCircularPaths,
                                                                                           list, ref listOfMyMatrAdj1, ref listOfGroupingSurfaceForPatterns,
                                                                                           ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication, ref fileOutput);
                                                }
                                                else
                                                {
                                                    //non faccio niente e li rimetto in gioco per
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // >>>>>>> CIRCULAR CASE:
                #region da rivedere
                //first I group patterns by same length and same distance:
                var listOfListsOfCoherentPatternsCircum = GroupFoundPatternsOfTypeCircum(
                    currentGroupingSurfaceForPatterns.listOfPatternsCircum, mySwApplication);

                //Then I group coherent patterns in subgroups of patterns:
                foreach (var list in listOfListsOfCoherentPatternsCircum)
                {
                    var listOfListsOfPatternsWithSameCenterAndPlane = GroupPatternsWithSameCenterPlane(list);
                    var numOfListsOfParallelPatterns = listOfListsOfPatternsWithSameCenterAndPlane.Count;
                    //Grouping in lists of parallel patterns
                    foreach (var listOfPatternsWithSameCenterAndPlane in listOfListsOfPatternsWithSameCenterAndPlane)
                    {
                        if (listOfPatternsWithSameCenterAndPlane.Count == 2)
                        {
                            if (IsTranslationTwoPatterns(listOfPatternsWithSameCenterAndPlane[0], listOfPatternsWithSameCenterAndPlane[1]))
                            {
                                var typeOfNewComposedPattern = "Composed ROTATIONAL (same center) of length 2";
                                BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                 ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                 ref listOfGroupingSurfaceForPatterns, listOfPatternsWithSameCenterAndPlane);
                            }
                        }
                        else //listOfPatternsWithSameCenterAndPlane.Count > 2
                        {
                            //    var listOfPatternCentroids =
                            //        listOfPatternsWithSameCenterAndPlane.Select(pattern => pattern.patternCentroid).ToList();
                            //    KLdebug.Print("", nameFile);
                            //    KLdebug.Print("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:", nameFile);
                            //    var listOfMyMatrAdj = Functions.CreateMatrAdj(listOfPatternCentroids, ref fileOutput);

                            //    var indOfMatr = 0;
                            //    List<MyPathOfPoints> listOfPathsOfCentroids;
                            //    bool onlyShortPaths;


                            //    //////////////
                            //    var maxPath = Functions.FindPaths_ComposedPatterns(listOfMyMatrAdj[indOfMatr], listOfPatternsWithSameCenterAndPlane,
                            //            ref fileOutput, out listOfPathsOfCentroids, out onlyShortPaths, ref toleranceOk, ref listOfMyMatrAdj,
                            //            ref listOfGroupingSurfaceForPatterns, ref listOfComposedPattern, ref listOfComposedPatternTwo);

                            //    if (toleranceOk)
                            //    {
                            //        if (maxPath == false)
                            //        {
                            //            if (onlyShortPaths == false)
                            //            {
                            //                GetComposedPatternsFromListOfPathsLine(listOfPathsOfCentroids,
                            //                    listOfPatternsWithSameCenterAndPlane,
                            //                    ref listOfMyMatrAdj, ref listOfGroupingSurfaceForPatterns,
                            //                    ref listOfComposedPattern, ref listOfComposedPatternTwo);
                            //            }
                            //            else
                            //            {
                            //                //non faccio niente e li rimetto in gioco per
                            //            }
                            //        }
                            //    }
                            //    else
                            //    {
                            //        KLdebug.Print("===>>    TOLLERANZA NON SUFFICIENTEMENTE PICCOLA. TERMINATO.", nameFile);
                            //    }
                        }
                    }
                }
            }
            #endregion
            listOfOutputComposedPattern    = listOfComposedPattern;
            listOfOutputComposedPatternTwo = listOfComposedPatternTwo;
        }
        //This function takes as input a list of patterns with MyPathGeometricObject line,
        //it subdivides the patterns by same number of RE on the pattern, then by constant distance.
        public static List <List <MyPattern> > GroupFoundPatternsOfTypeLine(List <MyPattern> listOfPatternsOfTypeLine, SldWorks mySwApplication)
        {
            var nameFile              = "ComposedPatterns.txt";
            var tolerance             = Math.Pow(10, -4);
            var listOfListsOfPatterns = new List <List <MyPattern> >();

            foreach (var pattern in listOfPatternsOfTypeLine)
            {
                var indexOfFind = listOfListsOfPatterns.FindIndex(list => (list[0].listOfMyREOfMyPattern.Count ==
                                                                           pattern.listOfMyREOfMyPattern.Count && Math.Abs(list[0].constStepOfMyPattern - pattern.constStepOfMyPattern) < tolerance));
                //var indexOfFind1 = listOfListsOfPatterns.FindIndex(list => (list[0].listOfMyREOfMyPattern.Count ==
                //    pattern.listOfMyREOfMyPattern.Count));
                //var indexOfFind2 = listOfListsOfPatterns.FindIndex(list => (Math.Abs(list[0].constStepOfMyPattern - pattern.constStepOfMyPattern) < tolerance));
                //KLdebug.Print("     trova indice lista con num elementi corrispondente: " + indexOfFind1, nameFile);
                //KLdebug.Print("     trova indice lista con num distanza corrispondente: " + indexOfFind2, nameFile);

                if (indexOfFind != -1)
                {
                    //The list referred to patterns with same RE number and same constant step already exists. I add it to the corresponding list:
                    listOfListsOfPatterns[indexOfFind].Add(pattern);
                }
                else
                {
                    //The list referred to patterns with same RE number and same constant step does not exist yet. I create it:
                    List <MyPattern> newListOfPatterns = new List <MyPattern> {
                        pattern
                    };
                    listOfListsOfPatterns.Add(newListOfPatterns);
                }
            }
            listOfListsOfPatterns.RemoveAll(list => list.Count < 2);
            return(listOfListsOfPatterns);
        }
示例#57
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);
            }

            //查询参数
            KVS item = (KVS)objKVSService.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会四舍五入
             */
            //-----------计算中间值,----------
            //新风CJ孔数量和新风CJ孔第一个CJ距离边缘距离
            int     frontCjNo       = (int)((item.Length - 3m - 30m) / 32m) + 1;
            decimal frontCjFirstDis = (item.Length - 3m - (frontCjNo - 1) * 32m) / 2m;
            //铆钉数量
            int     rivetNo  = (int)((item.Length - 200m) / 300m);
            decimal rivetDis = (item.Length - 200m) / rivetNo;
            //为了适应肯德基脖颈缺口
            decimal midRoofSecondHoleDis = 0m;

            if (item.ExNo == 2)
            {
                midRoofSecondHoleDis = (item.Length - 300m - item.ExDis - item.ExLength) / 4m;
            }
            else if (item.ExNo == 1)
            {
                midRoofSecondHoleDis = (item.Length - 300m) / 2m;
            }
            //KSA数量,KSA侧板长度(以全长计算)
            int     ksaNo         = (int)((item.Length - 7m) / 498m);
            decimal ksaSideLength = (item.Length - 8m - ksaNo * 498m) / 2m;


            try
            {
                //----------Top Level----------
                ////判断KSA数量,KSA侧板长度,如果太小,则使用特殊小侧板侧边
                //swFeat = swAssy.FeatureByName("LocalLPattern1");
                //if (ksaNo == 1) swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                //else
                //{
                //    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                //    swModel.Parameter("D1@LocalLPattern1").SystemValue = ksaNo; //D1阵列数量,D3阵列距离
                //}
                ////KSA距离左边缘
                //if (ksaSideLength < 12m / 1000m) swModel.Parameter("D1@Distance15").SystemValue = 0.5m / 1000m;
                //else swModel.Parameter("D1@Distance15").SystemValue = ksaSideLength;

                //排风脖颈数量和距离
                if (item.ExNo == 1)
                {
                    swModel.Parameter("D1@Distance52").SystemValue = (item.Length - item.ExLength) / 2000m;
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                else if (item.ExNo == 2)
                {
                    swModel.Parameter("D1@Distance52").SystemValue = ((item.Length - item.ExDis) / 2m - item.ExLength) / 1000m;
                    swFeat = swAssy.FeatureByName("LocalLPattern1");
                    swFeat.SetSuppression2(1, 2, configNames);                                                 //参数1:1解压,0压缩
                    swModel.Parameter("D1@LocalLPattern1").SystemValue = item.ExNo;                            //D1阵列数量,D3阵列距离
                    swModel.Parameter("D3@LocalLPattern1").SystemValue = (item.ExDis + item.ExLength) / 1000m; //D1阵列数量,D3阵列距离
                }
                //日光灯
                if (item.LightType == "FSSHORT")
                {
                    //SHORT
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-3"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020404-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020406-S-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-3"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-4"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-3"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    //LONG
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-4"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-3"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020405-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020407-S-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-5"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-6"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                }
                else
                {
                    //SHORT
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-3"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020404-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020406-S-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-3"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-4"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-3"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩
                    //LONG
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-4"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-3"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020405-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020407-S-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-5"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-6"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩
                }
                //----------排风腔----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0110-1"));
                swPart = swComp.GetModelDoc2();//打开零件3
                swPart.Parameter("D1@Sketch1").SystemValue  = (item.Length - 7m) / 1000m;
                swPart.Parameter("D5@Sketch62").SystemValue = (item.ExDis + item.ExLength) / 1000m;
                //排风口
                if (item.ExNo == 1)
                {
                    swFeat = swComp.FeatureByName("EXCOONE");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("EXCOTWO");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swPart.Parameter("D1@Sketch115").SystemValue = item.ExLength / 1000m;
                    swPart.Parameter("D2@Sketch115").SystemValue = item.ExWidth / 1000m;
                    swPart.Parameter("D5@Sketch62").SystemValue  = midRoofSecondHoleDis / 1000m;
                }
                else
                {
                    swFeat = swComp.FeatureByName("EXCOONE");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("EXCOTWO");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swPart.Parameter("D4@Sketch114").SystemValue = item.ExDis / 1000m;
                    swPart.Parameter("D2@Sketch114").SystemValue = item.ExLength / 1000m;
                    swPart.Parameter("D1@Sketch114").SystemValue = item.ExWidth / 1000m;
                    swPart.Parameter("D5@Sketch62").SystemValue  = (item.ExDis + item.ExLength) / 1000m;
                    if (midRoofSecondHoleDis > 300m)
                    {
                        swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D3@Sketch116").SystemValue = midRoofSecondHoleDis / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                }
                //----------其他零件----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0111-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 6m) / 1000m;

                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0112-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch3").SystemValue = ksaSideLength / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0113-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch3").SystemValue = ksaSideLength / 1000m;

                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0114-2"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength + 50m) / 1000m;
                swPart.Parameter("D2@Sketch1").SystemValue = (item.ExHeight + 54.8m) / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0115-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength + 50m) / 1000m;
                swPart.Parameter("D2@Sketch1").SystemValue = (item.ExHeight + 54.8m) / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0117-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D1@Sketch1").SystemValue = item.ExLength / 2000m;
                swPart.Parameter("D2@Sketch1").SystemValue = (item.ExWidth + 20m) / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0118-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = (item.ExLength * 2m) / 1000m;

                //----------MiddleRoof灯板----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0023-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 3m) / 1000m;
                swPart.Parameter("D1@Sketch1").SystemValue = (item.Deepth - 788.5m) / 1000m;
                if (item.ExNo == 1)
                {
                    swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swPart.Parameter("D2@Sketch20").SystemValue = midRoofSecondHoleDis / 1000m;
                }
                else
                {
                    swPart.Parameter("D2@Sketch20").SystemValue = (item.ExDis + item.ExLength) / 1000m;
                    if (midRoofSecondHoleDis > 300m)
                    {
                        swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D1@Sketch26").SystemValue = midRoofSecondHoleDis / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                }
                //灯具
                if (item.LightType == "FSSHORT")
                {
                    swFeat = swComp.FeatureByName("FSLONG");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("FSSHORT");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                }
                else
                {
                    swFeat = swComp.FeatureByName("FSLONG");
                    swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                    swFeat = swComp.FeatureByName("FSSHORT");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                }
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020401-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Deepth - 793m) / 1000m;
                //----------大侧板----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0036-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0037-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0038-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0039-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m;

                //------------新风腔----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0052-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 7m) / 1000m;
                if (item.ExNo == 1)
                {
                    swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                    swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    swPart.Parameter("D3@Sketch50").SystemValue = midRoofSecondHoleDis / 1000m;
                }
                else
                {
                    swPart.Parameter("D3@Sketch50").SystemValue = (item.ExDis + item.ExLength) / 1000m;
                    if (midRoofSecondHoleDis > 300m)
                    {
                        swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                        swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩
                        swPart.Parameter("D3@Sketch127").SystemValue = midRoofSecondHoleDis / 1000m;
                    }
                    else
                    {
                        swFeat = swComp.FeatureByName("MIDROOFINSDIS2");
                        swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩
                    }
                }
                swPart.Parameter("D1@LPattern2").SystemValue = rivetNo + 1;
                swPart.Parameter("D3@LPattern2").SystemValue = rivetDis / 1000m;

                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0053-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 103m) / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0054-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 3m) / 1000m;
                swPart.Parameter("D1@LPattern1").SystemValue    = frontCjNo;
                swPart.Parameter("D10@Sketch8").SystemValue     = frontCjFirstDis / 1000m;
                swPart.Parameter("D1@LPattern2").SystemValue    = rivetNo + 1;
                swPart.Parameter("D3@LPattern2").SystemValue    = rivetDis / 1000m;
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0055-1"));
                swPart = swComp.GetModelDoc2();
                swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 7m) / 1000m;

                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
示例#58
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);
            }

            //查询参数
            BCJ300 item = (BCJ300)objBCJ300Service.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     cjNo       = (int)((item.Length - 40m) / 30m);//天花烟罩马蹄形CJ孔阵列距离为30
            decimal firstCjDis = (item.Length - 30m * cjNo) / 2;

            if (firstCjDis < 15m)
            {
                cjNo--;
                firstCjDis = firstCjDis + 15m;
            }


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

                //----------脖颈----------
                if (item.SuType == "UP")
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0010-2"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201990413-1"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                }
                else
                {
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0010-2"));
                    swComp.SetSuppression2(0); //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201990413-1"));
                    swComp.SetSuppression2(2); //2解压缩,0压缩.
                }

                //----------侧板----------
                switch (item.SidePanel)
                {
                case "LEFT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;

                case "RIGHT":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

                case "MIDDLE":
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    break;

                default:
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2"));
                    swComp.SetSuppression2(2);     //2解压缩,0压缩.
                    swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1"));
                    swComp.SetSuppression2(0);     //2解压缩,0压缩.
                    break;
                }

                //----------CJ腔主体----------
                //重命名装配体内部
                compReName = "FNCJ0015[BCJ300-" + tree.Module + "]{" + (int)item.Length + "}";
                status     = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCJ0015-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;
                    swPart.Parameter("D1@LPattern1").SystemValue = cjNo + 1;
                    swPart.Parameter("D3@Skizze17").SystemValue  = firstCjDis / 1000m;
                    swPart.Parameter("D4@Skizze16").SystemValue  = item.SuDis / 1000m;
                }
                //----------其他零件----------
                swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0016-1"));
                swPart = swComp.GetModelDoc2();//打开零件
                swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 10m) / 1000m;


                swModel.ForceRebuild3(true);    //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢
                swModel.Save();                 //保存,很耗时间
                swApp.CloseDoc(packedAssyPath); //关闭,很快
            }
            catch (Exception ex)
            {
                throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message);
            }
            finally
            {
                swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用
            }
        }
 public CommandManager(SldWorks iSwApp)
 {
     this.iSwApp = iSwApp;
     this.iCmdMgr = iSwApp.GetCommandManager(SwAddin.addinID);
     SetupCommands();
 }
示例#60
0
 public DrawingProperties(SldWorks sw)
 {
     this._swApp      = sw;
     CutlistData      = new CutlistData();
     this._innerArray = new ArrayList();
 }