C# SolidWorks 二次开发 API---给零件加材质

这两天比较忙,在整理一份api帮助的功能翻译清单.

今天看一下如何获取零件的材质 以及修改材质.

我们先打开一个零件,如下图:

 

        private void btn_SetMaterial_Click(object sender, EventArgs e)
        {
            ISldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = swApp.ActiveDoc;
            ModelDocExtension swModelDocExt = (ModelDocExtension)swModel.Extension;
            string swMateDB = "";
            string tempMaterial = "";
            //获取现有材质
            tempMaterial = ((PartDoc)swModel).GetMaterialPropertyName2("", out swMateDB);

            MessageBox.Show($"当前零件材质为 {swMateDB} 中的 {tempMaterial} ");

            string configName = null;
            string databaseName = null;
            string newPropName = null;
            configName = "默认";
            databaseName = "SOLIDWORKS Materials";
            newPropName = "Beech";
            ((PartDoc)swModel).SetMaterialPropertyName2(configName, databaseName, newPropName);

            tempMaterial = ((PartDoc)swModel).GetMaterialPropertyName2("", out swMateDB);

            MessageBox.Show($"修改之后  当前零件材质为 {swMateDB} 中的 {tempMaterial} ");
        }

 

效果如下:

发布了51 篇原创文章 · 获赞 17 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/zengqh0314/article/details/102789680