VBA: Extrude Upto Vertex

Ok I am trying to automate extrude up to vertex. I recorded doing this and even the recorded macro doesn't work when played back under the same circumstances.

I have tried two methods.

I have the model rebuilt before selecting both the sketch and the vertex. (the vertex I am using is a sketch Point.)

AsModelDoc.FeatureBoss2 True, False, True, 3, 0, 0, 0, False, False, False, False, 0, 0, False, False, False, False

Set ExtrusionFeat = FeatMan.FeatureExtrusion(True, False, False, 3, 0, 0, 0, False, False, False, False, 0, 0, False, False, False, False, False, True, True)

Thank you,

Corey Scheich

Reply to
Corey Scheich
Loading thread data ...

let me see the whole macro

Reply to
Sean Phillips

Here is a simplified example that works the same to it is assumed with this example that you have a sketch with one closed contour selected first from the tree, then the second selection (using CTRL) is a point. These are selected before running the macro. I am using SW2003 SP 4.1 on XP

Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Dim boolstatus As Boolean Dim longstatus As Long Dim Annotation As Object Dim Gtol As Object Dim DatumTag As Object Dim FeatureData As Object Dim Feature As Object Dim Component As Object Dim FeatMan As SldWorks.FeatureManager Dim ThisPoint As SldWorks.SketchPoint Dim ThisLine As SldWorks.SketchLine Dim feat As SldWorks.Feature Dim SelMan As SldWorks.SelectionMgr Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc Set SelMan = Part.SelectionManager Set FeatMan = Part.FeatureManager Set feat = SelMan.GetSelectedObject4(1) Set ThisPoint = SelMan.GetSelectedObject4(2)

Part.ClearSelection

feat.Select2 False, 0 ThisPoint.Select3 True, 1, Nothing

FeatMan.FeatureExtrusion True, False, False, 3, 0, 0.00254, 0.00254, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, 1, 1, 1

Part.SelectionManager.EnableContourSelection = 0 Part.ClearSelection

End Sub

I appreciate the help

Thank you, Corey Scheich

Reply to
Corey Scheich

Just a side note: Extruding up to Body works great, even the recorded macro runs. So I don't understand why going to a vertex doesn't quite work.

Reply to
Corey Scheich

Hello Corey-

I admire your work with macros. I'm very weak in this area.

I do have a question. If your editing a sketch, already have the profile and the vertex selected, why do you need a macro? Isn't it just one mouse click to complete the extrusion?

Best Regards, Devon T. Sowell

formatting link

Reply to
Devon T. Sowell

It is actually part of a much longer macro. It will be able to create a "sweep" without giving the "Sweep intersected itself" error.

Corey

Reply to
Corey Scheich

here this works now.

select a sketch and a vertex or sketchpoint. you must list it as a variant because you dont know what the user has selected. you should do some error checking if it is upto the user to make the selections.

Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Dim boolstatus As Boolean Dim longstatus As Long Dim Annotation As Object Dim Gtol As Object Dim DatumTag As Object Dim FeatureData As Object Dim Feature As Object Dim Component As Object Dim FeatMan As SldWorks.FeatureManager Dim ThisPoint As Variant Dim ThisLine As SldWorks.SketchLine Dim feat As SldWorks.Feature Dim SelMan As SldWorks.SelectionMgr Sub main()

Set swApp = New SldWorks.SldWorks

Set Part = swApp.ActiveDoc Set SelMan = Part.SelectionManager Set FeatMan = Part.FeatureManager Set feat = SelMan.GetSelectedObject4(1) Set ThisPoint = SelMan.GetSelectedObject4(2)

Part.ClearSelection

feat.Select2 False, 0 ThisPoint.Select3 True, 1, Nothing

FeatMan.FeatureExtrusion True, False, False, 3, 0, 0.00254, 0.00254, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, 1, 1, 1

Part.SelectionManager.EnableContourSelection = 0 Part.ClearSelection

End Sub

Reply to
Sean Phillips

Works swell. I'm not sure what you changed but I will look at it.

I appreciate it

Corey Scheich

Reply to
Corey Scheich

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.