2 Replies Latest reply on Feb 5, 2016 9:19 PM by Alexander Kibbe

    How do I select a solid body in a macro?

    Alexander Kibbe

      I have a problem where I need to select a solid body in a macro.

       

      Here is a code snippet.  To use this code you FIRST click a surface on any part then run it.  It prompts you for an offset amount and a repetition count then makes that many "shells" around the original surface of the specified thickness. 

       

      The problem is the last FOR loop.  It's supposed to select the "thicken"s and set their material independent of the part (and independent of eachother)  the problem is that this code selects them the wrong way.  It selects them as if one clicked on 'thicken#' in the main part tree, but I need it to select as if one had clicked on 'thicken#' inside the 'solidbody' subfolder

       

          Set swApp = Application.SldWorks

       

          Set Part = swApp.ActiveDoc

         

          Dim swSurfFeat(50) As SldWorks.Feature

          Dim swThikFeat(50) As SldWorks.Feature

         

          For x = 1 To TextBox2.Text

          boolstatus = Part.InsertOffsetSurface(TextBox1.Text, False)

          Set swSurfFeat(x) = Part.Extension.GetLastFeatureAdded()

          Next x

         

          For x = 1 To TextBox2.Text

          Part.ClearSelection2 True

          swSurfFeat(x).SelectByMark False, 1

          Dim myFeature2 As Object

          Set myFeature2 = Part.FeatureManager.FeatureBossThicken(TextBox1.Text, 1, 0, False, False, True, True)

          Set swThikFeat(x) = Part.Extension.GetLastFeatureAdded()

          Next x

         

          For x = 1 To TextBox2.Text

          Part.ClearSelection2 True

          swThikFeat(x).SelectByMark False, 1

          Part.SetMaterialPropertyName2 "Default", "<location>", "<material>"

          Next x

       

      I know that this sort of code

       

      boolstatus = Part.Extension.SelectByID2("Thicken21", "SOLIDBODY", 0, 0, 0, False, 0, Nothing, 0)

      Part.SetMaterialPropertyName2 "Default", "E:/Program Files/SOLIDWORKS Corp/SOLIDWORKS/lang/english/sldmaterials/SOLIDWORKS Materials.sldmat", "Plain Carbon Steel"

       

      Does correctly select the 'solidbody' and then sets its material, but I can't count on knowing the name of the feature.