3D arc geometry evaluator getstrokes "Type mismatch"

3D arc geometry evaluator getstrokes "Type mismatch"

Jef_E
Collaborator Collaborator
861 Views
6 Replies
Message 1 of 7

3D arc geometry evaluator getstrokes "Type mismatch"

Jef_E
Collaborator
Collaborator

Hi,

 

I'm trying to implement the getstrokes feature from the API sample. I modified it a little so the input is the first 3D sketch and the first 3D arc in it.

 

I also have the same problem when trying it for 2D arcs (what I really need) but the sample was for 3D arcs thats why I use this to try and explain my problem.

 

This is the error message produced:

System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.CurveEvaluator.GetStrokes(Double FromParam, Double ToParam, Double Tolerance, Int32& VertexCount, Double[]& VertexCoordinates)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

SyntaxEditor Code Snippet

    Dim partDoc As PartDocument
    partDoc = ThisApplication.ActiveDocument
    
    ' Have the user select a sketch entity.
    Dim selectObj As SketchEntity3D


    selectObj = PartDoc.componentDefinition.Sketches3D.Item(1).SketchArcs3D.Item(1)
    
''From here is nothing edited by me!
If selectObj Is Nothing Then On Error Resume Next Call partDoc.ComponentDefinition.ClientGraphicsCollection.Item("Test").Delete Call partDoc.GraphicsDataSetsCollection.Item("Test").Delete ThisApplication.ActiveView.Update Exit Sub End If ' Get the tolerance to approximate with. Dim tolerance As Double tolerance = Val(InputBox("Enter the chord height tolerance:", "Tolerance", "0.25")) ' Get the evaluator from the curve. Dim eval As CurveEvaluator eval = selectObj.Geometry.Evaluator ' Get the parameter extents. Dim startParam As Double Dim endParam As Double Call eval.GetParamExtents(startParam, endParam) Dim vertexCount As Long Dim vertexCoords() As Double Call eval.GetStrokes(startParam, endParam, tolerance, vertexCount, vertexCoords) ' Create a client graphics object. If one already exists, give the user ' the option of re-using it, or creating a new one. Dim graphics As ClientGraphics Dim graphicsData As GraphicsDataSets On Error Resume Next graphics = partDoc.ComponentDefinition.ClientGraphicsCollection.Item("Test") On Error Goto 0 If graphics Is Nothing Then graphics = partDoc.ComponentDefinition.ClientGraphicsCollection.Add("Test") graphicsData = partDoc.GraphicsDataSetsCollection.Add("Test") Else 'Dim answer As VbMsgBoxResult 'answer = MsgBox("Yes to add to existing graphics. No to create new graphics. Cancel to clean graphics and quit.", vbYesNoCancel + vbQuestion) If answer = vbNo Then On Error Resume Next graphics.Delete partDoc.GraphicsDataSetsCollection.Item("Test").Delete On Error Goto 0 graphics = partDoc.ComponentDefinition.ClientGraphicsCollection.Add("Test") graphicsData = partDoc.GraphicsDataSetsCollection.Add("Test") ElseIf answer = vbYes Then graphicsData = partDoc.GraphicsDataSetsCollection.Item("Test") ElseIf answer = vbCancel Then If Not graphics Is Nothing Then graphics.Delete partDoc.GraphicsDataSetsCollection.Item("Test").Delete ThisApplication.ActiveView.Update Exit Sub End If End If End If Dim coordSet As GraphicsCoordinateSet coordSet = graphicsData.CreateCoordinateSet(1) Call coordSet.PutCoordinates(vertexCoords) ' Create a graphics node. Dim node As GraphicsNode node = graphics.AddNode(1) ' Create a line strip using the calculated coordinates. Dim lineStrip As LineStripGraphics lineStrip = node.AddLineStripGraphics lineStrip.Coordinate= coordSet ThisApplication.ActiveView.Update

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
862 Views
6 Replies
Replies (6)
Message 2 of 7

Jef_E
Collaborator
Collaborator

I'm still stuck here..



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 3 of 7

danijel.radenkovic
Collaborator
Collaborator

Hi Jef,

I have tested your code and it works fine if you add "Set" in every row where is  "variable=something".

 

 

Try with this:

Option Explicit

' Draws client graphics that is an approximation
' of the selected curve.
' To use this have a part open that contains
' a 3D skech that contains curves.
Public Sub Approximate3DSketchGeometry()
    Dim partDoc As PartDocument
    Set partDoc = _
              ThisApplication.ActiveDocument
   
   ' Have the user select a sketch entity.
    Dim selectObj As SketchEntity3D
    
    Set selectObj = partDoc.ComponentDefinition.Sketches3D.Item(1).SketchArcs3D.Item(1)
'    Set selectObj = ThisApplication. _
'                    CommandManager.Pick _
'                    (kSketch3DCurveFilter, _
'                    "Select 3D sketch entity")
    If selectObj Is Nothing Then
        On Error Resume Next
        Call partDoc.ComponentDefinition _
        .ClientGraphicsCollection.Item _
                                ("Test").Delete
        Call partDoc.GraphicsDataSetsCollection _
                             .Item("Test").Delete
        ThisApplication.ActiveView.Update
        Exit Sub
    End If
   
   ' Get the tolerance to approximate with.
    Dim tolerance As Double
    tolerance = Val(InputBox _
     ("Enter the chord height tolerance:", _
                       "Tolerance", "0.25"))
   
   ' Get the evaluator from the curve.
    Dim eval As CurveEvaluator
    Set eval = selectObj.Geometry.Evaluator
   
   ' Get the parameter extents.
    Dim startParam As Double
    Dim endParam As Double
    Call eval.GetParamExtents _
                        (startParam, endParam)
   
    Dim vertexCount As Long
    Dim vertexCoords() As Double
    Call eval.GetStrokes(startParam, endParam, _
            tolerance, vertexCount, vertexCoords)
   
    ' Create a client graphics object.
    ' If one already exists, give the user
    ' the option of re-using it, or creating
    ' a new one.
    Dim graphics As ClientGraphics
    Dim graphicsData As GraphicsDataSets
    On Error Resume Next
    Set graphics = partDoc.ComponentDefinition. _
            ClientGraphicsCollection.Item("Test")
    On Error GoTo 0
    If graphics Is Nothing Then
        Set graphics = partDoc. _
      ComponentDefinition.ClientGraphicsCollection _
                                      .Add("Test")
        Set graphicsData = partDoc. _
           GraphicsDataSetsCollection.Add("Test")
    Else
        Dim answer As VbMsgBoxResult
        answer = MsgBox _
        ("Yes = existing. No = new Cancel. = quit.", _
                         vbYesNoCancel + vbQuestion)
        If answer = vbNo Then
            On Error Resume Next
            graphics.Delete
            partDoc.GraphicsDataSetsCollection _
                              .Item("Test").Delete
            On Error GoTo 0
           
            Set graphics = partDoc.ComponentDefinition _
                  .ClientGraphicsCollection.Add("Test")
            Set graphicsData = partDoc. _
                  GraphicsDataSetsCollection.Add("Test")
        ElseIf answer = vbYes Then
            Set graphicsData = partDoc. _
                GraphicsDataSetsCollection.Item("Test")
        ElseIf answer = vbCancel Then
            If Not graphics Is Nothing Then
                graphics.Delete
                partDoc.GraphicsDataSetsCollection _
                                .Item("Test").Delete
                ThisApplication.ActiveView.Update
                Exit Sub
            End If
        End If
    End If
   
    Dim coordSet As GraphicsCoordinateSet
    Set coordSet = graphicsData.CreateCoordinateSet(1)
    Call coordSet.PutCoordinates(vertexCoords)

   ' Create a graphics node.
    Dim node As GraphicsNode
    Set node = graphics.AddNode(1)
   
    ' Create a line strip using the calculated coordinates.
    Dim lineStrip As LineStripGraphics
    Set lineStrip = node.AddLineStripGraphics
    lineStrip.CoordinateSet = coordSet
   
    ThisApplication.ActiveView.Update
End Sub

Danijel

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 4 of 7

danijel.radenkovic
Collaborator
Collaborator

Here is a video screenshot.

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 5 of 7

Jef_E
Collaborator
Collaborator

Set is because you use VBA and I'm using vb.net so that is not the problem,

 

what version of inventor are you using?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 6 of 7

danijel.radenkovic
Collaborator
Collaborator

@Jef_E wrote:

Set is because you use VBA and I'm using vb.net so that is not the problem,

 

what version of inventor are you using?


Yes, I know that. I just figured out later that you are trying to modify code for ilogic.

 

By the way, I am using Inventor 2017/VBA7.1 on Windows10 x64.

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 7 of 7

danijel.radenkovic
Collaborator
Collaborator

@Jef_E wrote:

Set is because you use VBA and I'm using vb.net so that is not the problem,

 

what version of inventor are you using?


Hi Jef,

According to Mfg DevBlog, I have found something that is interesting.

http://adndevblog.typepad.com/manufacturing/2014/07/type-mismatch-error-with-vba-code-in-net.html

 

What I mentioned as a difference between VBA and VB.net code is in declaration of double. There is a "= {}".

 

 

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.