Adding Basic Dims Automatically

Adding Basic Dims Automatically

NachoShaw
Advisor Advisor
666 Views
5 Replies
Message 1 of 6

Adding Basic Dims Automatically

NachoShaw
Advisor
Advisor

Hey

 

Is there any code about to automatically add dims to drawing views? nothing too complicated, just need the X, Y (widest, tallest) dims. I am creating views automatically and would like to add the painstaking process to the end of it, i must have done about 500 of these today.....

 

DIMS.png

 

 

cheers

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
667 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Is there a possibility that you use parameters instead of dimensions, like in the picture?Dimension.PNG

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 6

NachoShaw
Advisor
Advisor

Hi

 

i had thought of that. In fact, i have written code to pretty much guarantee i can get the X,Y,Z of the part. not all parts are parameter driven they are part driven (created with the coexistence of other parts).

 

Unfortunately we have to show the dimension as a dimension edge to edge otherwise there may be ambiguity to the size and we can become responsible for anomolies / incorrect dims

 

 

cheers

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 4 of 6

bshbsh
Collaborator
Collaborator

weird, there was a similar question not long ago. 

 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Here a bit of code that retrieve the standard dimensions from all the views in the drawing. (the same function as annotate--> retreive model annotations)

also it looks at where the dimension is and places it accordingly.

If you have a lot of dimensions in all the sketches it wil also import these in the drawing.

Also, one downside to this function is that it cannot place dimensions in view 2 that are already in view 1....

 

Function RetreiveAnnotations(ByRef oBaseView As DrawingView, ByRef oView2 As DrawingView, ByRef oView3 As DrawingView, ByRef oView4 As DrawingView)
'function that retrieve dimensions from all views
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

Dim oDrawView As DrawingView 
For Each oDrawView In oSheet.DrawingViews
	Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
	On Error Resume Next
	oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)
	
Next

'next the location of every dimension is checked, and moved to the side of the view.
Dim dimension As GeneralDimension
Dim C1R As Integer = 0
Dim C1L As Integer = 0
Dim C1U As Integer = 0
Dim C1D As Integer = 0
Dim C2R As Integer = 0
Dim C2L As Integer = 0
Dim C2U As Integer = 0
Dim C2D As Integer = 0
Dim C3R As Integer = 0
Dim C3L As Integer = 0
Dim C3U As Integer = 0
Dim C3D As Integer = 0

		
	For Each dimension In oSheet.DrawingDimensions  
	
	Dim dimy As Double = dimension.DimensionLine.midpoint.y
	Dim dimx As Double = dimension.DimensionLine.midpoint.x
	Dim tx As Double = dimension.Text.Origin.X
	Dim ty As Double = dimension.Text.Origin.Y
	
		If dimension.Type = kLinearGeneralDimensionObject Then
				If dimension.DimensionLine.direction.x = 0 Then
					'look at wich view the dimension is attached
					If dimy > oBaseView.Position.Y + (0.5 * oBaseView.Height) Then
						
						If dimx > oView2.Position.X + (0.5 * oView2.Width) + 1 Then
							'dimension connected to view4
						Else
							'dimension connected to view2
							If tx > oView2.Center.X Then
								C2R = C2R + 1
								MoveRight(oView2,dimension,C2R)
							ElseIf tx < oView2.Center.X Then
								C2L = C2L + 1
								MoveLeft(oView2,dimension,C2L)
							End If
						End If
					
					Else
						If dimx > oBaseView.Position.X + (0.5 * oBaseView.Width) + 1 Then
							'dimension connected to view3
							If tx > oView3.Center.X Then
								C3R = C3R + 1
								MoveRight(oView3,dimension,C3R)
							ElseIf tx < oView3.Center.X Then
								C3L = C3L + 1
								MoveLeft(oView3,dimension, C3L)
							End If
						Else
							'dimension connected to baseview
							If tx > oBaseView.Center.X Then
								C1R = C1R + 1
								MoveRight(oBaseView, dimension, C1R)
							ElseIf tx < oBaseView.Center.X Then
								C1L = C1L + 1
								MoveLeft(oBaseView,dimension, C1L)
							End If
						End If
					End If
			
			ElseIf dimension.DimensionLine.direction.y = 0 Then
					'look at wich view the dimension is attached
					If dimx > oBaseView.Position.X + (0.5 * oBaseView.Width) Then
						If dimy > oView3.Position.Y + (0.5 * oView3.Height) + 1 Then
							'dimension connected to view4
						Else
							'dimension connected to view3
							If ty > oView3.Center.Y Then
								C3U = C3U + 1
								MoveUp(oView3, dimension, C3U)
							ElseIf ty < oView3.Center.Y Then
								C3D = C3D + 1
								MoveDown(oView3, dimension, C3D)
							End If
						End If
					
					Else
						If dimy > oBaseView.Position.Y + (0.5 * oBaseView.Height) + 1 Then
							'dimension connected to view2
							If ty > oView2.Center.Y Then
								C2U = C2U + 1
								MoveUp(oView2, dimension, C2U)
							ElseIf ty < oView2.Center.Y Then
								C2D = C2D + 1
								MoveDown(oView2, dimension, C2D)
							End If
						Else
							'dimension connected to baseview
							If ty > oBaseView.Center.Y Then
								C1U = C1U + 1
								MoveUp(oBaseView, dimension , C1U)
							ElseIf ty < oBaseView.Center.Y Then
								C1D = C1D + 1
								MoveDown(oBaseView, dimension, C1D)
							End If
						End If
					End If	
			Else
				'dimension not horizontal or vertical, is not moved
			End If
			
		ElseIf dimension.Type = kDiameterGeneralDimensionObject Then
