Creating a tapered cutout using vba

Creating a tapered cutout using vba

Anonymous
Not applicable
841 Views
5 Replies
Message 1 of 6

Creating a tapered cutout using vba

Anonymous
Not applicable

Goodevening,

 

I'm new to using Inventor VBA, and i'm trying to make a tapered hole in a existing solid.

 

I've succeeeded in creating the solidbody, and i've also created the sketch with a circle on it.

 

I'ts no problem to "cut" the extrusion from the solid body.
The problem is that i want the cutout to be tapered at a specific angle say 45° 

I cant't seem to find the code to do this.

 

Can someone please give me an example of how to extrude a circle with a tapered wall?

 

Regards, Ferry.....

0 Likes
Accepted solutions (1)
842 Views
5 Replies
Replies (5)
Message 2 of 6

HermJan.Otterman
Advisor
Advisor

Hello Zoef8,

 

 

here is a sample from the inventor API help.

 

I added the single last line for the taper

oExtrudeDef.TaperAngle = -1

 

mind you that the angle is in radians!!! so recalculate you degrees to radians!

 

(ilogic / vb.net)

 

I hope this will help you

 

 

 

Public Sub DrawBlockWithPocket()

' Create a new part document, using the default part template.

Dim oPartDoc As PartDocument

oPartDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject))

' Set a reference to the component definition.

Dim oCompDef As PartComponentDefinition

oCompDef = oPartDoc.ComponentDefinition

' Create a new sketch on the X-Y work plane. Since it's being created on

' one of the base workplanes we know the orientation it will be created in

' and don't need to worry about controlling it. Because of this we also

' know the origin of the sketch plane will be at (0,0,0) in model space.

Dim oSketch As PlanarSketch

oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

' Set a reference to the transient geometry object.

Dim oTransGeom As TransientGeometry

oTransGeom = ThisApplication.TransientGeometry

' Draw a 4cm x 3cm rectangle with the corner at (0,0)

Dim oRectangleLines As SketchEntitiesEnumerator

oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(4, 3))

' Create a profile.

Dim oProfile As Profile

oProfile = oSketch.Profiles.AddForSolid

' Create a base extrusion 1cm thick.

Dim oExtrudeDef As ExtrudeDefinition

oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation)

Call oExtrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)

Dim oExtrude As ExtrudeFeature

oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

' Get the top face of the extrusion to use for creating the new sketch.

Dim oFrontFace As Face

oFrontFace = oExtrude.StartFaces.Item(1)

' Create a new sketch on this face, but use the method that allows you to

' control the orientation and orgin of the new sketch.

oSketch = oCompDef.Sketches.AddWithOrientation(oFrontFace, oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints(1))

' Determine where in sketch space the point (0.5,0.5,0) is.

Dim oCorner As Point2d

oCorner = oSketch.ModelToSketchSpace(oTransGeom.CreatePoint(0.5, 0.5, 0))

' Create the interior 3cm x 2cm rectangle for the pocket.

oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oCorner, oTransGeom.CreatePoint2d(oCorner.X + 3, oCorner.Y + 2))

' Create a profile.

oProfile = oSketch.Profiles.AddForSolid

' Create a pocket .25 cm deep.

oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation)

oExtrudeDef.SetDistanceExtent(0.25, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)

oExtrudeDef.TaperAngle = -1

oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

End Sub

 

End Class

 

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 6

HermJan.Otterman
Advisor
Advisor

so for the angle add this:

 

Dim angleInRadians As Double = (45 * Math.PI) / 180  '45 = angle in degree

 

replace the -1  with  -angleInRadians

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 4 of 6

Anonymous
Not applicable

Hi Hermjan,

 

Thnk you for the effort! unfortunately  the code you gave me isn't working!

 

As soon as i try to run the macro, i get the error Invalid use off property!

This occurs on the line oPartdoc = thisapplication ......

 

Also at the end of the code the line  

 

oExtrudeDef.SetDistanceExtent(0.25, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)

 

is painted red as to highlight a syntax error of some kind

 

 

 

i'll post the code that i have to create the hole (without the taper offcourse) , perhaps you can m odify it a bit

 

the code assumes there is already a sketch active

 

 

private sub hole()

 

Dim oSketch As PlanarSketch
Set oSketch = ThisApplication.ActiveEditObject

 

Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

 

