1 Reply Latest reply on Feb 7, 2017 9:17 PM by Keith Rice

    CutList feature CustomPropertyManager has no properties

    Alexander Zeitler

      I'm trying to access the custom properties of a sheetmetal cutlist feature like this:

       

      "Zuschnittslistenelement1" is the german name for "Cut-List-Item1"

       

      IModelDoc2 partModel = _solidWorks.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART,

        (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel,

        string.Empty, ref loadError, ref loadWarnings);

      _solidWorks.ActivateDoc2(fileName, false, loadError);

       

      object featuresObject = partModel.FeatureManager.GetFeatures(true);

      object[] features = featuresObject as object[];

       

      Feature cutList = null;

      foreach (object featureObject in features)

      {

        Feature feature1 = featureObject as Feature;

        if (feature1.Name == "Zuschnittslistenelement1")

        {

        cutList = feature1;

        }

      }

       

      if (cutList != null)

      {

        CustomPropertyManager propertyManager = cutList.CustomPropertyManager;

        string resolvedRahmenLaenge;

        string rahmenLaenge;

        propertyManager.Get4("Rahmenlänge", false, out rahmenLaenge, out resolvedRahmenLaenge);

       

        string resolvedRahmenBreite;

        string rahmenBreite;

        propertyManager.Get4("Rahmenbreite", false, out rahmenBreite, out resolvedRahmenBreite);

      }

       

      propertyManager.Count is 0.

        • Re: CutList feature CustomPropertyManager has no properties
          Keith Rice

          It would be helpful if you posted the model you are testing this on. Anyway, the code below worked fine for me and you can test it out by pasting it into a VSTA C# macro called "Macro1". I would recommend you look for the cut list folder using IFeature.GetTypeName so that you're not relying on a string value that could possibly change.

           

          using SolidWorks.Interop.sldworks;
          using SolidWorks.Interop.swconst;
          using System.Runtime.InteropServices;
          using System;
          
          namespace Macro1.csproj
          {
              public partial class SolidWorksMacro
              {
          
                  public SldWorks app;
          
                  public void Main()
                  {
                      ModelDoc2 model = (ModelDoc2)app.ActiveDoc;
                      Feature feat = (Feature)model.FirstFeature();
                      while (feat != null)
                      {
                          if (feat.GetTypeName() == "CutListFolder")
                          {
                              CustomPropertyManager custPropMgr = feat.CustomPropertyManager;
                              app.SendMsgToUser(custPropMgr.Count.ToString());
                          }
          
                          feat = (Feature)feat.GetNextFeature();
                      }
                  }
              }
          }
          

           

          Keith

          SolidWorks API Training and Services