7 Replies Latest reply on Sep 15, 2017 1:36 PM by Nathan Vigneaux

    Changing Dimension in Part Rather than Assembly

    Nathan Vigneaux

      Hello,

      I have followed this example:

      http://help.solidworks.com/2017/English/api/sldworksapi/Change_Dimension_Example_VB.htm

       

      The example works well for an assembly, but when I try to apply this to a part it will not work.

      I changed the file name and also the parameter 'swDocumentTypes_e.swDocASSEMBLY' to 'swDocumentTypes_e.swDocPART'

      but I keep getting this error:

      Object variable or With block variable not set (Error 91)

      at this line:

      'Set swDim = swFeature.Parameter("D3")'

       

      I've also changed the dimension names so that they match up with the code.

      Can anyone tell me why it is not getting a value?

        • Re: Changing Dimension in Part Rather than Assembly
          Alex Burnett

          Did you make sure that swFeature is set to something when the SelectByID2 command is called? If it is null (can't find a selection) then you try to get a parameter from it, it will fail.

           

          If you could post your specific code and a couple of example files then that would help immensely. You can create dummy files so you aren't posting proprietary stuff on here.

            • Re: Changing Dimension in Part Rather than Assembly
              Nathan Vigneaux

              swFeature is set to Nothing when I debug.

               

              Here is the code I'm running:

               

              Option Explicit

               

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swFeature As SldWorks.Feature

              Dim swSelectionManager As SldWorks.SelectionMgr

              Dim swDim As SldWorks.Dimension

              Dim fileName As String

              Dim boolstatus As Boolean

              Dim errors As Long

              Dim warnings As Long

              Dim val As Variant

               

               

              Sub main()

               

                  Set swApp = Application.SldWorks

                  fileName = "C:\Users\nvigneaux\Documents\Macro Testing\macrotestpart.sldprt"

                  Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_Silent, "", errors, warnings)

                

                

                  boolstatus = swModel.Extension.SelectByID2("CirPattern1", "COMPPATTERN", 0, 0, 0, False, 0, Nothing, 0)

                  Set swSelectionManager = swModel.SelectionManager

                  Set swFeature = swSelectionManager.GetSelectedObject6(1, -1)

                 

                  swDim = swFeature.Parameter("D3")

               

                  ' Get D3 of LocalCirPattern1

                  Debug.Print "D3@CirPattern1 is " & swFeature.Parameter("D3").SystemValue & " before changing it."

                 

               

                  ' Change D3 of LocalCirPattern1 from 360 degrees to 270 degrees (4.72 radians)

                  errors = swDim.SetSystemValue3(4.72, swSetValue_InThisConfiguration, Empty)

               

                  swModel.EditRebuild3

               

                  Debug.Print "D3@CirPattern1 is " & swFeature.Parameter("D3").SystemValue & " after changing it."

              End Sub