2D Equation Curve

2D Equation Curve

Anonymous
Not applicable
501 Views
2 Replies
Message 1 of 3

2D Equation Curve

Anonymous
Not applicable

As a complete beginner with the Inventor API I have been working through the 'My First Plug-In' tutorials and various other online  courses/videos using Visual Basic [Visual Studio 2017] without too many problems but now having tried to code for a sketch that is based on an equation curve , I am completely stuck.

 

Autodesk's sample code  doesn't seem to work and nor does a suggested update [below] that appears on one of the forums.

 

'Create a spline based on an equation.

Dim equationCurve As SketchEquationCurve
equationCurve = sketch.SketchEquationCurves.Add(kParametric, kCartesian,   'Set removed as now longer supported
".001*t * cos(t)", ".001*t * sin(t)", 0, 360)         'Syntax Error

 

 

I have played around with this for hours without success. What am I doing wrong?

 

I would be very grateful for a bit of guidance.

 

Thankyou

 

 

0 Likes
Accepted solutions (1)
502 Views
2 Replies
Replies (2)
Message 2 of 3

Xun.Zhang
Alumni
Alumni
Accepted solution

Hello @Anonymous,

Launch Inventor and try below vba code.

Hope it helps!

Public Sub SketchCurves()
    ' Create a new part.
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                  ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
                  
    
    ' Create a 2D sketch on the Y-Z plane.
    Dim sketch2 As PlanarSketch
    Set sketch2 = partDef.Sketches.Add(partDef.WorkPlanes.Item(1))
    
    ' Create a spline based on an equation.
    Dim equationCurve As SketchEquationCurve
    Set equationCurve = sketch2.SketchEquationCurves.Add(kParametric, kCartesian, ".001*t * cos(t)", ".001*t * sin(t)", 0, 360)
                                
    ' Create a 3D sketch.
    Dim sketch3 As Sketch3D
    Set sketch3 = partDef.Sketches3D.Add
    
    
    ' Create a 3D spline based on an equation.
    Dim equationCurve2 As SketchEquationCurve3D
    Set equationCurve2 = sketch3.SketchEquationCurves3D.Add(kCartesian, _
                            ".001*t * cos(t) + 8", ".001*t * sin(t)", "0.002*t", 0, 360 * 3)
                            
    ThisApplication.ActiveView.Fit    

End Sub

 


Xun
Message 3 of 3

Anonymous
Not applicable

Thankyou for you reply.

 

Whilst the code for the 2D Equation Curve certainly works in the VBA Editor in Inventor, the code I have been writing so far doesn't, as it is has been produced  with Visual Studio Community 2017.

 

I would like to stay with Visual Studio as its IntelliSense is really helpful for a beginner. I have manged to get quite a long way but I am stuck on the code for the equation curve.

 

Dim equationCurve As SketchEquationCurve

Set equationCurve = sketch2.SketchEquationCurves.Add(kParametric, kCartesian, ".001*t * cos(t)", ".001*t * sin(t)", 0, 360)

 

How would this be written in Visual Studio?

 

0 Likes