Dim oTrans As Transaction
Set oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create hole")


'4 sets van elk drie punten t.w. centerpunt start van cirkelboog en einde van de cirkelboog als rotatie 0 graden is
'set 1 hoekpunt linksonder
ipx = 0
ipy = 5
breedte = 0.9
radius = 0.9
cp1x = (ipx - (breedte / 2) + radius)
cp1y = (ipy - (hoogte / 2) + radius)

cp1sx = (cp1x - radius)
cp1sy = cp1y
cp1ex = cp1x
cp1ey = (cp1y - radius)

 

'########################
'# code om Cirkel te tekenen #
'# #


Dim oCircle As SketchCircle

Set oCircle = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(ipx, ipy), radius)
oTrans.End 'einde van transactie

 

 

'######################################################################################
'# vanaf hier code om uitname te maken
'######################################################################################

 

 

Dim oCompDef As PartComponentDefinition

Set oPartDoc = ThisApplication.ActiveDocument 
Set oCompDef = oPartDoc.ComponentDefinition 
Set oProfile = oSketch.Profiles.AddForSolid 

cut = True


If cut = True Then
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
End If

If cut = False Then
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
End If


cutdir = "neg"

 

If cutdir = "neg" Then
Call oExtrudeDef.SetDistanceExtent(0.4, kNegativeExtentDirection) ' extrusiediepte vanaf werkvlak

Else
Call oExtrudeDef.SetDistanceExtent(0.4, kPositiveExtentDirection) ' extrusiediepte vanaf werkvlak
End If

Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

 


oSketch.ExitEdit


End Sub

 

 

 

Thanks for looking at it

Regards Ferry.....

0 Likes
Message 5 of 6

HermJan.Otterman
Advisor
Advisor
Accepted solution

Hello Ferry,

 

 

 

 

I added one line:

 

oExtrudeDef.TaperAngle = -((45 * 3.xxx-xxxxxxxx) / 180)

 

45 is the angle, 3.1415.. = PI

 

if you look in the Inventor API help look for an Example: "Extrude Feature - Create Block with Pocket"

you will find the VBA code of what I send previously.

it will make the block and a new sketch

 

 

 

Your code with one line added

 

 

Private Sub hole()

 

Dim oSketch As PlanarSketch
Set oSketch = ThisApplication.ActiveEditObject

 

Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

 

Dim oTrans As Transaction
Set oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create hole")


'4 sets van elk drie punten t.w. centerpunt start van cirkelboog en einde van de cirkelboog als rotatie 0 graden is
'set 1 hoekpunt linksonder
ipx = 0
ipy = 5
breedte = 0.9
Radius = 0.9
cp1x = (ipx - (breedte / 2) + Radius)
cp1y = (ipy - (hoogte / 2) + Radius)

cp1sx = (cp1x - Radius)
cp1sy = cp1y
cp1ex = cp1x
cp1ey = (cp1y - Radius)

 

'########################
'# code om Cirkel te tekenen #
'# #


Dim oCircle As SketchCircle

Set oCircle = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(ipx, ipy), Radius)
oTrans.End 'einde van transactie

 

 

'######################################################################################
'# vanaf hier code om uitname te maken
'######################################################################################

 

 

Dim oCompDef As PartComponentDefinition

Set oPartDoc = ThisApplication.ActiveDocument
Set oCompDef = oPartDoc.ComponentDefinition
Set oProfile = oSketch.Profiles.AddForSolid

cut = True


If cut = True Then
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
oExtrudeDef.TaperAngle = -((45 * 3.xxx-xxxxxxxx) / 180)  'alleen deze regel toegevoegd!
End If

If cut = False Then
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
End If


cutdir = "neg"

 

If cutdir = "neg" Then
Call oExtrudeDef.SetDistanceExtent(0.4, kNegativeExtentDirection) ' extrusiediepte vanaf werkvlak

Else
Call oExtrudeDef.SetDistanceExtent(0.4, kPositiveExtentDirection) ' extrusiediepte vanaf werkvlak
End If

Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

 


oSketch.ExitEdit


End Sub

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 6 of 6

Anonymous
Not applicable

Great!!!  

 

This is the solution i was looking for!

 

Thank you very much for helping me! Works great!

 

Regards, Ferry..

0 Likes