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