DIMENSIONS IN A DRAWING

DIMENSIONS IN A DRAWING

anavazquez5LRNJ
Enthusiast Enthusiast
433 Views
4 Replies
Message 1 of 5

DIMENSIONS IN A DRAWING

anavazquez5LRNJ
Enthusiast
Enthusiast

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
0 Likes
434 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

Hi @anavazquez5LRNJ 

Could you share the error messages your receiving, the more info tab indixating the line number and error message.? I see on this line a string variable "Findwalls" not mentioned in preceeding code. 

If Component.Contains(FindWalls) 

 

What is the first line the code is failing? Without your specific model and drawing to test it will be difficult to determine the desired outcome other than to manually review the code and you keep testing on your side. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 5

anavazquez5LRNJ
Enthusiast
Enthusiast

Thank you very much, I have already modified my code, I do not see any error, only that the positions of the dimensions for example at the top are not placed where they should be.

 

0 Likes
Message 4 of 5

anavazquez5LRNJ
Enthusiast
Enthusiast

Here is the modified code and I add the image of the drawing dimensionsthe top dimension is placed down with the bottom dimensionthe top dimension is placed down with the bottom dimension

   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 component1 = comp.Name 
            Dim Walls As String = "Wall"
            If component1.Contains(Walls) = True Then
				
                ' Add a dimension to the component if the component name contains "Wall"
               Dim ShGeneral = ThisDrawing.Sheets.ItemByName("General:1") 
               Dim genDims = ShGeneral.DrawingDimensions.GeneralDimensions
               Dim VIEW1 = ShGeneral.DrawingViews.ItemByName("VIEW1") 'Vista general
			   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

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)


Dim dimX As Double = 0
Dim dimY As Double = 0

' Get the width and height of the view
Dim viewWidth As Double = VIEW1.Width
Dim viewHeight As Double = VIEW1.Height

' Calculate the x position based On the x coordinate Of the Component occurrence
If x < y  Then 
    dimX = 1.02 
	 dimY = 0.9
	 
 Else If x > y Then 
	 dimX = -0.02
	  dimY = -0.02 

End If

  ']        
  
MessageBox.Show(" coordinates of the occurrence X=" & x & vbCrLf & ", Y=" & y & vbCrLf &", Z=" & z)
Dim linDim1 = genDims.AddLinear("Ancho_" & component1, VIEW1.SheetPoint(dimX, dimY), WPl_Wall_FlangeLeft, WPl_Wall_FlangeRight)
          
            End If
        Next
    End If
    Next
   Next

 

 

 

0 Likes
Message 5 of 5

A.Acheson
Mentor
Mentor

Hi @anavazquez5LRNJ 

 

Here is a working code for dimensioning an assembly.  I have used the curve start point for locating the dimension text. Hopefully it will get you moving in the right direction. This post here was helpful for setting up the proxy faces. 

 

Sub Main
	
	Dim drawDoc As DrawingDocument = ThisDoc.Document

	' Loop through each sheet in the drawing document.
	For Each drawSheet As Sheet In drawDoc.Sheets
		
		' Loop through each view on the sheet.
		If Not drawSheet.Name = "General:1" Then Continue For
		
		For Each drawView As DrawingView In drawsheet.DrawingViews
		    If Not drawView.Name = "VIEW1" Then Continue For

		        ' Get the assembly document for the view.
		        Dim asmDoc As AssemblyDocument = drawview.ReferencedDocumentDescriptor.ReferencedDocument

		        ' Loop through each assembly component.
		        For Each occ As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences
		      
		            If Not occ.Name.Contains("Wall") Then Continue For
					
					' Get curve, location of each dimension leg start point.
					Dim curve1 As DrawingCurve = GetCurve("WPl_Wall-FlangeLeft", occ, drawView)
					Dim curve2 As DrawingCurve = GetCurve("WPl_Wall-FlangeRight", occ, drawView)
					
					Dim tg As TransientGeometry = ThisApplication.TransientGeometry
					Dim pt1 As Point2d = tg.CreatePoint2d(curve1.StartPoint.X +2 , curve1.StartPoint.Y)
			
					Dim genDims As GeneralDimensions = drawSheet.DrawingDimensions.GeneralDimensions
					
					Dim dim1 As LinearGeneralDimension = genDims.AddLinear(pt1, drawSheet.CreateGeometryIntent(curve1), drawSheet.CreateGeometryIntent(curve2))
					dim1.CenterText
		
				Next	
			Next
	   Next
End Sub

Function GetCurve(faceName As String, occ As ComponentOccurrence, drawView As DrawingView) As DrawingCurve
   
    	Dim namedEntities = iLogicVb.Automation.GetNamedEntities(occ.Definition.Document)
   
    	Dim partFace As Face = namedEntities.FindEntity(faceName)
	
		' Get Proxy if it occurs in a Assembly.
		Dim partFaceProxy As FaceProxy
		occ.CreateGeometryProxy(partFace, partFaceProxy)

		' Finds the drawing edge that represents the one with the named entity.
		Dim drawViewCurves As DrawingCurvesEnumerator = drawView.DrawingCurves(partFaceProxy)
		Dim drawCurve As DrawingCurve = drawViewCurves.Item(1)
		Return drawCurve
	
End Function

 

 

AAcheson_0-1684010227822.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes