I have been trying to create a code which add dimension in drawing using the work axis available in the parts and assemblies, below is the code I am trying and I am encountering an error. Please help.
Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument Dim oView As DrawingView = ActiveSheet.View("VIEW1").View Dim oAssyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oPt As Point2d = oTG.CreatePoint2d Dim oOcc1 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("Component Name") Dim oOcc2 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("Component Name") Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oDocDef1 As Document = oOcc1.Definition.Document Dim oDocDef2 As Document = oOcc2.Definition.Document oWA1 = oDocDef1.CmponentDefinition.WorkAxis.ItemByName("Axis Name") oWA2 = oDocDef2.ComponentDefinition.WorkAxis.ItemByName("Axis Name") Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oWA1) Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oWA2) Dim oLinDim As LinearGeneralDimension oLinDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oGeomIntent1, oGeomIntent2)
Solved! Go to Solution.
Solved by dutt.thakar. Go to Solution.
In order to dimension between model edges and a Plane or Axis (represented as a line) in a drawing view, you first have to "include" the plane. This is done with something similar to this:
Dim oModelDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPlane As WorkPlane = oModelDoc.ComponentDefinition.WorkPlanes.Item(1)
oView.SetIncludeStatus(oPlane)
Then use something like oView.DrawingCurves().Item(1) object for your GeometryIntent.
Wesley Crihfield
(Not an Autodesk Employee)
Thanks for your reply. The axis with which I am trying to create dimension is already included in the drawing. But I tried with the code you sent. It is still not creating dimension. I am struggling a bit to know whether we can add Work Axis in the geometry intent? If you see the code I described in the question, I am using axis of occurrences from assembly to generate the dimensions. I am not sure whether this method supports or not.
I also tried creating planes and used some of the hints you described but still not working, see below what I tried with your hint.
Dim oPlane1 As WorkPlane = oAssyDoc.ComponentDefinition.WorkPlanes.Item(3) oView.SetIncludeStatus(oPlane1, True) Dim oPlane2 As WorkPlane = oAssyDoc.ComponentDefinition.WorkPlanes.Item(6) oView.SetIncludeStatus(oPlane2, True) Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oPt As Point2d = oTG.CreatePoint2d ' Dim oOcc1 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("Component Name") ' Dim oOcc2 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("Component Name") Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oIn1 As DrawingCurve = oView.DrawingCurves(oPlane1) Dim oIn2 As DrawingCurve = oView.DrawingCurves(oPlane2) Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oIn1) Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oIn2) Dim oLinDim As LinearGeneralDimension oLinDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oGeomIntent1, oGeomIntent2)
Automating placing dimensions onto view geometry within drawings is often a very challenging task. It gets more challenging, the more qantity & complexity of the geometry.
The geometry you will be attaching the dimension to will no longer be recognized as a work axis within the drawing, once it has been "included". It is now seen as a DrawingCurve or DrawingCurveSegment (2D line geometry). You won't still be able to refer to it as oPlane1. You will have to somehow find which Item in the DrawingCurves collection is the line you want. There are a few tools to help with this, but its not easy. One thing that can be checked is CurveType. Once you find the right object, then when specifying your GeometryIntent, you'll usually specify its StartPoint, CenterPoint, or EndPoint, as the actual attachment point on the geometry. Here are a few links to get you started.
DrawingCurvesEnumerator Object
Here are a couple of the API Sample programs available from the Online Help area.
Unfortunately, they use SelectSet to find their geometry, but good reference material anyway.
Create ordinate dimension API Sample
Create linear foreshortened dimension sample API Sample
Wesley Crihfield
(Not an Autodesk Employee)
What version of Inventor are you using?
So this code is not the most efficient by any means but it does work. In the end you'll need to find a way to reference the centerlines on the sheet itself when creating the geometry intent. The below actually creates the centerlines on a custom named layer and later loops through all the centerlines looking for that named layer. It works in my project because I'm only ever adding one centerline and always looking up the other and that's all I need, so I only need two custom layers... I'm sure you can find a better way but hopefully it helps.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oView As DrawingView = ActiveSheet.View("VIEW1").View
Dim oAssyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPt As Point2d = oTG.CreatePoint2d
Dim oOcc1 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("ButtAndTubeAssy")
Dim oOcc2 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("Rod")
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oDocDef1 As Document = oOcc1.Definition.Document
Dim oDocDef2 As Document = oOcc2.Definition.Document
Dim oWA1 As WorkAxis
Dim oWAP1 As WorkAxisProxy
For Each myAxis In oDocDef1.ComponentDefinition.WorkAxes
If myAxis.Name = "Y Axis" Then oWA1 = myAxis
Next
Logger.Debug(oWA1.Name)
Call oOcc1.CreateGeometryProxy(oWA1, oWAP1)
Logger.Debug(oWAP1.Name)
oSheet.Centerlines.AddByWorkFeature(oWAP1, oView, ,ThisDrawing.Document.StylesManager.Layers("ButtYAxis"))
Dim oWA2 As WorkAxis
Dim oWAP2 As WorkAxisProxy
For Each myAxis In oDocDef2.ComponentDefinition.WorkAxes
If myAxis.Name = "Y Axis" Then oWA2 = myAxis
Next
Call oOcc2.CreateGeometryProxy(oWA2, oWAP2)
oSheet.Centerlines.AddByWorkFeature(oWAP2, oView, , ThisDrawing.Document.StylesManager.Layers("RodYAxis"))
For Each CL In ActiveSheet.Sheet.Centerlines
If CL.Layer.Name = "ButtYAxis" Then
BaseYAxis = CL
Else If CL.Layer.Name = "RodYAxis" Then
RodYAxis = CL
End If
Next
Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(BaseYAxis)
Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(RodYAxis)
Dim oLinDim As LinearGeneralDimension
oLinDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oGeomIntent1, oGeomIntent2)
This is done in 2020... I know 2021 added new iLogic for adding dims based on named geometry so hopefully this is actually already obsolete.
Thanks for the efforts and writing this code.
Answer to your first question : I am now using Inventor 2019.
I have tried adding the same code in my drawing with some modifications.
Here is the issues I am facing: First ItemByName is giving me error and it is not recognizing in the tree that which Occurrence I would like to use for Work axis. The I tried with Item(1) instead of ItemByName and it is processing the information but only first child assembly occurrences and not the sub assemblies or sub parts.
Second thing is When I am adding user defined axis it is not supporting and thus the method of creating proxies is not working. Also it is not adding center lines using the layers added in your code. I am not sure whether it is problem with 2019 or I am still missing something. See the picture for info.
Thanks for the efforts finally I am able to crack it.
See below code for information, First thing is you need is to access leaf occurrences to get all sub assembly occurrences and second thing WorkAxes.Item("Axis Name") to specify the axis needs to be used.
Thanks @clutsa and @WCrihfield for your efforts and guidance.
BR,
Dutt.
Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument Dim oView As DrawingView = ActiveSheet.View("VIEW1").View Dim oAssyDoc As AssemblyDocument = ActiveSheet.View("VIEW1").ModelDocument Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oPt As Point2d = oTG.CreatePoint2d Dim oOcc1 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.AllLeafOccurrences.Item(1) Dim oOcc2 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.AllLeafOccurrences.Item(3) MessageBox.Show(oOcc1.Name) MessageBox.Show(oOcc2.Name) Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oDocDef1 As Document = oOcc1.Definition.Document Dim oDocDef2 As Document = oOcc2.Definition.Document Dim oWA1 As WorkAxis = oDocDef1.ComponentDefinition.WorkAxes.Item("InletRefAxis") Dim oWAP1 As WorkAxisProxy ' For Each myAxis In oDocDef1.ComponentDefinition.WorkAxes ' If myAxis.Name = "InletRefAxis" Then oWA1 = myAxis ' Next Logger.Debug(oWA1.Name) oOcc1.CreateGeometryProxy(oWA1, oWAP1) Logger.Debug(oWAP1.Name) Dim oCL1 As Centerline oCL1 = oSheet.Centerlines.AddByWorkFeature(oWAP1, oView) Dim oWA2 As WorkAxis = oDocDef2.ComponentDefinition.WorkAxes.Item("Y Axis") Dim oWAP2 As WorkAxisProxy ' For Each myAxis1 In oDocDef2.ComponentDefinition.WorkAxes ' If myAxis1.Name = "Y Axis" Then oWA2 = myAxis1 ' Next oOcc2.CreateGeometryProxy(oWA2, oWAP2) Dim oCL2 As Centerline oCL2 = oSheet.Centerlines.AddByWorkFeature(oWAP2,oView) Logger.Debug(oWA2.Name) Logger.Debug(oWAP2.Name) Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oCL1) Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oCL2) Dim oLinDim As LinearGeneralDimension oLinDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oGeomIntent1, oGeomIntent2)
I think if we work this backwards we can get you an answer. I commented out all the code to create the centerlines from work axes. In you drawing manually create the centerlines and custom layers. Don't forget to set the centerlines to the new layers. See if you can get that much to work to prove out that 2019 can dimension to centerline with iLogic.
Then if we need to we can figure out how to produce the centerlines automatically and see if we can just keep a reference to that centerline without having to search the layers.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oView As DrawingView = ActiveSheet.View("VIEW1").View
Dim oAssyDoc As AssemblyDocument = ThisDrawing.ModelDocument 'oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPt As Point2d = oTG.CreatePoint2d
'Dim oOcc1 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("ButtAndTubeAssy") 'use to find top level components
'Dim oOcc2 As ComponentOccurrence' = oAssyDoc.ComponentDefinition.Occurrences.ItemByName("Rod")
'For Each prt As ComponentOccurrence In oAssyDoc.ComponentDefinition.Occurrences.AllLeafOccurrences 'AllLeafOccurrences burrows thru Occurrences of Occurences
' 'Logger.Debug(prt.Name)
' If prt.Name Like "RodEndFitting" Then 'use to find subOccurrences
' oOcc2 = prt
' Else If prt.Name Like "SomeOtherSubComponentName" Then 'can find multiple parts in same loop
' oOcc2 = prt
' End If
'Next
''Logger.Debug(oOcc1.Name)
''Logger.Debug(oOcc2.Name)
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
'Dim oDocDef1 As Document = oOcc1.Definition.Document
'Dim oDocDef2 As Document = oOcc2.Definition.Document
'Dim oWA1 As WorkAxis
'Dim oWAP1 As WorkAxisProxy
'For Each myAxis In oDocDef1.ComponentDefinition.WorkAxes
' If myAxis.Name = "Y Axis" Then oWA1 = myAxis
'Next
''Logger.Debug(oWA1.Name)
'Call oOcc1.CreateGeometryProxy(oWA1, oWAP1)
''Logger.Debug(oWAP1.Name)
'oSheet.Centerlines.AddByWorkFeature(oWAP1, oView, ,ThisDrawing.Document.StylesManager.Layers("ButtYAxis"))
'Dim oWA2 As WorkAxis
'Dim oWAP2 As WorkAxisProxy
'For Each myAxis In oDocDef2.ComponentDefinition.WorkAxes
' If myAxis.Name = "Y Axis" Then oWA2 = myAxis
'Next
'Call oOcc2.CreateGeometryProxy(oWA2, oWAP2)
'oSheet.Centerlines.AddByWorkFeature(oWAP2, oView, , ThisDrawing.Document.StylesManager.Layers("RodYAxis"))
For Each CL In ActiveSheet.Sheet.Centerlines
If CL.Layer.Name = "ButtYAxis" Then
BaseYAxis = CL
Else If CL.Layer.Name = "RodYAxis" Then
RodYAxis = CL
End If
Next
Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(BaseYAxis)
Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(RodYAxis)
Dim oLinDim As LinearGeneralDimension
oLinDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPt, oGeomIntent1, oGeomIntent2)
Can't find what you're looking for? Ask the community or share your knowledge.