ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
DPDaniel Plucinski16/12/2014

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.