4 Replies Latest reply on May 28, 2014 8:03 AM by Fg Ning

    how to Reset the rotate angle of move/copy feature by API

    Fanggang Ning

      dear all

       

      i want to use SolidWorks API to change the  rotate angle of move/copy feature,shown as below

      Ashampoo_Snap_2014.05.26_09h12m47s_003_.jpg

       

      Sub main()

       

       

      Set swApp = Application.SldWorks

       

       

      Set Part = swApp.ActiveDoc

       

       

      Set moveCopyFeat = Part.FeatureByName("实体-移动/复制1")

       

       

      Set moveCopy_featData = moveCopyFeat.GetDefinition

       

      copycount = moveCopy_featData.GetBodiesCount

       

        

      boolstatus = Part.EditRebuild3()

      Part.ClearSelection2 True

      End Sub

       

      in fact ,i don't know how to change or Reset the relevant parameters in feature mainly because i couldn't get these parameter name .

      for instance ,in sketch ,it's easy to get the name by record macro file "part.Parameter("D1@" & "曲面-扫描1@CLK-1")"

       

      while when i modify parameters in feature ,for example ,the rotate angle mentioned above , the macro couldn't record this process ,which lead to the difficulties  for me to modify the parameters that i need to change .


      many thanks


        • Re: how to Reset the rotate angle of move/copy feature by API
          Artem Taturevych

          Hi,

           

          Try this:

           

          Set moveCopy_featData = moveCopyFeat.GetDefinition

           

          copycount = moveCopy_featData.GetBodiesCount

           

          moveCopy_featData.AccessSelections Part, Nothing

          moveCopy_featData.TransformValue = 1.57 'angle in radians

          moveCopyFeat.ModifyDefinition moveCopy_featData, Part, Nothing

            • Re: how to Reset the rotate angle of move/copy feature by API
              Fg Ning

              hi ,Artem

              thank you for your timely reply !

              yes ,

              Set movecopyfeat = assembly.FeatureByName("实体-移动/复制1@CLK-1@8STRANDBRAID")

              Set moveCopy_featData = moveCopyFeat.GetDefinition

              copycount = moveCopy_featData.GetBodiesCount

              moveCopy_featData.AccessSelections Part, Nothing
              moveCopy_featData.TransformValue = 1.57 'angle in radians
              moveCopyFeat.ModifyDefinition moveCopy_featData, Part, Nothing


              can works very well ,while when i put this section into an assembly ,the red linehas some problems .could mind solve this for me .

              thanks

                • Re: how to Reset the rotate angle of move/copy feature by API
                  Artem Taturevych

                  In assembly you need to pass the pointer to the component instead of Nothing:

                   

                  moveCopy_featData.AccessSelections Part, swComp

                  moveCopy_featData.TransformValue = 1.57 'angle in radians

                  moveCopyFeat.ModifyDefinition moveCopy_featData, Part, swComp

                   

                  where

                   

                  Dim swComp as SldWorks.Component2

                  Set swComp = moveCopyFeat.GetComponent()

                   

                  but if you are saying that the red line is failing (I assume you have null-reference exception: Object or with block variable not set) make sure that the name of the feature is correct (i.e. 实体-移动/复制1@CLK-1@8STRANDBRAID) because it is NULL in this case.

                    • Re: how to Reset the rotate angle of move/copy feature by API
                      Fg Ning

                      dear Artem,

                      thank you for your advice .

                      now the programming workshop smoothly,while when i check the effect. i find the angle was not changed ,

                       

                      Dim swApp As Object

                      Dim part As Object

                      Dim assembly As Object

                      Dim boolstatus As Boolean

                      Dim Annotation As Object

                      Dim Feature As Object

                      Dim FeatureData As Object

                      Dim myDisplayDim As Object

                      Dim myDimension As Object

                      Sub main()

                       

                      Set swApp = Application.SldWorks

                      Set part = swApp.ActiveDoc

                          Set moveCopyFeat = part.FeatureByName("实体-移动/复制1")

                      Set moveCopy_featData = moveCopyFeat.GetDefinition

                      moveCopy_featData.AccessSelections part, Nothing

                      moveCopy_featData.TransformValue = 1.57 'angle in radians

                      moveCopyFeat.ModifyDefinition moveCopy_featData, part, Nothing

                      End Sub

                       

                      can you check it for me

                       

                      Ashampoo_Snap_2014.05.26_09h12m47s_003_.jpg