コード例 #1
0
        public static string SetAttValueByName(string AtrName, ModelDoc2 swModel, string Value)
        {
            string cfgname2 = swModel.ConfigurationManager.ActiveConfiguration.Name;

            CustomPropertyManager cpmMdl = swModel.Extension.get_CustomPropertyManager(cfgname2);
            //string outval = "";
            string sovVal = "";

            cpmMdl.Set(AtrName, Value);

            return(sovVal);
        }
コード例 #2
0
        protected int _save()
        {
            ModelDoc2 swDoc;
            int       errors   = 0;
            int       warnings = 0;

            swDoc = ((ModelDoc2)(swApp.NewDocument(template, 0, 0, 0)));
            CustomPropertyManager swCustProp = swDoc.Extension.get_CustomPropertyManager("");

            swCustProp.Set(Settings.Default.propertyName, name);
            swDoc.Extension.SaveAs(Path.Combine(project.workDir, file), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            swApp.OnIdleNotify -= new DSldWorksEvents_OnIdleNotifyEventHandler(_save);
            updateDBForm();
            return(0);
        }
コード例 #3
0
        protected int _setName()
        {
            ModelDoc2 swDoc;
            int       errors   = 0;
            int       warnings = 0;

            swDoc = (ModelDoc2)swApp.OpenDocSilent(Path.Combine(project.workDir, file), (int)docType, ref errors);
            CustomPropertyManager swCustProp = swDoc.Extension.get_CustomPropertyManager("");

            swCustProp.Set(Settings.Default.propertyName, this.name);
            updatePending = false;
            swDoc.Extension.SaveAs(Path.Combine(project.workDir, file), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            swApp.OnIdleNotify -= new DSldWorksEvents_OnIdleNotifyEventHandler(_setName);
            this.updateDBForm();
            return(0);
        }
コード例 #4
0
        protected int _save_Uprofile()
        {
            ModelDoc2 swDoc;
            int       errors   = 0;
            int       warnings = 0;

            swDoc = ((ModelDoc2)(swApp.NewDocument(template, 0, 0, 0)));
            CustomPropertyManager swCustProp = swDoc.Extension.get_CustomPropertyManager("");

            swCustProp.Set(Settings.Default.propertyName, name);

            // Create sketch
            swDoc.SketchManager.InsertSketch(true);
            // Draw the lines
            SketchSegment line1, line2, line3;

            line1 = (SketchSegment)(swDoc.SketchManager.CreateLine(-0.05, 0.0, 0.0, 0.05, 0.0, 0.0));   // horizontal
            line2 = (SketchSegment)(swDoc.SketchManager.CreateLine(-0.05, 0.0, 0.0, -0.05, 0.05, 0.0)); // left
            line3 = (SketchSegment)(swDoc.SketchManager.CreateLine(0.05, 0.0, 0.0, 0.05, 0.05, 0.0));   // right
            // left and right line same length
            line2.Select4(false, null);
            line3.Select4(true, null);
            swDoc.SketchAddConstraints("sgSAMELENGTH");
            // line 1 center on datum origin
            swDoc.Extension.SelectByID2("", swSelectType_e.swSelDATUMPOINTS.ToString(), 0.0, 0.0, 0.0, false, 0, null, 0);
            line1.Select4(true, null);
            swDoc.SketchAddConstraints("sgATMIDDLE");
            // Add dimensions
            line1.Select4(false, null);
            swDoc.AddDimension2(0.0, -0.05, 0.0);
            line2.Select4(false, null);
            swDoc.AddDimension2(-0.06, 0.025, 0.0);
            // Exit sketch
            swDoc.ClearSelection2(true);
            swDoc.SketchManager.InsertSketch(true);

            swDoc.Extension.SaveAs(Path.Combine(project.workDir, file), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            swApp.OnIdleNotify -= new DSldWorksEvents_OnIdleNotifyEventHandler(_save_Uprofile);
            updateDBForm();
            return(0);
        }
コード例 #5
0
ファイル: Helper.cs プロジェクト: TarenLewis/solidworkscsharp
        internal static bool ReplaceCustomPropertyValue(CustomPropertyManager customPropertyManager, string CustomProperty, string Replaceable, string Replacing)
        {
            string val = customPropertyManager.Get(CustomProperty);

            if (val == null)
            {
                if (val.ToLower().Contains(Replaceable.ToLower()))
                {
                    string NewVal = val.Replace(Replaceable, Replacing);
                    int    ret    = customPropertyManager.Set(CustomProperty, NewVal);

                    if (ret == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
コード例 #6
0
ファイル: Helper.cs プロジェクト: ahmsville/SWXSTANDALONE
        internal static bool replaceCustomPropertyValue(CustomPropertyManager customPropertyManager, string CustomProperty, string Repleacable, string Replacing)
        {
            string val = customPropertyManager.Get(CustomProperty);

            // check if the custom property exists
            if (!string.IsNullOrEmpty(val))
            {
                // check if the replecable string exists in the custom property value
                if (val.ToLower().Contains(Repleacable.ToLower()))
                {
                    string NewVal = val.Replace(Repleacable, Replacing);
                    int    ret    = customPropertyManager.Set(CustomProperty, NewVal);
                    if (ret == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
コード例 #7
0
 public void Commit()
 {
     #region 00. 提交尺寸
     EquationMgr emgr = (EquationMgr)swDoc.GetEquationMgr();
     int         ic   = emgr.GetCount();
     for (int i = 0; i < ic; i++)
     {
         //在这里想办法只获取全局变量
         string s = emgr.get_Equation(i);
         if (s.Contains("@"))
         {
             continue;
         }
         s = s.Replace("\"", "");
         s = s.Remove(s.IndexOf('='));
         s = s.Trim();
         s = s.ToUpper();
         if (Sizes.ContainsKey(s))
         {
             if (Sizes[s] != _Sizes[s])
             {
                 string Equation = JswFunc.FormatEquation(s, Sizes[s].ToString());
                 emgr.set_Equation(i, Equation);
             }
         }
         else
         {
             if (_Sizes.ContainsKey(s))
             {
                 emgr.Delete(i);
                 i--;
                 ic--;
             }
         }
     }
     //foreach (string key in Sizes.Keys)
     //{
     //    if (Sizes[key] != _Sizes[key])
     //    {
     //        JswFunc.SetEquationValueByName(swDoc, key, Sizes[key]);
     //    }
     //}
     _Sizes = new Dictionary <string, object>(Sizes);
     #endregion
     #region 10. 提交属性
     string cfgname2 = swDoc.ConfigurationManager.ActiveConfiguration.Name;
     CustomPropertyManager cpmMdl = swDoc.Extension.get_CustomPropertyManager(cfgname2);
     //修改属性
     foreach (string key in Attrs.Keys)
     {
         if (_Attrs.ContainsKey(key))
         {
             if (Attrs[key] != _Attrs[key])
             {
                 cpmMdl.Set(key, Attrs[key]);
             }
         }
         else
         {
             //如果该Key在_Attrs中找不到,表示为新增的属性
             int    outval = 30;
             string sovVal = "";
             // cpmMdl.Set(AtrName, Value);
             cpmMdl.Add2(key, outval, Attrs[key]);
         }
     }
     //清理已经删除的属性
     foreach (string key in _Attrs.Keys)
     {
         if (!Attrs.ContainsKey(key))
         {
             //旧属性不在新列表中,表示该属性已被删除。
             cpmMdl.Delete(key);
         }
     }
     _Attrs = new Dictionary <string, string>(Attrs);
     #endregion
 }
コード例 #8
0
        private void SaveAll()
        {
            try
            {
                int intVal;
                SwConfig = (Configuration)SwModel.GetConfigurationByName((string)CboxConfigName.SelectedValue);
                CustomPropertyManager swConfigCustMgr = SwConfig.CustomPropertyManager;

                intVal = swConfigCustMgr.Add2(TextBox1.Text, (int)swCustomInfoType_e.swCustomInfoText, TextBoxDeaNo.Text);
                if (intVal == -1)
                {
                    intVal = swConfigCustMgr.Set(TextBox1.Text, TextBoxDeaNo.Text.Trim());
                }

                intVal = swConfigCustMgr.Add2(TextBox2.Text, (int)swCustomInfoType_e.swCustomInfoText, TextBoxName.Text);
                if (intVal == -1)
                {
                    intVal = swConfigCustMgr.Set(TextBox2.Text, TextBoxName.Text.Trim());
                }

                intVal = swConfigCustMgr.Add2(TextBox3.Text, (int)swCustomInfoType_e.swCustomInfoText, TextBoxDesigner.Text);
                if (intVal == -1)
                {
                    intVal = swConfigCustMgr.Set(TextBox3.Text, TextBoxDesigner.Text.Trim());
                }

                intVal = swConfigCustMgr.Add2(TextBox4.Text, (int)swCustomInfoType_e.swCustomInfoDate, DatePickerDesignDate.SelectedDate.ToString());
                if (intVal == -1)
                {
                    intVal = swConfigCustMgr.Set(TextBox4.Text, DatePickerDesignDate.SelectedDate.ToString().Trim());
                }



                intVal = SwCustPropMgr.Add2(TextBox5.Text, (int)swCustomInfoType_e.swCustomInfoText, TextBoxDwgNo.Text);
                if (intVal == 0)
                {
                    intVal = SwCustPropMgr.Set(TextBox5.Text, TextBoxDwgNo.Text.Trim());
                }

                intVal = SwCustPropMgr.Add2(TextBox6.Text, (int)swCustomInfoType_e.swCustomInfoText, TextBoxDwgName.Text);
                if (intVal == 0)
                {
                    intVal = SwCustPropMgr.Set(TextBox6.Text, TextBoxDwgName.Text.Trim());
                }

                intVal = SwCustPropMgr.Add2(TextBox7.Text, (int)swCustomInfoType_e.swCustomInfoText, TextBoxNote.Text);
                if (intVal == 0)
                {
                    intVal = SwCustPropMgr.Set(TextBox7.Text, TextBoxNote.Text.Trim());
                }

                //intVal = swCustPropMgr.Set(textBox5.Text, textBoxDwgNo.Text);
                //intVal = swCustPropMgr.Set(textBox6.Text, textBoxDwgName.Text);
                //intVal = swCustPropMgr.Set(textBox7.Text, textBoxNote.Text);

                SwModel.ForceRebuild3(true);

                TextColorReset();

                TextBlock.Text = "写入完成。";
            }
            catch (Exception ex)
            {
                throw ex;
            }


            //this.Hide();
            //System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(msg));
            //th.Start();
            //System.Threading.Thread.Sleep(1000);
            //System.Environment.Exit(0);
            this.Close();
        }