Message 1 of 5
DIMENSIONS IN A DRAWING
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I was trying to put dimensions with workplane but I have problems when doing it, since I want the dimension to be placed depending on the coordinate where the occurrence is.
But as much as I have tried, I have not succeeded, I do not know if anyone here can support me by taking a look at my code to see if I'm on the right track.
'[ Identifies the measures of the box
Dim Width As String = Round(Measure.ExtentsLength) 'Width of box (x)
Dim Height As String = Round(Measure.ExtentsHeight) 'Height of the box (y)
Dim Length As String = Round(Measure.ExtentsWidth) 'Length of the box (Z) of the part.
']
Dim drawingDoc As DrawingDocument = ThisApplication.ActiveDocument
' Loop through each sheet in the drawing document
For Each sheet As Sheet In drawingDoc.Sheets
' Loop through each view on the sheet
For Each view As DrawingView In Sheet.DrawingViews
If View.name = "VIEW1" Then
' Check if the view is an assembly view
' Get the assembly document for the view
Dim asmDoc As AssemblyDocument = View.ReferencedDocumentDescriptor.ReferencedDocument
' [Loop through each assembly component
For Each comp As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences
Dim Component = comp.Name
Dim SearchWalls As String = "Wall"
If Component.Contains(FindWalls) = True Then
' Add a dimension to the component if the component name contains "Wall".
Dim ShGeneral = ThisDrawing.Sheets.ItemByName("General:1") 'Name of the sheet.
Dim genDims = ShGeneral.DrawingDimensions.GeneralDimensions
Dim VIEW1 = ShGeneral.DrawingViews.ItemByName("VIEW1") 'General view
Dim WPl_Wall_FlangeLeft = VIEW1.GetIntent(comp.Name, "WPl_Wall-FlangeLeft")
Dim WPl_Wall_FlangeRight = VIEW1.GetIntent(comp.Name, "WPl_Wall-FlangeRight")
' Get the active drawing document
' Get the coordinates of the occurrence.
Dim oMatrix As Matrix = comp.Transformation
Dim x As Double = oMatrix.Cell(1, 4)
Dim y As Double = oMatrix.Cell(2, 4)
Dim z As Double = oMatrix.Cell(3, 4)
''[Find the way to put the dimension depending on where the coordinate is
''[Declare variables for the dimension position
Dim dimX As Double = 0
Dim dimY As Double = 0
' Set the position of the dimension depending on the coordinates (I don't know yet how it should work)
If x < 0 Then
dimX = 1
Else If x > 0
dimX = 0
End If
If y < 0 Then
dimY = 1
Else If y > 0 Then
dimY = 0
End If
']
MessageBox.Show("The occurrence is at position X=" & x & vbCrLf & ", Y=" & y & vbCrLf &", Z=" & z)
Dim linDim1 = genDims.AddLinear("Width_" & Component, VIEW1.SheetPoint(dimX, dimY), WPl_Wall_FlangeLeft, WPl_Wall_FlangeRight)
End If
Next
End If
Next
Next