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: 

VBA WorkPlanes.AddByNormalToCurve doesn't work , but it works fine in the UI

1 REPLY 1
Reply
Message 1 of 2
Anonymous
264 Views, 1 Reply

VBA WorkPlanes.AddByNormalToCurve doesn't work , but it works fine in the UI

Hello,

    I'm trying to programatically create a relatively complex shape, and to do so, I need to create a work plane normal to an equation curve.  

 

In the UI, I can easily create an equation curve, then create a plane normal to that curve at the endpoint.  It works perfectly, and looks like this:

normal1.jpg

This is the equation (That was created programatically)

normal2.jpg

And I can add a normal plane to it, no problem.

 

 But when I attempt to create the equation curve and plane programmatically, I get, "Invalid Procedure Call or argument"

 

 

I've attached a dummy part that contains the script.  You can just run the script, it will create a demo line/curve based object, then an equation driven curve, then it will attempt to create normal planes.   The first will succeed, the second will fail.  

 

I think the AddByNormalToCurve is being too restrictive.  The docs say, "For a 2D sketch entity, the geometry must be a Spline2d, Arc2d, Circle2d, EllipticalArc2d, or Ellipse2d", but I believe that equation curves should work as well because they do from the UI.

 

Am I simply missing something, or is there a deficiency in the API?

 

Thanks,

  -Caleb

 

(Just in case the part doesn't work right, you can just try out this code... it's the important bit of the part anway)

 

Private Type SnailStructT
     eqCurve As SketchEquationCurve
     line As SketchLine
End Type


Sub createSweep()
        Dim invDocs As Documents
        Dim currentDoc As Document
        Dim docType As DocumentTypeEnum
        
        Set currentDoc = ThisApplication.ActiveDocument
        
        Debug.Assert (currentDoc.DocumentType = kPartDocumentObject)
        Dim currentPart As Inventor.PartDocument
        Set currentPart = currentDoc
        
        ' create a sketch
        Dim partDef As Inventor.PartComponentDefinition
        Set partDef = currentPart.ComponentDefinition
        
        Dim xyPlane As WorkPlane
        Set xyPlane = partDef.WorkPlanes.Item(3)
        
        Dim sketch As PlanarSketch
        Set sketch = partDef.Sketches.Add(xyPlane, False)
        
        ' Create some lines (from the demo)
        Dim plane1 As WorkPlane
        Dim plane2 As WorkPlane
        Dim snail As SnailStructT
        snail = dumbThingy(sketch)
        Dim o As Object
        Dim p As SketchPoint
        
        Set plane1 = partDef.WorkPlanes.AddByNormalToCurve(snail.line, snail.line.StartSketchPoint)

        ' Create an equation curve
        Dim snail2 As SnailStructT
        snail2 = createSnailSketch(sketch, "20mm", "360 * 2", "360 * 2.25")
        
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' everything works up to this point... but then this fails.'
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim c As Object
        Set p = snail2.eqCurve.StartSketchPoint
        Set c = snail2.eqCurve
        
        Set plane2 = partDef.WorkPlanes.AddByNormalToCurve(c, p)
        
End Sub
Private Function createSnailSketch(sketch As PlanarSketch, _
            r0 As Variant, _
            startAngle As Variant, _
            endAngle As Variant) As SnailStructT
    
    sketch.Edit
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    Dim eqCurve As SketchEquationCurve
     
    Set eqCurve = sketch.SketchEquationCurves.Add(kParametric, _
            kPolar, _
            r0 + "*pow(2.618;t/360)", _
            "t", _
            startAngle, endAngle)
    
    Set createSnailSketch.eqCurve = eqCurve
    sketch.ExitEdit
End Function

Private Function dumbThingy(sketch As PlanarSketch) As SnailStructT
    sketch.Edit
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry

        Dim p1 As Point2d
        Dim p2 As Point2d
        Set p1 = tg.CreatePoint2d(0, 0)
        Set p2 = tg.CreatePoint2d(5, 0)
        Dim lines(1 To 4) As SketchLine
        Set lines(1) = sketch.SketchLines.AddByTwoPoints(p1, p2)
        Set p1 = tg.CreatePoint2d(5, 3)
        Set lines(2) = sketch.SketchLines.AddByTwoPoints(lines(1).EndSketchPoint, p1)
        Set p1 = tg.CreatePoint2d(4, 3)
        Set p2 = tg.CreatePoint2d(4, 4)
        Dim arc As SketchArc
        Set arc = sketch.SketchArcs.AddByCenterStartEndPoint(p1, lines(2).EndSketchPoint, p2)
        
        Set p1 = tg.CreatePoint2d(0, 4)
        Set lines(3) = sketch.SketchLines.AddByTwoPoints(arc.EndSketchPoint, p1)
        
        Set lines(4) = sketch.SketchLines.AddByTwoPoints(lines(1).StartSketchPoint, lines(3).EndSketchPoint)
        Call sketch.GeometricConstraints.AddHorizontal(lines(1))
        Call sketch.GeometricConstraints.AddPerpendicular(lines(1), lines(2))
        Call sketch.GeometricConstraints.AddTangent(lines(2), arc)
        Call sketch.GeometricConstraints.AddTangent(lines(3), arc)
        Call sketch.GeometricConstraints.AddParallel(lines(1), lines(3))
        Call sketch.GeometricConstraints.AddParallel(lines(4), lines(2))
    sketch.ExitEdit
        Set dumbThingy.line = lines(1)
End Function



 

 

1 REPLY 1
Message 2 of 2
YuhanZhang
in reply to: Anonymous

Hi Henry,

 

I can reproduce the error and report it as INVGEN-20942, you can provide this number to query its status later.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report