Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a Punch Tool

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
b.kushaiynov
64 Views, 3 Replies

Create a Punch Tool

I just wanted to create a punchtool on a point . There type missmatch i dont understand why , if some one could help me i would very helpfull .  

Sub Bohrungen()

'set a reference to active document
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

' set a reference to shett metal metal definition
Dim oShMetDef As SheetMetalComponentDefinition
Set oShMetDef = oPartDoc.ComponentDefinition

'assume a face has been selected in the part
Dim oFace As Face
Set oFace = oPartDoc.SelectSet(1)

'Set reference to the transient geometry
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry


'Make sure it is a planar face
If oFace.SurfaceType = kPlaneSurface Then

Dim oPlanarSurface As Plane
Set oPlanarSurface = oFace.Geometry

Dim oSketch As PlanarSketch
Set oSketch = oShMetDef.Sketches.Add(oFace)

Dim oPoint1 As SketchPoint
Set oPoint1 = oSketch.SketchPoints.Add(oTG.CreatePoint2d(-10, 3.5), False)


Else
MsgBox ("pls select planar face")

End If

' create an Ifeaturedefinition object for a punch tool
Dim oSMFeatures As SheetMetalFeatures
Set oSMFeatures = oShMetDef.Features

Dim oiFeatureDef As iFeatureDefinition
Set oiFeatureDef = oSMFeatures.PunchToolFeatures.CreateiFeatureDefinition("J:\_Vorlagen\Inventor\Bibliothek\IDE\Punches\Langloch.ide")

'set the inpunt
' Dim oInput As iFeatureInput
' For Each oInput In oiFeatureDef.iFeatureInputs
'
' Dim oParamInput As iFeatureParameterInput
' Select Case oInput.Name
' Case "lg"
' Set oParamInput = oInput
' oParamInput.Expression = "1.6"
' Case "du"
' Set oParamInput = oInput
' oParamInput.Expression = "1.2"
' End Select
' Next
Dim oParamInput As iFeatureParameterInput

Set oParamInput = oiFeatureDef.iFeatureInputs.Item(1)
oParamInput.Expression = "16 mm"

Set oParamInput = oiFeatureDef.iFeatureInputs.Item(2)
oParamInput.Expression = "12 mm"



' Create the iFeature at 0 degree

Dim oPunchTool As PunchToolFeature
Set oPunchTool = oSMFeatures.PunchToolFeatures.Add(oPoint1, oiFeatureDef, 0, False) ' - here is problem i dont know what it is . Typen unverträglich (Fehler 13)

End Sub

3 REPLIES 3
Message 2 of 4
cidhelp
in reply to: b.kushaiynov

Hello @b.kushaiynov ,

 

as first argument of PunchToolFeatures.Add you need an ObjectCollection.

See the API-Sample here:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-00CA6F7C-C067-4001-9894-166F1B130F0F

 

 

Message 3 of 4

The error you're encountering, "Typen unverträglich (Error 13)" indicates a type mismatch, likely related to the parameters passed to PunchToolFeatures.Add. The issue could stem from the oPoint1 parameter not being in the expected type or format.

Here's a suggestion to fix it:

  1. Ensure oPoint1 is of the correct type. Since PunchToolFeatures.Add expects a 3D point, but oPoint1 is created as a 2D point (CreatePoint2d), you should convert the 2D point to a 3D point.

    You can do this by modifying:

    vba
    Copy code
    Dim oPoint1 As SketchPoint Set oPoint1 = oSketch.SketchPoints.Add(oTG.CreatePoint2d(-10, 3.5), False)

    to include a projection or use a 3D point (CreatePoint instead of CreatePoint2d).

  2. You also need to ensure the face and other parameters are set properly before adding the punch tool.

This should resolve the type mismatch issue.

Message 4 of 4
b.kushaiynov
in reply to: b.kushaiynov

Thanks for Clarification. I just didnt understand the issue. What was wrong. 

PunchToolFeatures.Add expects a 3D point-> where can i see this  on objects, that it expects 3D point  ? 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report