iLogic Leader Assistance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.