Failed to create Punch Feature in API ( Help )

Failed to create Punch Feature in API ( Help )

SandmanINV
Advocate Advocate
398 Views
2 Replies
Message 1 of 3

Failed to create Punch Feature in API ( Help )

SandmanINV
Advocate
Advocate

Hi Everybody.

I am trying to create a punch feature, but, i failed. Somebody help me about that.

Here is my  code folow API Help.

Thank you.

Option Explicit
Private Sub cmd_khoitao_Click()
'Tao part
Dim opart As PartDocument
Set opart = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject, , , "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"))
'don vi do
'Dim ounit As UnitsOfMeasure
'Set ounit = ThisApplication.ActiveDocument.UnitsOfMeasure
'Dim olenghtunit As UnitsTypeEnum
'olenghtunit = ounit.LengthUnits
'unit.LengthUnits = kMillimeterLengthUnits
'ThisApplication.ActiveDocument.Update
'''''''''''''''
Dim ocompdef As SheetMetalComponentDefinition
Set ocompdef = opart.ComponentDefinition

Dim otransi As TransientGeometry
Set otransi = ThisApplication.TransientGeometry
'Quy dinh kich thuoc
ocompdef.UseSheetMetalStyleThickness = False
Dim othickness As Parameter
Set othickness = ocompdef.Thickness
othickness.Value = 0.16 'cm
'Tao base sketch
Dim osketchbase As Sketch
Set osketchbase = ocompdef.Sketches.Add(ocompdef.WorkPlanes.Item(2), False)

Dim orecbase As SketchEntitiesEnumerator
Set orecbase = osketchbase.SketchLines.AddAsTwoPointRectangle(otransi.CreatePoint2d(0, 0), otransi.CreatePoint2d(159.5, 104.9))
'Base feature
Dim obaseprofile As Profile
Set obaseprofile = osketchbase.Profiles.AddForSolid

Dim smfeatures As SheetMetalFeatures
Set smfeatures = ocompdef.Features

Dim obasefacedef As FaceFeatureDefinition
Set obasefacedef = smfeatures.FaceFeatures.CreateFaceFeatureDefinition(obaseprofile)

Dim obaseface As FaceFeature
Set obaseface = smfeatures.FaceFeatures.Add(obasefacedef)
'Tao sketch thu 2
Dim ofacesketch2 As Face
Set ofacesketch2 = obaseface.Faces.Item(5)
Dim osketch2 As Sketch
Set osketch2 = ocompdef.Sketches.AddWithOrientation(ofacesketch2, ocompdef.WorkAxes.Item(1), True, True, ocompdef.WorkPoints.Item(1), False)
Dim opointcol As ObjectCollection
Set opointcol = ThisApplication.TransientObjects.CreateObjectCollection

Dim opoint11 As SketchPoint
Set opoint11 = osketch2.SketchPoints.Add(otransi.CreatePoint2d(-159.5 + 24.72, 104.9 - 13.74), True)
Call opointcol.Add(opoint11)

Dim opoint12 As SketchPoint
Set opoint12 = osketch2.SketchPoints.Add(otransi.CreatePoint2d(-159.5 + 24.72 - 6, 104.9 - 13.74), True)
Call opointcol.Add(opoint12)

Dim opoint13 As SketchPoint
Set opoint13 = osketch2.SketchPoints.Add(otransi.CreatePoint2d(-159.5 + 24.72 - 12, 104.9 - 13.74), True)
Call opointcol.Add(opoint13)
'ifeature deffinition
Dim oiFeatureDef As iFeatureDefinition
Set oiFeatureDef = smfeatures.PunchToolFeatures.CreateiFeatureDefinition( _
"C:\Users\Public\Documents\Autodesk\Inventor 2015\Catalog\Punches\keyhole.ide") ' Set input Dim oInput As iFeatureInput For Each oInput In oiFeatureDef.iFeatureInputs Dim oparainput As iFeatureParameterInput Select Case oInput.Name Case "Length" Set oparainput = oInput oparainput.Expression = "0.1 cm" Case "Slot_Width" Set oparainput = oInput oparainput.Expression = "1.2 cm" Case "Hole_Diameter" Set oparainput = oInput oparainput.Expression = "1.5 cm" End Select Next Dim opunch1 As PunchToolFeature Set opunch1 = smfeatures.PunchToolFeatures.Add(opointcol, oiFeatureDef) MsgBox ("Done!") ThisApplication.ActiveView.GoHome End Sub
0 Likes
399 Views
2 Replies
Replies (2)
Message 2 of 3

SandmanINV
Advocate
Advocate

Somebody help.

0 Likes
Message 3 of 3

SandmanINV
Advocate
Advocate

Hi ! I resolved problem by myself.

Thank you.

0 Likes