iLogic Leader Assistance

iLogic Leader Assistance

Anonymous
Not applicable
1,125 Views
7 Replies
Message 1 of 8

iLogic Leader Assistance

Anonymous
Not applicable

Hi, 

 

I've spent a good deal of time trying to educate myself in writing iLogic code and I've hit a wall.  What I'm trying to do is automate a view on a particular sheet using leaders to call out the ends of parts.  I'd like the leaders to pull an iProperty followed by a number with each number increasing by one.  For example, the iProperty would be "A" so the leaders would start with A1 then A2, A3 and so on.  I have searched the web and found a few instances of code that people say work yet when I try it, I run into errors.  I typically get one of the following errors: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)), Unable to cast object of type 'Autodesk.iLogic.Runtime.CadDrawingSheet' to type 'Inventor.Sheet' or the rule runs and nothing appears to happen. 

 

Here are two examples of code I've tried using. At the moment I am just trying to get the leaders to appear. I figured I'd work on the iProperty code and numbering once I can get the leaders working. 

 

This code gives me this error: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

ActiveSheet = ThisDrawing.Sheet("Metal Setup")

ActiveView = ActiveSheet.View("Labeled view")



Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
   
   ' Set a reference to the active sheet.   
    Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet 
    
    Dim oDrawingView As DrawingView = oActiveSheet.DrawingViews.Item(1)
    
   ' Set a reference to the drawing curve segment. This assumes that a drawing curve is selected    
    Dim oDrawingCurveSegment As DrawingCurveSegment = oDrawDoc.SelectSet.Item(1)
   
   ' Set a reference to the drawing curve.   
    Dim oDrawingCurve As DrawingCurve = oDrawingCurveSegment.Parent
    
    ' Get the mid point of the selected curve, assuming that the selected curve is linear    
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint
    
    Dim oEndPoint As Point2d = oDrawingCurve.EndPoint    
   
    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry ' Set a reference to the TransientGeometry object.
    
    ' Create a few leader points.  
    Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 
   
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oEndPoint.X - 2, oEndPoint.Y + 2))
    
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oEndPoint.X - 1, oEndPoint.Y + 1))    
    
    ' 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 = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
    
    Call oLeaderPoints.Add(oGeometryIntent)
'    RouteSize = Parameter("Route_Size")'    RouteType = Parameter("Route_Type")'    RouteSide = Parameter("Route_Side")
 ' 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 =  RouteSize  + " " + RouteType + " " + RouteSide    
   
    Dim oLeaderNote As LeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText) 
    
     ' Insert a node.
    Dim oFirstNode As LeaderNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)
        
    Dim oSecondNode As LeaderNode  = oFirstNode.ChildNodes.Item(1)
    
'    Call oFirstNode.InsertNode(oTG.CreatePoint2d(oEndPoint.X - 1, oEndPoint.Y + 1))
    Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oEndPoint.X - 1, oEndPoint.Y + 1))

 

This one runs but no leaders appear.

ActiveSheet = ThisDrawing.Sheet("Metal Setup")

ActiveView = ActiveSheet.View("Labeled view")



Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
   
   ' Set a reference to the active sheet.   
    Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet 
    
    Dim oDrawingView As DrawingView = oActiveSheet.DrawingViews.Item(1)
    
   ' Set a reference to the drawing curve segment. This assumes that a drawing curve is selected    
    Dim oDrawingCurveSegment As DrawingCurveSegment = oDrawDoc.SelectSet.Item(1)
   
   ' Set a reference to the drawing curve.   
    Dim oDrawingCurve As DrawingCurve = oDrawingCurveSegment.Parent
    
    ' Get the mid point of the selected curve, assuming that the selected curve is linear    
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint
    
    Dim oEndPoint As Point2d = oDrawingCurve.EndPoint    
   
    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry ' Set a reference to the TransientGeometry object.
    
    ' Create a few leader points.  
    Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 
   
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oEndPoint.X - 2, oEndPoint.Y + 2))
    
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oEndPoint.X - 1, oEndPoint.Y + 1))    
    
    ' 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 = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
    
    Call oLeaderPoints.Add(oGeometryIntent)
'    RouteSize = Parameter("Route_Size")'    RouteType = Parameter("Route_Type")'    RouteSide = Parameter("Route_Side")
 ' 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 =  RouteSize  + " " + RouteType + " " + RouteSide    
   
    Dim oLeaderNote As LeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText) 
    
     ' Insert a node.
    Dim oFirstNode As LeaderNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)
        
    Dim oSecondNode As LeaderNode  = oFirstNode.ChildNodes.Item(1)
    
'    Call oFirstNode.InsertNode(oTG.CreatePoint2d(oEndPoint.X - 1, oEndPoint.Y + 1))
    Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oEndPoint.X - 1, oEndPoint.Y + 1))

Any help would be greatly appreciated. I am open to suggestions, maybe there is a better way to approach what I am trying to do.

 

 

 

 

 

0 Likes
1,126 Views
7 Replies
Replies (7)
Message 2 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide non confidential drawing to test the iLogic code?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 8

Anonymous
Not applicable

Hi Chandra,

 

Here is the drawing I am working on along with a snippet of the view with the labeling I'm hoping to create. 

 

Thank you for your help,

Jenny

0 Likes
Message 4 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

The above iLogic code will work for only linear drawing curves. But drawing contains circular or elliptical drawing curves.

 

