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: 

Problem in a Macro

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
linuskotte
592 Views, 8 Replies

Problem in a Macro

Hi

 

 

this is my code creating pipe in inventor part modelling

.

while run this macro this type of error msg showing(Image2) what's the problem i don't know please solve my issue

 

 

 

Image1 is my Form1

 

 

 

Private Sub CommandButton1_Click()

'Define Variables
Dim CenterlineradiusO As Double
Dim CenterRadiusI As Double
Dim DistantExtent As Double

'set variables from values in edit boxes
CenterRadiusO = OuterDiameter / 2
CenterRadiusI = InnerDiameter / 2
DistantExtent = Pipelength

'Error message if inner diameter greater than outer diameter

If InnerDiameter > OuterDiametre Then
Createbutton.Enabled = False
MsgBox ("Inner diameter must be a smaller value than outer diameter")
End If

' Create new part document
Dim oDoc As PartDocument
Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject)

'get component definetion from part document
Dim ocompdef As ComponentDefinition
Set ocompdef = oDoc.ComponentDefinition

'Create a new sketch on the X-Y work plane
Dim sketch1 As PlanarSketch
Set sketch1 = ocompdef.Sketches.Add(ocompdef.WorkPlanes.Item(3))

'set a reference to the transient geometry object
Dim oTransgeom As TransientGeometry
Set oTransgeom = ThisApplication.TransientGeometry

'Draw a circle on the sketch
Dim Outercircle As SketchCircle
Set Outercircle = sketch1.SketchCircles.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusO)
Dim Innercircle As SketchCircle
Set Innercircle = sketch1.SketchCircles.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusI)

'Create a profile
Dim profile As profile
Set profile = sketch1.Profiles.AddForSolid

' Create a solid extrusion.
Dim Extrusion1 As ExtrudeFeature
Set Extrusion1 = ocompdef.Features.ExtrudeFeatures.AddByDistanceExtent(profile, 3, kSymmetricExtentDirection, kJoinOperation)

'fit the view
ThisApplication.ActiveView.Fit

End Sub





 

 

 

Thanks In advance

 

 

 

Regards,

LINUS KOTTE

8 REPLIES 8
Message 2 of 9
Ralf_Krieg
in reply to: linuskotte

Hi

 

And on which line the error occurs? If I try it out, just replacing OuterDiameter / 2, InnerDiameter / 2 and Pipelength with fixed values cause I don't have your form, the code runs fine.


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 3 of 9
Anonymous
in reply to: linuskotte

Hi LINUS KOTTE,

 

You've got a spelling mistake in your code (Highlighted in Red). Also, if the inner circle is smaller than the outer circle, your program will still run, you need an exit sub to stop the code from going any further.

 

Jope this help you.

 

Jon.

 

 

Private Sub CommandButton1_Click()

'Define Variables
Dim CenterlineradiusO As Double
Dim CenterRadiusI As Double
Dim DistantExtent As Double

'set variables from values in edit boxes
CenterRadiusO = OuterDiameter / 2
CenterRadiusI = InnerDiameter / 2
DistantExtent = Pipelength

'Error message if inner diameter greater than outer diameter

If InnerDiameter > OuterDiametre Then
Createbutton.Enabled = False
MsgBox ("Inner diameter must be a smaller value than outer diameter")

Exit Sub
End If

' Create new part document
Dim oDoc As PartDocument
Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject)

'get component definetion from part document
Dim ocompdef As ComponentDefinition
Set ocompdef = oDoc.ComponentDefinition

'Create a new sketch on the X-Y work plane
Dim sketch1 As PlanarSketch
Set sketch1 = ocompdef.Sketches.Add(ocompdef.WorkPlanes.Item(3))

'set a reference to the transient geometry object
Dim oTransgeom As TransientGeometry
Set oTransgeom = ThisApplication.TransientGeometry

'Draw a circle on the sketch
Dim Outercircle As SketchCircle
Set Outercircle = sketch1.SketchCircles.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusO)
Dim Innercircle As SketchCircle
Set Innercircle = sketch1.SketchCircles.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusI)

'Create a profile
Dim profile As profile
Set profile = sketch1.Profiles.AddForSolid

' Create a solid extrusion.
Dim Extrusion1 As ExtrudeFeature
Set Extrusion1 = ocompdef.Features.ExtrudeFeatures.AddByDistanceExtent(profile, 3, kSymmetricExtentDirection, kJoinOperation)

'fit the view
ThisApplication.ActiveView.Fit

End Sub

Message 4 of 9
linuskotte
in reply to: Anonymous

Hi

 

Here i attached my .ivb file in this macro one error is coming why it's coming i don't know.

 

please change the attached file extension is .ivb then it's open in inventor.

 

Capture.JPG

 

 

Please solve this macro.

 

thanks in advance

 

Thanks & Regards,

LINUS KOTTE

Message 5 of 9
jdkriek
in reply to: linuskotte

I looked at your VBA project and saw the error:

 

It should be sketch1.SketchCircles.AddByCenterRadius

 

errorSketchCircles.PNG

 

'Draw a circle on the sketch
Dim Outercircle As SketchCircle

' This line causes error
'Set Outercircle = sketch1.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusO)

' Should be
Set Outercircle = sketch1.SketchCircles.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusO)

Dim Innercircle As SketchCircle
Set Innercircle = sketch1.SketchCircles.AddByCenterRadius(oTransgeom.CreatePoint2d(0, 0), CenterRadiusI)
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 6 of 9
linuskotte
in reply to: jdkriek

Hi Kriek

Thankyou for ur reply.

 

I updated code as per ur comments but still it's showing errors.

 

error.JPG

 

 

Please solve my issue.

 

 

Thanks and Regards,

LINUS KOTTE

 

Message 7 of 9
ekinsb
in reply to: linuskotte

Attached is an updated version of your .ivb file.  There were a few small problems.  First, you weren't getting the values from the dialog so it was trying to create zero radius circles.  Second there were some variables there weren't consistent.  Adding the "Option Explicit" statement at the top of your program will help to find undeclared variables and inconsistencies in naming.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 9
linuskotte
in reply to: ekinsb

Thankyou Brian

 

I have one more question.

Brain how to give specific template for creating the model in above macro.

 

Thanks &Regards,

LINUS KOTTE

Message 9 of 9
ekinsb
in reply to: linuskotte

The Documents.Add method has a second optional argument where you can specify the full filename of the file you want to use as the template.  If you want to use one of the standard templates you can also use the FileMananger.GetTemplateFile function.  There are some samples in the API help for it.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

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

Post to forums  

Autodesk Design & Make Report