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;



   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");




   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




Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)