Adding BendNote (DrawingCurve) works in VBA but not VB?

Adding BendNote (DrawingCurve) works in VBA but not VB?

mthomas
Collaborator Collaborator
583 Views
6 Replies
Message 1 of 7

Adding BendNote (DrawingCurve) works in VBA but not VB?

mthomas
Collaborator
Collaborator

If I iterate through the DrawingCurves in a drawing view in VBA looking for kBendDownEdge or kBendUpEdge I am able to add BendNotes to the found curves. 

 

This same logic does not work in VB.net. It errors "Exception User-Unhandled" System.Runtime.InteropServices.COMException: 'Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))'

 

I'm not sure why and don't know how to proceed to make it work. 

 

 

Public Sub VBA_BENDNOTE()
        Dim oDoc As DrawingDocument
        Set oDoc = ThisApplication.ActiveDocument
        Dim oSheet As Sheet
        Set oSheet = oDoc.ActiveSheet

        Dim oCurve As DrawingCurve
        Dim myView As DrawingView
        Set myView = oSheet.DrawingViews.Item(1)
        
        Dim myBendNote As BendNote

        For Each oCurve In myView.DrawingCurves
            If oCurve.EdgeType = kBendDownEdge Or oCurve.EdgeType = kBendUpEdge Then
                Set myBendNote = oSheet.DrawingNotes.BendNotes.Add(oCurve)
            End If
        Next

End Sub

 

 

Private Sub AddBendNotes(oSheet As Sheet)
        Dim oCurve As DrawingCurve
        Dim oBendNote As BendNote
        Dim myView As DrawingView = oSheet.DrawingViews.Item(1)

        For Each oCurve In myView.DrawingCurves

            If oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendDownEdge Or Inventor.DrawingEdgeTypeEnum.kBendUpEdge Then
                oBendNote = oSheet.DrawingNotes.BendNotes.Add(oCurve)
            End If
        Next
    End Sub
Mike Thomas

0 Likes
584 Views
6 Replies
Replies (6)
Message 2 of 7

Cadkunde.nl
Collaborator
Collaborator

Helped someone with bend notes on drawingcurve a while ago,

He had a working ilogic script that adds bend notes:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/remove-bend-note-for-high-bend-radiu...

0 Likes
Message 3 of 7

mthomas
Collaborator
Collaborator

That works in VBA and in iLogic but is failing for me in VB.Net, so strange. I'm at a loss on what to do.

 

 

 

Mike Thomas

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

The one tip I might add here is that, even though DrawingCurves is 'Property' of the DrawingView object, it acts like a Method (a Function), and returns a collection type result every time it is used.  So it is best to use it once to set the value of a variable before that start of the loop.  Then use that variable as the collection you are looping through, instead of using that Property directly as the collection to loop through, so it is not re-running that function every time, essentially re-setting the collection each time.  It might work in some situations that way, but it is best to do it the way I suggested above.

So, change this:

For Each oCurve In myView.DrawingCurves

to:

Dim oCurves As DrawingCurvesEnumerator = myView.DrawingCurves
For Each oCurve In oCurves

You might also want to wrap your line that creates the bend note inside of a Try...Catch block, for good measure, and maybe add a Logger.Error() or MsgBox() in the Catch side, as feedback.  There may just be some odd status/property about some curves that it doesn't like.  Just some thoughts.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

mthomas
Collaborator
Collaborator

Thanks for the suggestions. Adding the Try...Catch let me figure out that the EdgeType check needs to be Inventor.DrawingEdgeTypeEnum.kBendExtentEdge in VB.net

 

However, it's still failing on adding the BendNote, even adding the oCurves. 

 

As its VB not iLogic I can't add an Logger.Error(), but will go the debug.print route and see if I can narrow down the differences. 

 

Any other suggestions?

 

 

 

If oCurve.EdgeType = Inventor.DrawingEdgeTypeEnum.kBendExtentEdge Then

 

 

Mike Thomas

0 Likes
Message 6 of 7

JelteDeJong
Mentor
Mentor

Just as a side note. I have 2 blog posts that might interest you. The first explains why I think you should stop using VBA: "Is VBA in Inventor obsolete?" But maybe you find the post: "Automatically generate bend notes" more interesting. There you will find this iLogic rule which creates bendnotes using iLogic.

Dim view As DrawingView = ThisApplication.CommandManager.Pick(
	           SelectionFilterEnum.kDrawingViewFilter,
	           "Select a drawing view")
If (view Is Nothing) Then Return
	
Dim bendCurves = view.DrawingCurves.Cast(Of DrawingCurve).
    Where(Function(curve) curve.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge Or
                          curve.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge).ToList()
						  
Dim bendNotes = view.Parent.DrawingNotes.BendNotes
For Each curve As DrawingCurve In bendCurves
    bendNotes.Add(curve)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 7 of 7

mthomas
Collaborator
Collaborator

Thanks, I will take a look.

 

I was only using VBA in hopes to find out why it was failing in VB.NET. I don't use VBA normally. 

 

Mike Thomas

0 Likes