1 Reply Latest reply on Apr 1, 2015 9:39 PM by Mitchell Conklin

    [VBA Macro] First selected extrude up to body to second selected body

    Daniel Plucinski

      I'm trying to write a macro that will allow me to select an extrude and a body to extrude it to within an assembly. My application for this is defining lengths of pipes between joints. Here are some screenshots to explain further:

       

      Here is my default pipe.

      Zw602xb.png

      Its boss extrude is set to blind and 10" long.

      i0L4VRH.png

      I change it to up to body and select the opposite joint to define the pipe length. I select "This configuration" so that I may have different lengths in my assembly.

      BfCFWwc.png

      This works, but there's several clicks that can be saved if it were made into a macro.

      NnBOQRI.png

      This is what I have so far. I make two selections. First, I select the pipe. Then, I select the joint and run my macro.

      cbb3bYT.png

      This is what happens after running my macro.

      DIsCAnq.png

      If I roll the boss extrude forward and edit it, it's changed correctly, but it has failed to update into my assembly. Plus, I'd like the macro to only modify "This configuration".

      lGwBr4U.png

      Here is my macro thus far:

       

      -------------

       

      Dim swApp As SldWorks.SldWorks

      Dim Model As ModelDoc2

      Dim PipeSelection As Object

      Dim PipeFeature As Feature

      Dim PipeDefinition As ExtrudeFeatureData2

      Dim JointSelection As Object

      Dim JointBody As Object

      Dim isGood As Boolean

      Dim SelMgr As SelectionMgr

       

      Sub main()

       

      Set swApp = CreateObject("sldWorks.application")

      Set Model = swApp.ActiveDoc

      Set SelMgr = Model.SelectionManager

       

      Set PipeSelection = SelMgr.GetSelectedObject6(1, -1)

      Set PipeFeature = PipeSelection.GetFeature

       

      Set JointSelection = SelMgr.GetSelectedObject6(2, -1)

      Set JointBody = JointSelection.GetBody

       

      Set PipeDefinition = PipeFeature.GetDefinition

      isGood = PipeDefinition.AccessSelections(Model, Nothing)

       

      PipeDefinition.SetEndCondition True, 7

      PipeDefinition.SetEndConditionReference True, JointBody

       

      isGood = PipeFeature.ModifyDefinition(PipeDefinition, Model, Nothing)

       

      End Sub

       

      -------------

       

      I couldn't find any solutions within the documentation, but hopefully someone knows how to remedy this issue.

       

      Thanks.

        • Re: [VBA Macro] First selected extrude up to body to second selected body
          Mitchell Conklin

          Hello Daniel, as a matter of fact I have been working on almost the exact same problem with my pluming project.  My complements on getting as far as you have with your application.  I am much more familiar with VBA for excel but am learning quickly for Solidworks.  I would like to speak with you some time about our present pickle and am hoping that between the 2 of us we will be able to come up with a slam dunk solution to post to the form.  Just respond to this thread if you are interested and I will get you my number. 

           

           

          Pluming - Minus the Routing Package ;-)

          Mitch

           

          PS:  I am working on a fitting orientation tool you might find to be useful for your processPointers.jpg