2 Replies Latest reply on Jan 20, 2015 5:40 PM by Adam Hoffman

    How do I keep from creating new display states each time I add a new configuration?

    Adam Hoffman

      I'm am using a macro to add a new configuration and when I do it keeps creating new display states each time I add a new configuration. I have the model set to not link configurations to display states, but it keeps adding new ones each time I create a new configuration with my vb.net add in. Does anyone know of a work around to this? Here is what I have so far:

       

      Dim bAlreadyExists As Boolean = SeeIfConfigExists(swModel, sNewPartNo)

       

      If bAlreadyExists = True Then
           MessageBox.Show("There Is Already A Configuration Named: " + sNewPartNo, "Part Number Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
           Exit Sub
      End If

       

      Dim swConfigMgr As SolidWorks.Interop.sldworks.ConfigurationManager = Nothing

      swConfigMgr = swModel.ConfigurationManager

       

      If Not swConfigMgr Is Nothing Then

           swConfigMgr.LinkDisplayStatesToConfigurations = False

      End If

       

      Dim swConfig As SolidWorks.Interop.sldworks.Configuration = swModel.GetActiveConfiguration

       

      If UCase(swConfig.Name) = "DEFAULT" Then
          Try
              swConfig.Name = sNewPartNo
           Catch ConfigPropSetError As Exception
                Debug.WriteLine(ConfigPropSetError)
            End Try

      Else
            swModel.AddConfiguration3(sNewPartNo, "", "", swConfigurationOptions2_e.swConfigOption_HideByDefault)

            swModel.ShowConfiguration2(sNewPartNo)

            swConfig = swModel.GetActiveConfiguration

      End If

        • Re: How do I keep from creating new display states each time I add a new configuration?
          Keith Rice

          Adam,

           

          When I run IModelDoc2::AddConfiguration3 on a brand new part, no display state is added. What I would recommend is that you upload the simplest piece of code you can create that still reproduces the problem and then let us look at it. It should be a piece of code we can easily paste into a VB.NET macro. Also, please test that code on a brand new part, not just your current model. The problem may be model specific. If it is model specific, upload that model.

           

          Also, at the top of your VB.NET classes / modules you should add this:

           

          Imports SolidWorks.Interop.sldworks
          

           

          This will remove the need for you to write out the entire namespace every time you declare a variable.

           

          Keith

          SolidWorks API Training

            • Re: How do I keep from creating new display states each time I add a new configuration?
              Adam Hoffman

              I tested on new part documents and the problem persists whether it is a new doc or an older one that has a hundred configurations. I ended up doing a work around to where before I add the configuration, I get a list of all the display state names. Then I add the new configuration without activating it, then get another list of display state names. I loop through the new list comparing them to the original list and if I find a new one, I delete it. It's not a pretty way to go about it, but when dealing with part documents that can have around 300 to 400 configurations in them, I don't need the extra hassle with hundreds of different display states. Thanks for your time.