這兩天比較忙,在整理一份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} ");
}
效果如下: