I would like to create code that automatically adds dimensions to assembly views in a drawing.
I would like to display in the assembly view using points or entities that exist in the part.
The code below completes including the part's points in the assembly view. I want to use this to display dimension lines. How do I do this? Also, please let me know how I should modify the code to use non-point entities.
Sub main() Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet Dim oView As DrawingView = ActiveSheet.View("BaseView1").View Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim silo As Document silo = oDoc.ReferencedDocuments.Item(9) 'hardcoded for the part I need Dim oWP1 As Inventor.WorkPoint = silo.componentdefinition.workpoints.item("DPA1-1") Dim oWPP1 As WorkPointProxy Dim oAssDoc As AssemblyDocument = oDoc Dim oOccs As ComponentOccurrences oOccs = oAssDoc.ComponentDefinition.Occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oOccs 'Chops off ":####" at the End Of occurrance display name Dim oOccName As String oOccName = oOcc.Name Dim trimCount As Integer trimCount = oOccName.Length - oOccName.LastIndexOf(":") oOccName = Left(oOccName, (oOccName.Length - trimCount)) If oOccName = silo.DisplayName oOcc.CreateGeometryProxy(oWP1, oWPP1) oView.SetIncludeStatus(oWPP1, True) End If Next End Sub
You might want to look at the feature 'Assign name' to face.
You can use those names in your ilogic code in your drawing. Adding dimension can be as simple as this:
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet1:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim namedGeometry1 = VIEW1.GetIntent(MakePath("SubAssem1:1", "Part2:1"), "Face1")
Dim namedGeometry2 = VIEW1.GetIntent(MakePath("SubAssem1:1", "Part2:1"), "Face2")
Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
ThisDrawing.BeginManage()
Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW1.SheetPoint(-0.1, 0.5), namedGeometry1)
Dim linDim2 = genDims.AddLinear("Dimension 2", VIEW1.SheetPoint(1.1, 0.5), namedGeometry2)
Dim linDim3 = genDims.AddLinear("Dimension 3", VIEW1.SheetPoint(0.5, 1.2), namedGeometry1, namedGeometry2)
ThisDrawing.EndManage()
Maybe this YouTube movie is interesting to you: https://www.youtube.com/watch?v=9C3c6OVsU1U
On a side note, sometimes dimension texts are placed in an unexpected place. The reason and the workaround are a bit to much to discuss here. However, I proposed a solution/idea to Autodesk. In that proposal/idea, you can find all the information on the topic. (And it would be cool if you voted for the idea/proposal 😉
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
"Assign name" cannot be defined in an assembly. Because they are defined only in the part, you need code to create dimensions by defining them in the part and importing them from the assembly view...
indeed the "Assign name" method only works in parts. But by using the iLogic command "MakePath" you can get the intent of a Faces in a part in an assemlby. Have a look at this line:
Dim namedGeometry1 = VIEW1.GetIntent(MakePath("SubAssem1:1", "Part2:1"), "Face1")
The named face here is in the "SubAssem1:1" and "Part2:1"
But if you really want to define your faces in your assembly (but want to use most of the default iLogic commands) then have a look at my blog series on this topic. (I would not recommend doing this as a beginner but maybe it works for you.) This series will let you recreate the functions iLogic has but then for assemblies.
Can't find what you're looking for? Ask the community or share your knowledge.