Esempio n. 1
0
        public static void UpdateProperty(MaterialModel objMaterial)
        {
            //1.打开指定的SW文件
            ModelDoc2 swDoc = swAppHelper.ActiveDoc(Globals.FileName);
            //2.获取当前激活配置名
            string configName = swDoc.ConfigurationManager.ActiveConfiguration.Name;

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

            #region 重建模型
            swDoc.ClearSelection();    //清除选择
            swDoc.ForceRebuild3(true); //重建模型Ctrl+Q
            //swDoc.ShowNamedView2("*等轴测", 7);//等轴测显示
            //swDoc.ViewZoomtofit2();//全屏显示
            //swDoc.Save();
            //swAppHelper.CloseDoc(objDoc.OriginalFileName);
            #endregion
        }