good afternoon,
Trying to collect hole centers from 2 drawing views and add an ordinate set either up or down based on location of holes on view.
this causes the error:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.OrdinateDimensionSets.Add(ObjectCollection GeometryIntents, Point2d PlacementPoint, DimensionTypeEnum DimensionType, Object DimensionStyle, Object Layer)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
<code>
Dim inv = ThisApplication Dim oDoc = ThisDrawing.Document Dim cnt As Long Dim cursht As Inventor.Sheet Dim Jndx As Long Dim oVw As Inventor.DrawingView Dim oDcrv As Inventor.DrawingCurve 'On Error Resume Next Dim oTG As Inventor.TransientGeometry = inv.TransientGeometry 'On Error Resume Next Dim gIntent As Inventor.GeometryIntent For Jndx = 30 To 31 '87 Dim oUpr As Inventor.ObjectCollection = inv.TransientObjects.CreateObjectCollection Dim oLwr As Inventor.ObjectCollection = inv.TransientObjects.CreateObjectCollection cursht = oDoc.Sheets(Jndx) Dim oviews As Inventor.DrawingViews = cursht.DrawingViews oVw = oviews(2) For Each oDcrv In oVw.DrawingCurves If oDcrv.CurveType = CurveTypeEnum.kCircleCurve Then gIntent = cursht.CreateGeometryIntent(oDcrv.CenterPoint) If gIntent.Geometry.Y >= oVw.Position.Y Then oUpr.Add(gIntent) Else oLwr.Add (gIntent) End If End If 'MessageBox.Show(cnt,oVw.Name) Next ' 'oDcrv If oUpr.Count >1 Then ''MessageBox.Show(OUPR(1).GEOMETRY.X & ", " & oVw.Position.Y + oVw.Height + 3, " UPPER pOSITION") cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr, _ oTG.CreatePoint2d(oUpr(1).GEOMETRY.X, oVw.Position.Y + oVw.Height ), _ DimensionTypeEnum.kVerticalDimensionType) End If If oLwr.Count >1 Then ''MessageBox.Show(OUPR(1).GEOMETRY.X & ", " & oVw.Position.Y - oVw.Height - 3, "LOWER pOSITION") cursht.DrawingDimensions.OrdinateDimensionSets.Add(oLwr, _ oTG.CreatePoint2d(oLwr(1).GEOMETRY.X, oVw.Position.Y - oVw.Height ), _ DimensionTypeEnum.kVerticalDimensionType) End If oVw = oviews(5) oLwr.Clear For Each oDcrv In oVw.DrawingCurves If oDcrv.CurveType = CurveTypeEnum.kCircleCurve Then oLwr.Add (gIntent) End If Next ' 'oDcrv Next 'Jndx
<\code>
Solved! Go to Solution.
Solved by dalton98. Go to Solution.
Hello. I would recommend you look at the sample program for creating ordinate dimensions.
Top right inventor program > (?) icon > Help > Programming/ API Help
Then search "Create ordinate dimension API Sample" > Sample Programs > Drawings > "Create Ordinate Dimension"
Also, I understand your though process on wanting to create the dimension above/ below the view based on the hole position, but in your drawing the holes are vertically aligned, so you want two dimensions for the same position? What if the hole is centered and doesn't favor top/bot? Just some thoughts
Good morning;
Thanks for the reply, however, I do not see in the sample where I went wrong. True, the holes look to be vertically aligned, yet most will not be and only a little out of alignment thus the upper and lower divide to ordinate sets.
The following error occurs
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.OrdinateDimensionSets.Add(ObjectCollection GeometryIntents, Point2d PlacementPoint, DimensionTypeEnum DimensionType, Object DimensionStyle, Object Layer)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
========
when it gets to the 'add'.
I've changed it up a bit to see if I could get the error to pop where I could find it, as such
<code>
If oUpr.Count >1 Then Dim tmppnt As Inventor.Point2d = oTG.CreatePoint2d(oUpr.Item(1).GEOMETRY.X, oVw.Position.Y + oVw.Height) MessageBox.Show(oUpr.Item(1).GEOMETRY.X & ", " & oVw.Position.Y + oVw.Height + 3, " UPPER pOSITION") cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr, tmppnt, DimensionTypeEnum.kVerticalDimensionType) End If If oLwr.Count >1 Then Dim tmppnt As Inventor.Point2d = oTG.CreatePoint2d(oLwr.Item(1).GEOMETRY.X, oVw.Position.Y - oVw.Height ) MessageBox.Show(oUpr.Item(1).GEOMETRY.X & ", " & oVw.Position.Y + oVw.Height + 3, " lower pOSITION")
cursht.DrawingDimensions.OrdinateDimensionSets.Add(oLwr, tmppnt, DimensionTypeEnum.kVerticalDimensionType) End If
<\code>
You cant place all ordinate dimensions with one command, you will need to do each individual one. Ex.
For i = 1 to oUpr.Count
cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr(i), tmppnt, DimensionTypeEnum.kVerticalDimensionType)
Next
I get the following error with that change:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.ObjectCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6939FFDD-BA10-11D2-B779-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
===========
also, the 2018 API Help DrawingDimensions.OrdinateDimensionSets.Add method shows an object collection of GeometryIntents
OrdinateDimensionSets.Add( GeometryIntents As ObjectCollection, PlacementPoint As Point2d, DimensionType As DimensionTypeEnum, [DimensionStyle] As Variant, [Layer] As Variant )
could it be because I didn't specify dimensionstyle or layer optionals from an external rule?
the rule with the recommended change:
<code>
Dim inv = ThisApplication Dim oDoc = ThisDrawing.Document Dim cnt As Long Dim cursht As Inventor.Sheet Dim Jndx As Long Dim oVw As Inventor.DrawingView Dim oDcrv As Inventor.DrawingCurve 'On Error Resume Next Dim oTG As Inventor.TransientGeometry = inv.TransientGeometry 'On Error Resume Next Dim gIntent As Inventor.GeometryIntent For Jndx = 33 To 33 '87 Dim oUpr As Inventor.ObjectCollection = inv.TransientObjects.CreateObjectCollection Dim oLwr As Inventor.ObjectCollection = inv.TransientObjects.CreateObjectCollection cursht = oDoc.Sheets(Jndx) Dim oviews As Inventor.DrawingViews = cursht.DrawingViews oVw = oviews(2) For Each oDcrv In oVw.DrawingCurves If oDcrv.CurveType = CurveTypeEnum.kCircleCurve Then gIntent = cursht.CreateGeometryIntent(oDcrv.CenterPoint) MessageBox.Show(gIntent.Geometry.y.tostring,oVw.Position.Y.ToString) If gIntent.Geometry.Y >= oVw.Position.Y Then oUpr.Add(gIntent) Else oLwr.Add (gIntent) End If End If Next ' 'oDcrv 'MessageBox.Show(oUpr.Count,oLwr.Count) If oUpr.Count >1 Then Dim tmppnt As Inventor.Point2d = oTG.CreatePoint2d(oUpr.Item(1).GEOMETRY.X, oVw.Position.Y + oVw.Height) MessageBox.Show(oUpr.Item(1).GEOMETRY.X & ", " & oVw.Position.Y + oVw.Height + 3, " UPPER pOSITION") 'cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr,tmppnt, DimensionTypeEnum.kVerticalDimensionType) For i = 1 To oUpr.Count cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr(i), tmppnt, DimensionTypeEnum.kVerticalDimensionType) Next End If If oLwr.Count >1 Then Dim tmppnt As Inventor.Point2d = oTG.CreatePoint2d(oLwr.Item(1).GEOMETRY.X, oVw.Position.Y - oVw.Height ) MessageBox.Show(oUpr.Item(1).GEOMETRY.X & ", " & oVw.Position.Y + oVw.Height + 3, " lower pOSITION") 'MessageBox.Show(OUPR(1).GEOMETRY.X & ", " & oVw.Position.Y - oVw.Height - 3, "LOWER pOSITION") 'cursht.DrawingDimensions.OrdinateDimensionSets.Add(oLwr, tmppnt, DimensionTypeEnum.kVerticalDimensionType) For i = 1 To oLwr.Count cursht.DrawingDimensions.OrdinateDimensionSets.Add(oLwr(i), tmppnt, DimensionTypeEnum.kVerticalDimensionType) Next End If oVw = oviews(5) oLwr.Clear For Each oDcrv In oVw.DrawingCurves If oDcrv.CurveType = CurveTypeEnum.kCircleCurve Then oLwr.Add (gIntent) End If Next ' 'oDcrv Next 'Jndx
<\code>
Oh ok I misunderstood. I got it to work for me by changing 2 things:
gIntent = cursht.CreateGeometryIntent(oDcrv, kCenterPointIntent)
'changing oUpr.Item(1).Geometry.X to oUpr.Item(1).PointOnSheet.X
'its a good habit to always define the objects you are working with so i defined
the ordinate dimension set
'also ordinate set dimensions are opposite of what the are so kVerticalDimensionType changes
to kHorizontalDimensionType
Here is the code I altered and got to work:
Dim inv = ThisApplication Dim oDoc = ThisDrawing.Document Dim cnt As Long Dim cursht As Inventor.Sheet Dim Jndx As Long Dim oVw As Inventor.DrawingView Dim oDcrv As Inventor.DrawingCurve 'On Error Resume Next Dim oTG As Inventor.TransientGeometry = inv.TransientGeometry 'On Error Resume Next Dim gIntent As Inventor.GeometryIntent Dim oUpr As Inventor.ObjectCollection = inv.TransientObjects.CreateObjectCollection Dim oLwr As Inventor.ObjectCollection = inv.TransientObjects.CreateObjectCollection cursht = oDoc.ActiveSheet Dim oviews As Inventor.DrawingViews = cursht.DrawingViews oVw = oviews(1) For Each oDcrv In oVw.DrawingCurves If oDcrv.CurveType = CurveTypeEnum.kCircleCurve Then gIntent = cursht.CreateGeometryIntent(oDcrv, kCenterPointIntent) 'If gIntent.Geometry.Y >= oVw.Position.Y Then oUpr.Add(gIntent) 'Else 'oLwr.Add (gIntent) 'End If End If Next ' 'oDcrv 'MessageBox.Show(oUpr.Count,oLwr.Count) If oUpr.Count >1 Then Dim tmppnt As Inventor.Point2d = oTG.CreatePoint2d(oUpr.Item(1).PointOnSheet.X, oVw.Position.Y + oVw.Height) 'MessageBox.Show(oUpr.Item(1).GEOMETRY.X & ", " & oVw.Position.Y + oVw.Height + 3, " UPPER pOSITION") 'cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr,tmppnt, DimensionTypeEnum.kVerticalDimensionType) Dim ordSet1 As OrdinateDimensionSet ordSet1 = cursht.DrawingDimensions.OrdinateDimensionSets.Add(oUpr, tmppnt, DimensionTypeEnum.kHorizontalDimensionType) End If
Can't find what you're looking for? Ask the community or share your knowledge.