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
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
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.
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
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.
Please solve this macro.
thanks in advance
Thanks & Regards,
LINUS KOTTE
I looked at your VBA project and saw the error:
It should be sketch1.SketchCircles.AddByCenterRadius
'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)
Hi Kriek
Thankyou for ur reply.
I updated code as per ur comments but still it's showing errors.
Please solve my issue.
Thanks and Regards,
LINUS KOTTE
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.
Thankyou Brian
I have one more question.
Brain how to give specific template for creating the model in above macro.
Thanks &Regards,
LINUS KOTTE
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.