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