Leader Text on an Assembly Edge

Leader Text on an Assembly Edge

Anonymous
Not applicable
885 Views
4 Replies
Message 1 of 5

Leader Text on an Assembly Edge

Anonymous
Not applicable

Greetings,

Using Inventor 2016

Windows 7

 

The following is the code for the creation of a leader on a specific edge in a part.

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
         
    Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
         
    Dim orefdoc As PartDocument = ThisApplication.Documents.Open("K:\Inventor\IRW Drawing File\IRWBaseForDrawings.ipt", False)
    
    Dim oDrawingCurvesEnum As DrawingCurvesEnumerator
       
    Dim oEdge As Edge = orefdoc.ComponentDefinition.SurfaceBodies.Item(2).Edges.Item(11) ' edge 11 or 12
            
    Dim oView As DrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)
        
     oDrawingCurvesEnum = oView.DrawingCurves(oEdge)
   
    Dim oDrawingCurve As DrawingCurve = oDrawingCurvesEnum.Item(1)

   
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint

    
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
     oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
     oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y+6))
     'oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X+1, oMidPoint.Y + 6))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent
     oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oMidpoint)

     oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String
    sText = "ELECTRICAL CONTROL PANEL"

    Dim oLeaderNote As LeaderNote
     oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
        
    Dim oFirstNode As LeaderNode
     oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

 

The following is a code that I am trying to create to have the same behavior in an assembly.

 

 

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
         
    Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
         
    Dim orefdoc As AssemblyDocument = ThisApplication.Documents.Open("K:\Inventor\IRW Drawing File\IRW Dev.iam", False)
    
    Dim oDrawingCurvesEnum As DrawingCurvesEnumerator
       
    Dim oEdge As Edge = orefdoc.ComponentDefinition.Occurrences.Item(1).SurfaceBodies.Item(2).Edges.Item(11) ' edge 11 or 12
            
    Dim oView As DrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)
        
     oDrawingCurvesEnum = oView.DrawingCurves(oEdge)
   
    Dim oDrawingCurve As DrawingCurve = oDrawingCurvesEnum.Item(1)

   
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint

    
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
     oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
     oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y+6))
     'oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X+1, oMidPoint.Y + 6))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent
     oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oMidpoint)

     oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String
    sText = "ELECTRICAL CONTROL PANEL"

    Dim oLeaderNote As LeaderNote
     oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
        
    Dim oFirstNode As LeaderNode
     oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

 

 

 When I use the Microsoft Visual Basic window to help debug.  The only error appears on the following line. Invalid Procedure Call or Argument

oDrawingCurvesEnum = oView.DrawingCurves(oEdge)

 

iLogic throws off this error code:

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DrawingView.get_DrawingCurves(Object ModelObject)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Error in rule: TestLeaders, in document: IRW Dev

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

 

I have searched and searched to try and figure out why the code is throwing this error.  It appears there is a problem with how I identified the edge on my assembly.  However, I cannot seem to find the error?

 

Or there is a problem with how the DrawingCurvesEnumerator is being used?

 

The files that I am using to figure this out are attached.

 

Any help that leads to a solutioin is greatly appreciated!

 

0 Likes
Accepted solutions (1)
886 Views
4 Replies
Replies (4)
Message 2 of 5

wayne.brill
Collaborator
Collaborator

Hi,

 

I am able to recreate the error using the uploaded drawing and assembly. So far I am not finding the solution.

 

I am able to get oView.DrawingCurves(oEdge) to return the DrawingCurve in the DrawingCurvesEnumerator if I use a simple assembly I created. I need to rule out a problem with your assembly. Can you provide the complete assembly with all of the ipt files? Let me know if you want to send this to me directly.

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable

Wayne,

Sure If I can it would probably be better to send them all directly to you.  However, There are multiple large files.

 

 

0 Likes
Message 4 of 5

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi,

 

Thanks for providing the full assembly.  (privately)

 

I have not resolved the error when using the drawing attached to this post. However if I create a new drawing and create the base and project view using the full assembly, the code below does create the leader.  (attached that drawing)

 

One thing I found is that it makes a difference if the referenced assembly used to get the edge is opened with the same level of detail as the assembly that is referenced by the view. In this VBA example (an update to your code) the FileManager.GetLastActiveLevelOfDetailRepresentation() is used to get the LOD.

 

Public Sub LeaderNote_Curves_Test()
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
         
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
         
    'WB added
    Dim strFullFileName As String
    strFullFileName = "C:\Users\brillw\Documents\Inventor\WB_2-18-16\11864917 Leader Assembly Edge\IRW Dev.iam"
    
    ' Set a reference to the FileManager object.
    Dim oFileManager As FileManager
    Set oFileManager = ThisApplication.FileManager
    
    ' Get the name of the last active Level of Detail (LOD) Representation.
    Dim strLastActiveLOD As String
    strLastActiveLOD = oFileManager.GetLastActiveLevelOfDetailRepresentation(strFullFileName)
    
    ' Use the full file name and LOD name to get the full document name.
    Dim strFullDocumentName As String
    strFullDocumentName = oFileManager.GetFullDocumentName(strFullFileName, strLastActiveLOD)
    'WB END added
         
    Dim orefdoc As AssemblyDocument
    'Set orefdoc = ThisApplication.Documents.Open("K:\Inventor\IRW Drawing File\IRW Dev.iam", False)
    ' Get the error on this line "oView.DrawingCurves(oEdge)" with this
   ' Set orefdoc = ThisApplication.Documents.Open("C:\Users\brillw\Documents\Inventor\WB_2-18-16\11864917 Leader Assembly Edge\IRW Dev.iam", False)
   ' WB added - Error does not occur and leader is created using this to open the LOD
    Set orefdoc = ThisApplication.Documents.Open(strFullDocumentName, False)

    Dim oEdge As Edge
    Set oEdge = orefdoc.ComponentDefinition.Occurrences.Item(1).SurfaceBodies.Item(2).Edges.Item(11) ' edge 11 or 12
            
    Dim oView As DrawingView
    'Set oView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)
    'WB added, commented above
    Set oView = oDrawDoc.ActiveSheet.DrawingViews.Item(2)
        
    Dim oDrawingCurvesEnum As DrawingCurvesEnumerator
    Set oDrawingCurvesEnum = oView.DrawingCurves(oEdge)
   
    Dim oDrawingCurve As DrawingCurve
    Set oDrawingCurve = oDrawingCurvesEnum.Item(1)

    Dim oMidPoint As Point2d
    Set oMidPoint = oDrawingCurve.MidPoint

    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
     Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.x, oMidPoint.y + 6))
     'oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X+1?, oMidPoint.Y + 6))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent
    Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oMidPoint)

     Call oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String
    sText = "ELECTRICAL CONTROL PANEL"

    Dim oLeaderNote As LeaderNote
    Set oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
        
    Dim oFirstNode As LeaderNode
    Set oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

End Sub

Please let me know the results you get.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

Anonymous
Not applicable

Worked Like Charm!  Thank you very much!

Your help is greatly appreciated.

0 Likes