'				'look at wich view the dimension is attached
'				If dimy > oBaseView.Position.Y + (0.5 * oBaseView.Height) + 1 Then
'					If dimx > oView2.Position.X + (0.5 * oView2.Width) + 1 Then
'						Trace.WriteLine("dimension connected to view4")
'						Trace.WriteLine(dimension.ModelValue)
'					Else
'						Trace.WriteLine("dimension connected to view2")
'						Trace.WriteLine(dimension.ModelValue)
'					End If
				
'				Else
'					If dimx > oBaseView.Position.X + (0.5 * oBaseView.Width) + 1 Then
'						Trace.WriteLine("dimension connected to view3")
'						Trace.WriteLine(dimension.ModelValue)
'					Else
'						Trace.WriteLine("dimension connected to baseview")
'						Trace.WriteLine(dimension.ModelValue)
'					End If
'				End If			
'this piece is not used, because the diameter dimensions are not moved.					
		
		End If
	Next
End Function

Function MoveLeft(oView As DrawingView, dimension As DrawingDimension, Counter As Integer) '4 functions to move a dimension
Dim oTg = ThisApplication.TransientGeometry
Dim newX As Double
Dim newY As Double
Dim textHeight = 0.5
Dim deltaX As Double = (oView.Width * 0.5) + (0.6 * Counter)
            
newX = oView.Center.X - deltaX - textHeight
newY = dimension.Text.Origin.Y

dimension.Text.Origin = oTg.createpoint2d(newX,newY)

End Function

Function MoveRight(oView As DrawingView, dimension As DrawingDimension, Counter As Integer)
Dim oTg = ThisApplication.TransientGeometry
Dim newX As Double
Dim newY As Double
Dim deltaX As Double = (oView.Width * 0.5) + (0.6 * Counter)

newX = oView.Center.X + deltaX
newY = dimension.Text.Origin.Y

dimension.Text.Origin = oTg.Createpoint2d(newX,newY)

End Function

Function MoveUp(oView As DrawingView, dimension As DrawingDimension, Counter As Integer)
Dim oTg = ThisApplication.TransientGeometry
Dim newX As Double
Dim newY As Double
Dim texthieght = 0.5
Dim deltaY As Double = (oView.Height * 0.5) + (0.6 * Counter)

newX = dimension.Text.Origin.X
newY = oView.Center.Y + deltaY + textHeight

dimension.Text.Origin = oTg.createpoint2d(newX,newY)

End Function

Function MoveDown(oView As DrawingView, dimension As DrawingDimension, Counter As Integer)
Dim oTg = ThisApplication.TransientGeometry
Dim newX As Double
Dim newY As Double
Dim deltaY As Double = (oView.Height * 0.5) + (0.6 * Counter)

newX = dimension.Text.Origin.X
newY = oView.Center.Y - deltaY

dimension.Text.Origin = oTg.createpoint2d(newX,newY)

End Function

 with credits to @Anonymous  who gave a lot of insparation on automated drawings in the following topic.

https://forums.autodesk.com/t5/inventor-customization/ilogic-coding-to-create-automated-drawing/m-p/3412839#M38159

0 Likes
Message 6 of 6

JelteDeJong
Mentor
Mentor

hi, i created this rule. it only does not work when the most outer curve (line) is not a line or a (part of a) circle, but probally you are not using lines like splines that much.

 