Can you please create leader for drawing curve in drawing through UI? Same will be tested through API.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 8

Anonymous
Not applicable

HI Chandra,

 

I was not able to get the code above to work for me.  I got the following error,” The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))”  However, with the help of a coworker I was able to get one of the other codes (Rule 20) in my file to work. The code (Rule 20) has been modified to this:

 

Dim doc = ThisApplication.ActiveDocument

Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "select line")

 

' Set a reference to the drawing document.

' This assumes a drawing document is active.

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

 

' Set a reference to the active sheet.

Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet

 

' Set a reference to the drawing curve segment.

' This assumes that a drwaing curve is selected.

Dim oDrawingCurveSegment As DrawingCurveSegment = entity

 

' Set a reference to the drawing curve.

Dim oDrawingCurve As DrawingCurve = oDrawingCurveSegment.Parent

 

' Get the mid point of the selected curve

' assuming that the selection curve is linear

Dim oMidPoint As Point2d = oDrawingCurve.MidPoint

 

' Set a reference to the TransientGeometry object.

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

 

Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

 

' Create a few leader points.

Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y - 1.8))

Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y - 1.8 ))

 

' Create an intent and add to the leader points collection.

' This is the geometry that the symbol will attach to.

Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)

 

Call oLeaderPoints.Add(oGeometryIntent)

 

'Dim oNote As String

'    oNote = oDrawDoc.ActiveSheet.DrawingNotes.LeaderNotes.Item(1).FormattedText

'    'MessageBox.Show( oNote, "Title")

 

    'Dim sText As String

    Dim sText As String

    'ItemLetters = Parameter("J19708 metal item A.iam.ItemLetter")

    'sText = oNote

   

'    sText =oDrawDoc.ActiveSheet.DrawingNotes.LeaderNotes.Item(1).FormattedText

    sText =oDrawDoc.ActiveSheet.DrawingNotes.LeaderNotes.Item(1).FormattedText

   

   

    'MessageBox.Show( sText, "Title")

   

    'sText = "<Parameter Resolved='True' ComponentIdentifier='" & strFilename & "' Name='ItemLetter' Precision='2'>" & ItemLetters & "</Parameter>"

   

 

    Dim oLeaderNote As LeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)

'

'    ' Insert a node.

'    Dim oFirstNode As LeaderNode = oLeaderNote.Leader.RootNode.ChildNodes.Item(1)

'

'    Dim oSecondNode As LeaderNode = oFirstNode.ChildNodes.Item(1)

'

'    Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X + 5, oMidPoint.Y + 5))

'End Sub

'

'' Get the first symbol definition

'Dim oSketchSymDef As SketchedSymbolDefinition = oDrawDoc.SketchedSymbolDefinitions.Item("test leader")

'

'' Create the symbol with a leader

'Dim oSketchedSymbol As SketchedSymbol = oActiveSheet.SketchedSymbols.AddWithLeader(oSketchSymDef, oLeaderPoints)

 

The one quirk is that I have to have a dummy leader set off to the side so that the code can refer to it in order to pull our custom property “ItemLetter”.  Here is the line of code:

sText =oDrawDoc.ActiveSheet.DrawingNotes.LeaderNotes.Item(1).FormattedText 

If you open the leader box it looks like this:

 

(Snippet was deleted, please see attachment)

 

This has been our best work around for this but I keep thinking there has to be a better way to do this. 

The assembly we are labeling has a user parameter, “ItemLetter” as well. I was able to manually create a leader that worked really well, it would update anytime the ItemLetter was changed but I don’t know how to create the code for this.  The manually created leader dialog box looks like this:

 

(Snippet was deleted, please see attachment)

 

Is there a way to change this line of code so that it will insert the User Parameter from the assembly?

sText =oDrawDoc.ActiveSheet.DrawingNotes.LeaderNotes.Item(1).FormattedText

That would be ideal.  Then I need to figure out how to do the following two things:

  1. Have this automated, as in automatically pick the parts and place the leaders. Right now I have to run it and then pick a part.  We are trying to fully automate this print so the engineers can focus on larger, more complex projects.
  2. I need to figure out the code so that the ItemLetter is followed by a number that increases by one with each new part. Ex QQ1, QQ2, QQ3 and so on.

Thanks for the help!

0 Likes
Message 6 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Below iLogic code works only on selection of linearDrawingCurve. Because, midpoint is always associated with line curve segment. In the attached drawing, there are no much line curve segments. This is actual reason to throw exception from iLogic code.

 

Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y - 1.8))

Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X, oMidPoint.Y - 1.8 ))

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 8

Anonymous
Not applicable

HI Chandra,

 

I have attached the latest drawing for you to see.  It may make more sense.  I have also made some notes on the print explaining what the two rules (Rule20 (Works) & Rule20 (Works) Test) are doing.  

 

Rule20 (Works) is the best of the two rules at the moment.  Ideally I would like to be able to insert the parameter from the assembly in a way that it will update anytime I change the value of the ItemLetter in the assy.  

 

The ultimate result I'm looking for is to have this view completely label the end of each part with the ItemLetter followed by a consecutive number, ex X1, X2, X3. . .

 

Thank you for your help,

Jenny

0 Likes
Message 8 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

To read the parameter of assy, need assembly files as well. Please attach non confidential assembly (zipped).

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes