Reputation: 544
First note I don't have solidworks installed on my computer, but use the files for a project.
Solidworks has the ability to make a custom tab to the file properties. In this tab you can find all kind of information about a model(part) that is made in solidworks.
I read out all these information and store it in a .txt
file see image. 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. 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?
Upvotes: 11
Views: 1793
Reputation: 1303
If you don't have SOLIDWORKS installed, you can use the document manager (requires active SOLIDWORKS subscription to get key) to access custom properties:
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);
Upvotes: 3
Reputation: 1303
To read material properties try:
ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;
PartDoc swPart = (PartDoc)swModel;
double[] propertyValues = swPart.MaterialPropertyValues;
According to SOLIDWORKS documentation:
The material values include the color (R,G,B values), reflectivity (ambient, diffuse, specular, shininess), transparency and emission.
The format of the parameters or return values is an array of doubles as follows: [ R, G, B, Ambient, Diffuse, Specular, Shininess, Transparency, Emission ]
All elements must be in the range 0 to 1.
Upvotes: 2