Sub Main()
    Dim doc As DrawingDocument = ThisApplication.ActiveDocument
    For Each sheet As Sheet In doc.Sheets
        For Each View As DrawingView In sheet.DrawingViews

            Dim minCurveX As DrawingCurve = Nothing
            Dim minX As Double = 9999999999999
            Dim maxCurveX As DrawingCurve = Nothing
            Dim maxX As Double = -9999999999999

            Dim minCurveY As DrawingCurve = Nothing
            Dim minY As Double = 9999999999999
            Dim maxCurveY As DrawingCurve = Nothing
            Dim maxY As Double = -9999999999999

            For Each curve As DrawingCurve In View.DrawingCurves
                Dim geoType = curve.Segments.Item(1).GeometryType
                If (geoType <> Curve2dTypeEnum.kLineSegmentCurve2d And
                    geoType <> Curve2dTypeEnum.kCircleCurve2d) Then
                    ' I will will only search for curves that can be used for a dimension.
                    Continue For
                End If

                Dim curMinX = curve.Evaluator2D.RangeBox.MinPoint.X
                If (curMinX < minX) Then
                    minCurveX = curve
                    minX = curMinX
                End If
                Dim curMaxX = curve.Evaluator2D.RangeBox.MaxPoint.X
                If (maxX < curMaxX) Then
                    maxCurveX = curve
                    maxX = curMaxX
                End If

                Dim curMinY = curve.Evaluator2D.RangeBox.MinPoint.Y
                If (curMinY < minY) Then
                    minCurveY = curve
                    minY = curMinY
                End If
                Dim curMaxY = curve.Evaluator2D.RangeBox.MaxPoint.Y
                If (maxY < curMaxY) Then
                    maxCurveY = curve
                    maxY = curMaxY
                End If
            Next

            Dim intLeft = getMostLeftIntent(sheet, minCurveX)
            Dim intRight = getMostRightIntent(sheet, maxCurveX)
            Dim intBottom = getMostBottomIntent(sheet, minCurveY)
            Dim intTop = getMostTopIntent(sheet, maxCurveY)

            If (intLeft IsNot Nothing And intRight IsNot Nothing) Then
                Dim txtPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(
                    View.Position.X,
                    View.Position.Y + View.Height / 2 + 1)
                sheet.DrawingDimensions.GeneralDimensions.AddLinear(
                    txtPoint,
                    intLeft,
                    intRight,
                    DimensionTypeEnum.kHorizontalDimensionType)
            End If

            If (intBottom IsNot Nothing And intTop IsNot Nothing) Then
                Dim txtPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(
                    View.Position.X - View.Width / 2 - 1,
                    View.Position.Y)
                sheet.DrawingDimensions.GeneralDimensions.AddLinear(
                    txtPoint,
                    intBottom,
                    intTop,
                    DimensionTypeEnum.kVerticalDimensionType)
            End If
        Next
    Next
	
End Sub

Public Function getMostLeftIntent(sheet As Sheet, curve As DrawingCurve) As GeometryIntent
    Dim geoType = curve.Segments.Item(1).GeometryType
    Dim returnValue As GeometryIntent = Nothing
    If (geoType = Curve2dTypeEnum.kLineSegmentCurve2d) Then
        Dim startInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kStartPointIntent)
        Dim endInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kEndPointIntent)
        returnValue = If(startInt.PointOnSheet.X < endInt.PointOnSheet.X, startInt, endInt)
    ElseIf (geoType = Curve2dTypeEnum.kCircleCurve2d) Then
        returnValue = sheet.CreateGeometryIntent(curve, PointIntentEnum.kCircularLeftPointIntent)
    End If
    Return returnValue
End Function
Public Function getMostRightIntent(sheet As Sheet, curve As DrawingCurve) As GeometryIntent
    Dim geoType = curve.Segments.Item(1).GeometryType
    Dim returnValue As GeometryIntent = Nothing
    If (geoType = Curve2dTypeEnum.kLineSegmentCurve2d) Then
        Dim startInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kStartPointIntent)
        Dim endInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kEndPointIntent)
        returnValue = If(startInt.PointOnSheet.X > endInt.PointOnSheet.X, startInt, endInt)
    ElseIf (geoType = Curve2dTypeEnum.kCircleCurve2d) Then
        returnValue = sheet.CreateGeometryIntent(curve, PointIntentEnum.kCircularRightPointIntent)
    End If
    Return returnValue
End Function
Public Function getMostTopIntent(sheet As Sheet, curve As DrawingCurve) As GeometryIntent
    Dim geoType = curve.Segments.Item(1).GeometryType
    Dim returnValue As GeometryIntent = Nothing
    If (geoType = Curve2dTypeEnum.kLineSegmentCurve2d) Then
        Dim startInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kStartPointIntent)
        Dim endInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kEndPointIntent)
        returnValue = If(startInt.PointOnSheet.Y > endInt.PointOnSheet.Y, startInt, endInt)
    ElseIf (geoType = Curve2dTypeEnum.kCircleCurve2d) Then
        returnValue = sheet.CreateGeometryIntent(curve, PointIntentEnum.kCircularTopPointIntent)
    End If
    Return returnValue
End Function
Public Function getMostBottomIntent(sheet As Sheet, curve As DrawingCurve) As GeometryIntent
    Dim geoType = curve.Segments.Item(1).GeometryType
    Dim returnValue As GeometryIntent = Nothing
    If (geoType = Curve2dTypeEnum.kLineSegmentCurve2d) Then
        Dim startInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kStartPointIntent)
        Dim endInt As GeometryIntent = sheet.CreateGeometryIntent(curve, PointIntentEnum.kEndPointIntent)
        returnValue = If(startInt.PointOnSheet.Y < endInt.PointOnSheet.Y, startInt, endInt)
    ElseIf (geoType = Curve2dTypeEnum.kCircleCurve2d) Then
        returnValue = sheet.CreateGeometryIntent(curve, PointIntentEnum.kCircularBottomPointIntent)
    End If
    Return returnValue
End Function

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.

EESignature


Blog: hjalte.nl - github.com