How to get the assigned material name from a part document using Soldiworks document manager api ?
#solidworksapi #Solidworkdocumentmanagerapi #material
How to get the assigned material name from a part document using Soldiworks document manager api ?
#solidworksapi #Solidworkdocumentmanagerapi #material
The only way that I can find to do this is if the material is already a custom property in the file. If you want file specific data, you’ll have to use the Solidworks API instead.
Here’s the code snippet that gets the evaluated/resolved values for general custom properties with Document Manager.
dmDoc.GetAllCustomPropertyNamesAndValues(out var vNames, out var vTypes, out var vLinkedTo, out var vValues);
string[] sNames = (string[])vNames;
int[] sTypes = (int[])vTypes;
string[] sLinkedTo = (string[])vLinkedTo;
string[] sValues = (string[])vValues;
for(int i=0; i < sNames.Length; i++)
{
Console.WriteLine($"{sNames[i]}: {sValues[i]} [{sTypes[i]}]");
}
thanks @BigCrazyAl
I already aware of this way. If the material is part of custom property we cand do that. But in my case material is not part of custom property but I need just name of the material using Solidworks document manager api only. I knew , how to get it via native Solidworks api.
I need to know via document manager api and material not part of custom property
I think that’s a limitation of the document manager api. It cannot access feature tree or model information to my knowledge.
Hey, so if you use the SwDMDocument29::GetKeyWordStream(string pathToSaveXml), it will create a xml file with some info in it including the material name and other feature data
Hope this helped.
Thanks for posting.
For some reason, I cannot find GetKeyWordStream in swDMDocument29 nor can I find in the entire API docs. Can you paste the link please?
Just adding that you need to check the box for XML streams when you request a new doc man key.
Yeah, I could not find any docs on GetKeyWordStream either, I found it by accident when looking through all the methods with the help of VS IntelliSense, heres a simple example of what worked for me.
using SwDocumentMgr;
string LicKey = "SomeKeyHere";
string filePath = "PathToYourSwDocument";
string xmlSavepath = "PathToSaveXml";
SwDMApplication swDmApp = (SwDMApplication) new SwDMClassFactory().GetApplication(LicKey);
var swDoc = (SwDMDocument29)swDmApp.GetDocument(filePath, SwDmDocumentType.swDmDocumentUnknown, true, out var err);
swDoc?.GetKeyWordStream(xmlSavepath);