Need a VBA macro for creating a single sketch, a point and use punch at the end.

Need a VBA macro for creating a single sketch, a point and use punch at the end.

Anonymous
Not applicable
1,476 Views
4 Replies
Message 1 of 5

Need a VBA macro for creating a single sketch, a point and use punch at the end.

Anonymous
Not applicable

Hello, 

 

I required help for performing a operation in Inventor 2014. It is repeated task.

 

I need a VBA macro for creating one sketch, a single point and use that point for punch a mark.

 

so, steps are as follows for macro. (Note - Below all steps should be in a single macro.)

1. Create Sketch (need to select face manually of sheet metal part) --> I already have one macro for the same. I can share, taken from forum.

 

2. on the same sketch, plotting a single point. Co-ordinates for point will be Introduced manually by the user.

 

3. and the last step just open punch tool window, let the user select punch and press "OK".

 

Macro for creating sketch as i said earlier : Please see if below macro can help.

__________________________________________________________________________

Public Sub NewSketchOnPlane()
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument

' Create a new sketch on a selected face.
Dim planarEntity As Object
Set planarEntity = ThisApplication.CommandManager.Pick(kAllPlanarEntities, _
"Select a face or work plane.")
Dim sk As sketch
Set sk = partDoc.ComponentDefinition.Sketches.Add(planarEntity)

' Bring the sketch into edit mode.
sk.Edit
End Sub"

_______________________________________________________________

 

thanks in advance. Smiley Wink

 

0 Likes
Accepted solutions (1)
1,477 Views
4 Replies
Replies (4)
Message 2 of 5

FrodoZhou
Autodesk
Autodesk

Hello,

 

You can add these several lines into your code to create a sketch point, before you exit the sketch env.

 

// Add a sketch point to a planar sketch

Dim oPointOnFace As Point
Set oPointOnFace = planarEntity.PointOnFace //just use the PointOnFace as an example, sounds you will get user input anyway

sk.SketchPoints.Add sk.ModelToSketchSpace(oPointOnFace)

 

After you exit the sketch env, you can add these lines to execute the Punch Tool command which will pop up the dialog. Hope this is helpful.

 

// Find the ButtonDefinition of Punch Tool command and execute it

Dim oDef As ButtonDefinition
For Each oDef In ThisApplication.CommandManager.ControlDefinitions
If oDef.InternalName = "SheetMetalPunchToolCmd" Then
oDef.Execute
End If
Next

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hey thanks for the help,

 

Actually I am not from Coding Background, so could you please do one more favor ?

can u please create a single macro for the same, which I can copy paste.

 

sorry for trouble. Thanks again.

0 Likes
Message 4 of 5

FrodoZhou
Autodesk
Autodesk
Accepted solution

No problem. Try how does this work for you. If it works you should have a sketch point created and the punch tool dialog should pop up.

 

Public Sub NewSketchOnPlane()


Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument

 

' Create a new sketch on a selected face.
Dim planarEntity As Object
Set planarEntity = ThisApplication.CommandManager.Pick(kAllPlanarEntities, _
"Select a face or work plane.")
Dim sk As Sketch
Set sk = partDoc.ComponentDefinition.Sketches.Add(planarEntity)

 

' Bring the sketch into edit mode.
sk.Edit

 

'Add a sketch point to a planar sketch
Dim oPointOnFace As Point
Set oPointOnFace = planarEntity.PointOnFace 'just use the PointOnFace as an example, sounds you will get user input anyway
sk.SketchPoints.Add sk.ModelToSketchSpace(oPointOnFace)

 

'Exit sketch edit
sk.ExitEdit

 

' Find the ButtonDefinition of Punch Tool command and execute it
Dim oDef As ButtonDefinition
Set oDef = ThisApplication.CommandManager.ControlDefinitions("SheetMetalPunchToolCmd")

 

'Execute the Punch Tool command
oDef.Execute

 

End Sub

Message 5 of 5

Anonymous
Not applicable

Hell Yeah ... 

Its working.. .but still the window for point selection doesn't pop up, it takes point anywhere on sketch and goes to next step.

 

No worries, you have literally solved my issue 90%. Now I can use Dimension to set point where I want to by visiting Sketch Environment.

 

Really Thank you,

This macro can save my lot of time.

 

Keep Helping guys like Me. 🙂 

 

Thanks Again.

 

 

 

 

 

 

0 Likes