iProperties, add a custom value programatically |
Top Previous Next |
If you want to add an iProperty into the visible custom properties...
...use this function:
void AddCustomProperty(CComPtr<Document>& pInventorDoc, const CString& kcsPropName, const CString& kcsPropValue) { CComPtr <PropertySets> pPropSets; pInventorDoc->get_PropertySets(&pPropSets);
CComVariant varPropSetName(L"Inventor User Defined Properties"); CComPtr<PropertySet> pPropSet; HRESULT hRes = pPropSets->get_Item(varPropSetName,&pPropSet); if (FAILED(hRes) || (pPropSet == nullptr)) { ShowCOMError(hRes, L"Could not find custom property set"); return; }
CComPtr<Property> pProperty; CComVariant varPropName(kcsPropName) ; CComVariant varPropVal(kcsPropValue); CComVariant varPropId; pPropSet->Add(varPropVal, varPropName, varPropId, &pProperty); }
Here is an example of use:
CComQIPtr<Document> pDoc = pAssemblyDoc ; // upcast to Document AddCustomProperty(pDoc,gkcsInOutPropName,csInOut);
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)