2 Replies Latest reply on Jan 11, 2019 9:42 AM by Aaron Heathcote

    Remove all Custom Properties from SLDDRW without Document Manager C#

    Aaron Heathcote

      Does anyone have a solution to open up an SLDDRW and remove all custom properties without the Document Manager?

      I have requested a key a couple of times but they haven't come through yet.

       

      My current code which needs DocumentManager:

                               const string sLicenseKey = "<your_license_code>";

                              SwDocumentMgr.SwDMDocument15 swDoc = default(SwDocumentMgr.SwDMDocument15);

                              SwDocumentMgr.SwDmDocumentOpenError nRetVal = 0;

                              SwDocumentMgr.SwDMClassFactory swClassFact = default(SwDocumentMgr.SwDMClassFactory);

                              SwDocumentMgr.SwDMApplication3 swDocMgr = default(SwDocumentMgr.SwDMApplication3);

                              swClassFact = new SwDocumentMgr.SwDMClassFactory();

                              swDocMgr = (SwDocumentMgr.SwDMApplication3)swClassFact.GetApplication(sLicenseKey);

                              swDoc = (SwDocumentMgr.SwDMDocument15)swDocMgr.GetDocument(NewFiles + row[2] + ".SLDDRW",                                                  SwDocumentMgr.SwDmDocumentType.swDmDocumentDrawing, false, out nRetVal);

                              string[] vCustPropNameArr = null;

                              string sCustPropStr = null;

                              SwDocumentMgr.SwDmCustomInfoType nPropType = 0;

                             

                              vCustPropNameArr = (string[])swDoc.GetCustomPropertyNames();

                              if ((vCustPropNameArr == null)) return;

       

       

                              Debug.Print(" Custom Properties:");

       

       

                              foreach (string vCustPropName in vCustPropNameArr)

                              {

                                  sCustPropStr = swDoc.GetCustomProperty(vCustPropName, out nPropType);

                                  Debug.Print(" " + vCustPropName + " <" + nPropType + "> = " + sCustPropStr);

                              }

       

      Is there a better way which my program can open up the SLDDRW and run a loop for each custom property and deleting them?

        • Re: Remove all Custom Properties from SLDDRW without Document Manager C#
          Deepak Gupta

          Aaron Heathcote wrote:

           

          Does anyone have a solution to open up an SLDDRW and remove all custom properties without the Document Manager?

          I have requested a key a couple of times but they haven't come through yet

          You need to be on subscription to get the key. So have you checked the spam/junk emails as sometimes the email may get to these zones? Have you asked your VAR to follow up or find why key was not given?

           

          Alternatively you can use Task Scheduler or this tool #TASK to remove the properties.

            • Re: Remove all Custom Properties from SLDDRW without Document Manager C#
              Aaron Heathcote

              Hi Deepak, yes we are on subscription and I have contacted them also....

               

              for now, I have worked it out from another couple of threads. For anyone else that comes across this problem here is my code:

               

                                      SldWorks.ModelDoc2 swModelComp;

                                      SldWorks.ModelDocExtension swModelDocExtComp;

                                      SldWorks.CustomPropertyManager swCustPropMgrComp;

                                      swModelComp = (SldWorks.ModelDoc2)swApp.ActiveDoc;

                                      swModelDocExtComp = swModelComp.Extension;

               

               

                                      object PropNames = default(object);

                                      object PropTypes = default(object);

                                      object PropValues = default(object);

                                      swCustPropMgrComp = swModelDocExtComp.get_CustomPropertyManager(String.Empty);

                                      swCustPropMgrComp.GetAll(ref PropNames, ref PropTypes, ref PropValues);

                                      string[] asCustPropName = (string[])PropNames;

                                      string[] asCustPropValues = (string[])PropValues;

               

               

               

               

                                      for (int t = 0; t < asCustPropName.GetUpperBound(0) - 1; t++)

                                      {

                                          swCustPropMgrComp.Delete(asCustPropName[t]);

                                      }