12

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.enter image description here

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?

Desutoroiya
  • 534
  • 1
  • 6
  • 15

2 Answers2

3

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);
AndrewK
  • 1,153
  • 2
  • 15
  • 24
2

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.

AndrewK
  • 1,153
  • 2
  • 15
  • 24
  • Does this DLL work without solidworks installed on the computer? – Desutoroiya Mar 29 '16 at 06:05
  • It requires SOLIDWORKS to run. Unless you store your custom material information in a custom property (which could be accessed by the document manager api), you will not be able to access that info without SOLIDWORKS installed. – AndrewK Mar 29 '16 at 15:44
  • Then, this does not work for me. Like I said I don't have Solidworks installed on my system, and already readed out like in my question the custom properties – Desutoroiya Mar 30 '16 at 10:21