iLogic Sheet Metal Punch Tool

iLogic Sheet Metal Punch Tool

systemerorr41
Participant Participant
1,183 Views
7 Replies
Message 1 of 8

iLogic Sheet Metal Punch Tool

systemerorr41
Participant
Participant

Hello,

 

I made a quick iLogic rule which creates a new sketch, and puts a point on the sketch plane on a specific position.

Now, I would like to insert a Sheet Metal Punch Tool on said sketch point using Ilogic.

 

I've read this article on the Autodesk forums, which uses Ifeatures instead of Sheet Metal Punch Tool:

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/insert-ifeature-with-ilogic/td-p/712184...

But I'd like to use the sketch point which was previously created, like you'd normally do when using Sheet Metal Punch Tool. Additionally, I'd also like to specify the angle of the sheet metal punch tool using Ilogic, which you'd normally set under the 'geometry' tab.

How would I go about doing this?

Thanks 🙂

 

 

0 Likes
Accepted solutions (1)
1,184 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Not super familiar with this but out of curiosity I tried an attempt. I found an example of the angle punch tool in the API help. Regarding using an existing sketch I believe you would use the pick command  and pick the existing sketch point ,get the x and y coordinates and then add this point 2d with center point set to false to points collection of the punch tool.

Can you post the rule your are using?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8

JelteDeJong
Mentor
Mentor

without any code from you, it's difficult to finish it. but the following rule should work as a standalone rule. it will place a punch tool on all points of a selected sketch under 45 degrees.

Dim sketch As PlanarSketch = ThisApplication.CommandManager.Pick(
    SelectionFilterEnum.kAllPlanarEntities, "Select a sketch (with points)")
'Dim doc As PartDocument = ThisDoc.Document
'Dim def As SheetMetalComponentDefinition = doc.ComponentDefinition
Dim def As SheetMetalComponentDefinition = sketch.Parent

Dim objectCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
For Each sketchPoint As SketchPoint In sketch.SketchPoints
    objectCollection.Add(SketchPoint)
Next

Dim features As SheetMetalFeatures = def.Features

Dim featureDef = features.PunchToolFeatures.CreateiFeatureDefinition(
    "C:\Users\Public\Documents\Autodesk\Inventor 2021\Catalog\Punches\curved slot.ide")


Dim degrees As Double = 45
Dim rad As Double = degrees * Math.PI / 180
features.PunchToolFeatures.Add(objectCollection, featureDef, rad)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 8

systemerorr41
Participant
Participant

Hi!

Thanks for taking the time to post some code! 🙂

 

Running the code yields me with an error:

systemerorr41_2-1629643153462.pngsystemerorr41_3-1629643179917.png

invApp = ThisApplication
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
'CREATE SKETCH Dim xzPlane As Inventor.WorkPlane = oCD.WorkPlanes.Item(2) Dim sketch As Inventor.PlanarSketch sketch = oCD.Sketches.Add(xzPlane, False) sketch.Name = "PunchTool Sketch" 'DRAW POINT ON SKETCH Dim tg As Inventor.TransientGeometry = invApp.TransientGeometry Dim points As Inventor.SketchPoints = sketch.SketchPoints Dim x As Double x = 2.0 Dim y As Double z = 2.0 Row1Start = points.Add(tg.CreatePoint2d(x, z), True) 'CHOOSE PUNCH TOOL Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oPartDef As PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition Dim oFeatures As PartFeatures oFeatures = oPartDef.Features Dim oiFeatureDef As iFeatureDefinition 'oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2022\Catalog\Punches\keyhole.ide")

Dim def As SheetMetalComponentDefinition = sketch.Parent Dim features As SheetMetalFeatures = def.Features Dim featureDef = features.PunchToolFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2022\Catalog\Punches\keyhole.ide") Dim degrees As Double = 45 Dim rad As Double = degrees * Math.PI / 180 features.PunchToolFeatures.Add(points, featureDef, rad)
 

Where can I find more information about API functions, such as 'features.PunchToolFeatures.CreateiFeatureDefinition' for example?

I looked on https://www.autodesk.com/developer-network/platform-technologies/inventor/overview but I can't seem to find a document which talks about this.

 

Thanks!

 

0 Likes
Message 5 of 8

JelteDeJong
Mentor
Mentor

It's possible to find all API in the programming help.

programHelp.png

I changed your code a bit and added some comments. Some of the things you wanted are not possible.

 

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition

'CREATE SKETCH
Dim xzPlane As Inventor.WorkPlane = oPartDef.WorkPlanes.Item(2)
' next line could not work: Sketches placed on a work plane are invalid for punchtools
'Dim sketch As Inventor.PlanarSketch = oPartDef.Sketches.Add(xzPlane, False)
Dim face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face")
Dim sketch As Inventor.PlanarSketch = oPartDef.Sketches.Add(face, False)
'DRAW POINT ON SKETCH
Dim tg As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim points As Inventor.SketchPoints = sketch.SketchPoints
' be aware that those coordinates (2,2) are on the coordinate system of 
' the sketch and always x,y coordinates
Dim x As Double = 2.0 Dim y As Double = 2.0 Dim Row1Start = points.Add(tg.CreatePoint2d(x, y), True) ' CREATE OBJECT COLLECTION Dim punchPlaces As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection() punchPlaces.Add(Row1Start) 'CHOOSE PUNCH TOOL Dim features As SheetMetalFeatures = oPartDef.Features Dim featureDef = features.PunchToolFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2022\Catalog\Punches\keyhole.ide") Dim degrees As Double = 45 Dim rad As Double = degrees * Math.PI / 180 features.PunchToolFeatures.Add(punchPlaces, featureDef, rad)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 8

systemerorr41
Participant
Participant

Hi,

Thank you!

 

Instead of picking a face, I'm using the following code to avoid user-interaction:

oEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
Dim oFace As Face 
oFace = oEntities.FindEntity("Face0")
Dim sketch As Inventor.PlanarSketch
sketch = oAssDef.Sketches.Add(oFace)

The code runs fine up until the point where the punchtool gets inserted. So the sketch gets created, points in the sketch are inserted etc.. But when it comes down to inserting the punchtool it gives me an error. 

systemerorr41_0-1629714571883.png

So if i uncomment:

features.PunchToolFeatures.Add(points, featureDef, rad)

Then it works fine. I can use the created sketch with points and manually insert the punch tool with no problems.

Could you please show me where i made a mistake?

Here's the code in its entirety:

oAssDoc = ThisApplication.ActiveDocument
oAssDef = oAssDoc.ComponentDefinition
invApp = ThisApplication
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
'CREATE SKETCH
oEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
Dim oFace As Face 
oFace = oEntities.FindEntity("Face0")
Dim sketch As Inventor.PlanarSketch
sketch = oAssDef.Sketches.Add(oFace)
sketch.Name = "PunchTool Sketch"
'DRAW POINT ON SKETCH
Dim tg As Inventor.TransientGeometry = invApp.TransientGeometry 
Dim points As Inventor.SketchPoints = sketch.SketchPoints 
Dim x As Double
x = 2.0
Dim y As Double
z = 2.0
Row1Start = points.Add(tg.CreatePoint2d(x, z), True)
'CHOOSE PUNCH TOOL
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument 
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oFeatures As PartFeatures
oFeatures = oPartDef.Features
Dim oiFeatureDef As iFeatureDefinition

Dim def As SheetMetalComponentDefinition = sketch.Parent
Dim features As SheetMetalFeatures = def.Features
Dim featureDef = features.PunchToolFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2022\Catalog\Punches\keyhole.ide")
Dim degrees As Double = 45
Dim rad As Double = degrees * Math.PI / 180
'features.PunchToolFeatures.Add(points, featureDef, rad)

 

0 Likes
Message 7 of 8

JelteDeJong
Mentor
Mentor
Accepted solution

try this

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition

'CREATE SKETCH
Dim oEntities = iLogicVb.Automation.GetNamedEntities(oPartDoc)
Dim face As Face = oEntities.FindEntity("Face0")
Dim sketch As Inventor.PlanarSketch = oPartDef.Sketches.Add(face, False)

'DRAW POINT ON SKETCH
Dim tg As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim points As Inventor.SketchPoints = sketch.SketchPoints
' be aware that those coordinates (2,2) are on the coordinate system of 
' the sketch and always x,y coordinates
Dim x As Double = 2.0
Dim y As Double = 2.0
Dim Row1Start = points.Add(tg.CreatePoint2d(x, y), True)

' CREATE OBJECT COLLECTION
Dim punchPlaces As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
punchPlaces.Add(Row1Start)

'CHOOSE PUNCH TOOL
Dim features As SheetMetalFeatures = oPartDef.Features
Dim featureDef = features.PunchToolFeatures.CreateiFeatureDefinition("C:\Users\Public\Documents\Autodesk\Inventor 2022\Catalog\Punches\keyhole.ide")
Dim degrees As Double = 45
Dim rad As Double = degrees * Math.PI / 180
features.PunchToolFeatures.Add(punchPlaces, featureDef, rad)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 8 of 8

A.Acheson
Mentor
Mentor

I noticed there is an error inserting the iFeature manually and also when inserted by code.

It looks like the same error you have seen below

AAcheson_0-1629730318853.png

 

 

 

The sketch and points get created correctly and the feature gets inserted correctly but will throw the error right before feature insertion. This occurred with INV2020 keyhole.ide.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan