简体   繁体   English

从solidworks获取自定义材料

[英]Getting custom materials from solidworks

First note I don't have solidworks installed on my computer, but use the files for a project. 首先注意我的计算机上没有安装solidworks,但是将这些文件用于项目。

Solidworks has the ability to make a custom tab to the file properties. Solidworks能够为文件属性创建自定义选项卡。 In this tab you can find all kind of information about a model(part) that is made in solidworks. 在此选项卡中,您可以找到有关在solidworks中制作的模型(零件)的所有类型的信息。

I read out all these information and store it in a .txt file see image. 我读出所有这些信息并将其存储在.txt文件中,见图像。 Within this information you can find the material type of the part, where my question comes in. 在此信息中,您可以找到我的问题所在的零件的材料类型。 在此输入图像描述

I know the material type, however in solidworks the user can also assign custom materials to the material that is defined in the custom properties. 我知道材质类型,但在solidworks中,用户还可以将custom materials指定给custom materials定义属性中定义的材质。 For example the material is just regular wood, but the user want this wood to be pink. 例如,材料只是普通木材,但用户希望这种木材是粉红色的。

Is it possible to read out the custom materials that are attached to the material in custom properties? 是否可以读出custom materials附加到材料中的自定义属性?

If you don't have SOLIDWORKS installed, you can use the document manager (requires active SOLIDWORKS subscription to get key) to access custom properties: 如果您没有安装SOLIDWORKS,则可以使用文档管理器 (需要有效的SOLIDWORKS订阅来获取密钥)来访问自定义属性:

String sLicenseKey = "Your key from SOLIDWORKS";
SwDmDocumentOpenError nRetVal = 0;
SwDmCustomInfoType customInfoType;
SwDMClassFactory swClassFact = new SwDMClassFactory();
SwDMApplication swDocMgr = (SwDMApplication)swClassFact.GetApplication(sLicenseKey);
SwDMDocument17 swDoc = (SwDMDocument17)swDocMgr.GetDocument("C:\Filepath", SwDmDocumentType.swDmDocumentPart, false, out nRetVal);
SwDMConfigurationMgr swCfgMgr = swDoc.ConfigurationManager;
SwDMConfiguration14 swCfg = (SwDMConfiguration14)swCfgMgr.GetConfigurationByName("Config Name");
String materialProperty = swCfg.GetCustomProperty2("Property Name", out customInfoType);

To read material properties try: 要阅读材料属性,请尝试:

ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;
PartDoc swPart = (PartDoc)swModel;
double[] propertyValues = swPart.MaterialPropertyValues;

According to SOLIDWORKS documentation : 根据SOLIDWORKS文档

The material values include the color (R,G,B values), reflectivity (ambient, diffuse, specular, shininess), transparency and emission. 材料值包括颜色(R,G,B值),反射率(环境,漫反射,镜面反射,光泽度),透明度和发射。

The format of the parameters or return values is an array of doubles as follows: [ R, G, B, Ambient, Diffuse, Specular, Shininess, Transparency, Emission ] 参数或返回值的格式是双精度数组,如下所示:[R,G,B,Ambient,Diffuse,Specular,Shininess,Transparency,Emission]

All elements must be in the range 0 to 1. 所有元素必须在0到1的范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM