Interop Exception for View.DrawingCurves

Interop Exception for View.DrawingCurves

varad.keshatwar
Contributor Contributor
771 Views
21 Replies
Message 1 of 22

Interop Exception for View.DrawingCurves

varad.keshatwar
Contributor
Contributor

Hello Guys,
I am facing an error with the following API
View.DrawingCurves(OModel as Object)
I am facing this Interop error in Visual Basic, while using Inventor 2024 DLL.
I have attached the screenshots of all the errors here with, also attaching my code snippet.

 

Public Overridable Function GetGrooveCurvePoint(iGrooveNo As Integer) As Point2d
        Try
            Dim onumer As DrawingCurvesEnumerator = Nothing
            Dim oCurveLeft As DrawingCurve
            Dim dRefXMin As Double = 1000

 

            'onumer = oViewSection.DrawingCurves(oIptDoc.ComponentDefinition.Features(GlobalCADRes.strGroove + " " & iGrooveNo))
            Dim oFeature As Object = CType(oIptDoc.ComponentDefinition.Features(GlobalCADRes.strGroove & " " & iGrooveNo), Object)
            onumer = oViewSection.DrawingCurves(oFeature)

 

            'Get the Longest Curve of groove
            For Each oDrawCurve As DrawingCurve In onumer
                If oDrawCurve.StartPoint.X > oViewSection.Center.X And oDrawCurve.EndPoint.X > oViewSection.Center.X Then
                    If Math.Round(oDrawCurve.StartPoint.X, 2) = Math.Round(oDrawCurve.EndPoint.X, 2) Then
                        'If Math.Round(oDrawCurve.StartPoint.Y, 2) <> Math.Round(oDrawCurve.EndPoint.Y, 2) Then     ''''change by Nilesh for 69769 on 29/09/11
                        If oDrawCurve.EndPoint.X < dRefXMin Then
                            dRefXMin = oDrawCurve.EndPoint.X
                            oCurveLeft = oDrawCurve
                            'End If
                        End If
                    End If
                End If
            Next

 

            If oCurveLeft IsNot Nothing Then
                If oCurveLeft.StartPoint.X > oCurveLeft.EndPoint.X Then
                    Return oCurveLeft.StartPoint
                Else
                    Return oCurveLeft.EndPoint
                End If
            End If

 

            Return Nothing
        Catch ex As Exception
        End Try
    End Function

 

 

0 Likes
772 Views
21 Replies
Replies (21)
Message 2 of 22

marcin_otręba
Advisor
Advisor

Hi,

 

You share only some part of your code, and also screenshots doesn't give answers what could be wrong, I tested it and it gives good result when i use:

 Dim oFeature As Object = CType(oiptdoc.ComponentDefinition.Features(1), Object)

and when i  declare and set :

Dim oViewSection As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter,"")
Dim oiptdoc As PartDocument = oViewSection.ReferencedDocumentDescriptor.ReferencedDocument

 

also 

 

GlobalCADRes.strGroove is unknown and I don't know if it is correct or not.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 22

varad.keshatwar
Contributor
Contributor

@marcin_otręba 
Hello Marcin,

Thank you for checking the code. But please can you let me know did you try using Autodesk.Inventor.Interop.dll with version 28.2.0.0
PS: 
I'm facing the error at 
oViewSection.DrawingCurves(oFeature)
here at the above lines, somehow it fails to evaluate the drawing curves of required feature

0 Likes
Message 4 of 22

marcin_otręba
Advisor
Advisor

and oviewsection and ofeature both are not nothing ?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 22

varad.keshatwar
Contributor
Contributor

@marcin_otręba  you'll have to setup a environment, or maybe take any ipt or drawing doc to run this part of code. If possible we can connect, and discuss it over.

0 Likes
Message 6 of 22

marcin_otręba
Advisor
Advisor

i tested it with Autodesk.Inventor.Interop.dll with version 28.2.0.0 but in inventor 2025 i don't have 2024 verison installed.

I think there is something wrong with oViewSection object maybe ? where you set it up ? it is global object ?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 22

jjstr8
Collaborator
Collaborator

First thing I would try is to set Embed Interop Types = false for the Inventor interop reference. There's no reason to embed the interop types since the interop dll is already on the target system. Setting it to true breaks a few things in C#, so it may also cause issues in VB.

Message 8 of 22

varad.keshatwar
Contributor
Contributor

Yes, actually when I tried using Autodesk.Inventor.Interop.dll with version 28.2.0.0 in Inventor 2022 it works fine. But with Inventor 2024 it fails over the given piece of code, like it's unable to get the DrawingCurves.

@marcin_otręba no VviewSection has the required SectionView, I have already set it up from drawingdoc.views

0 Likes
Message 9 of 22

varad.keshatwar
Contributor
Contributor

Yes, Embed Interop Types = false for my VB project, also Framework is 4.8

0 Likes
Message 10 of 22

marcin_otręba
Advisor
Advisor

hi,

 

i installed 2024.3 and using my own vb it works just fine:

 

 

marcin_otrba_0-1740471942579.png

marcin_otrba_1-1740472113317.png

marcin_otrba_2-1740472135367.png

 

 

also i checked what happens when i do not set ofeature or sectionview - fo ofeature - nothing - you will get all curves, for sectionview - you would get error : object reference not set...

maybe try to change interop copy local parameter to truw and use specific version to false?

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 11 of 22

varad.keshatwar
Contributor
Contributor

@marcin_otręba, Thank you for setting up the environment. 
I tried the above settings but issue still persists. Also I'm using Inventor 2024.2 maybe if that's the issue.
I have tried to consolidate all the settings/maybe errors and objects here in the screenshot below. Hope that clarifies everything

 

 varadkeshatwar_0-1740483280842.png
PS: We cannot change copy local to true, because for Autodesk.Inventor.Interop, the Copy Local property is typically set to False and cannot be changed directly because it is a COM interop assembly registered in the Global Assembly Cache (GAC).
So for work around I have manually copied it to my project's bin directory.

0 Likes
Message 12 of 22

jjstr8
Collaborator
Collaborator

@varad.keshatwar : Your latest screenshot shows Embed Interop Types still set to true. Does this mean you tried setting it to false and then set it back? Regardless, you shouldn't need to set it to true. Also, the interop dll comes with the Inventor installation. There's no need to set copy local to true or to copy the dll to your addin folder. 

 

I was able to mock up enough code to test what you're doing. Like @marcin_otręba, mine ran fine. The only thing I see that could cause the error is that oFeature is somehow not valid. Your screenshot doesn't show enough to tell. I would remove the cast to Object and make oFeature a PartFeature. The cast is uneccessary since DrawingCurvesEnumerator takes an Object, which PartFeature derives from. 

0 Likes
Message 13 of 22

marcin_otręba
Advisor
Advisor

"The only thing I see that could cause the error is that oFeature is somehow not valid" - i tested it and if oFeature will be empty then oViewSection.DrawingCurves(oFeature) will result with all drawing curves from this view.

@varad.keshatwar could you update inventor to 2024.3.3 ? also did your code work in different inventor versions ?

could you try to ran it from ilogic in simplified version only to check if you will get it run without error?:

 

Dim onumer As DrawingCurvesEnumerator  = Nothing
Dim oCurveLeft As DrawingCurve
Dim oViewSection As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "")
Dim oiptdoc As PartDocument = oViewSection.ReferencedDocumentDescriptor.ReferencedDocument
Dim oFeature As Object = CType(oiptdoc.ComponentDefinition.Features("Kołnierz1"), Object) ' change name to yours
onumer = oViewSection.DrawingCurves(oFeature)
MessageBox.Show(onumer.count, "Title")

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 14 of 22

varad.keshatwar
Contributor
Contributor

Yes @marcin_otręba It works fine with other Inventor versions, in fact I tried 28.2 Autodesk.Inventor.Interop dll with Inventor 2022
Build 153, that worked totally fine.
Also I tried with Inventor VBA from Application tools, it worked fine same as ilogic and sorry unfortunately I cannot update to Inventor 2024.3.3 as of now

0 Likes
Message 15 of 22

varad.keshatwar
Contributor
Contributor

Hello @marcin_otręba @jjstr8 

I apologize for the delay, and I appreciate your input and coordination regarding my issue. I have discovered that the problem I was facing was not occurring for you. It turns out there was a bug that I identified.

I would like to share my findings with you. I found that whenever a sheet update is required, the following API:

DrawingView.DrawingCurves([ModelObject] As Variant) As DrawingCurvesEnumerator`

throws an error in Inventor 2024 but same works fine with Inventor 2022 regardless of Drawingsheet staus, which can be obtained from DrawingSheetStatusBits property for Sheet object.

I have attached a screen recording from my debugging session in Visual Studio 2022, which I hope will help you understand the problem. Additionally, I am including a screenshot for your reference.

varadkeshatwar_0-1741866393171.png

 

0 Likes
Message 16 of 22

jjstr8
Collaborator
Collaborator

@varad.keshatwar : That was the missing piece. You could report it as a bug, but I would say that it's working as intended. I would prefer that it not return the un-updated curves. That seems misleading. They may add a note in the documentation that the DrawingView needs to be up to date. I would just check the UpToDate property on the DrawingView and either force an update or message the user.

0 Likes
Message 17 of 22

Stakin
Collaborator
Collaborator

Pls Try it,if works Let me known.

 

Sub main
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "")
Dim oFeatureName As String= "Change me to your FeatureName"
Dim oPoint As Point2d = oGetFeatureFarRightPoint2d(oView, oFeatureName)
End Sub

Function oGetFeatureFarRightPoint2d(oView As DrawingView,oFeatureName As String) As Point2d
	Dim oPrtDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oFeature As PartFeature = CType(oPrtDoc.ComponentDefinition.Features(oFeatureName), PartFeature)
	Return  oView.DrawingCurves(oFeature).Cast(Of DrawingCurve).Where(Function(X) X.EndPoint.X = X.StartPoint.X).
									Select(Function(X) X.EndPoint).Distinct().OrderByDescending(Function(X) X.X).First()
End Function

 

 

0 Likes
Message 18 of 22

varad.keshatwar
Contributor
Contributor

@jjstr8 Yes it's true, we can either force an update or message the user. But I'm surprised that the same piece of code works totally fine with Inventor 2022 irrespective of sheet health status.

Message 19 of 22

varad.keshatwar
Contributor
Contributor

Hello Inventor Community,

@Stakin @jjstr8 @marcin_otręba 
Guys, I have observed one more issue with the following API.

DrawingView.DrawingCurves([ModelObject] As Variant) As DrawingCurvesEnumerator 

I have observed, when the sheet is sketch mode, and if requires update in that case too this API fails throws the same threw an exception of type 'System.Runtime.InteropServices.COMException'. Even Sheet update and Doc update does not work in this case.
Please refer screenshot attached

varadkeshatwar_0-1742223811010.png

 

PS: Guyz, I'm facing daily new issues with this API. Your guidance will be of great use if you help me to point this to any Autodesk executive ASAP😥😟

0 Likes
Message 20 of 22

jjstr8
Collaborator
Collaborator

@varad.keshatwar : I'm not sure why it worked in 2022 and not in 2024. At this point, I would go with the "message the user" fix. I don't think you'd want to interrupt a sketch edit. Let the use take care of updating the sheet.

0 Likes