Hello
You can create general dimension as shown below. But be aware, the creation is the most less problem of all. There are a lot of open questions. It's quite simple for a user to decide if a dimension is needed, where to place and many more, but not for a program. Even such a primitive thing like which side to offset dimension and how far away and to avoid colliding an existing dimension.
It could be more work to sort the automatic inserted dimensions and delete unused, doubled and so on, than let user insert himself.
Option Explicit
Private Sub CreateDimension()
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = oApp.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
Dim oView As DrawingView
Set oView = oSheet.DrawingViews.Item(1)
Dim oDimension As GeneralDimension
Dim oIntent As GeometryIntent
Dim oPoint As Point2d
Dim oTrans As Transaction
Set oTrans = oApp.TransactionManager.StartTransaction(oDrawDoc, "CreateDimensions")
Dim oDrawCurve As DrawingCurve
For Each oDrawCurve In oView.DrawingCurves
Select Case oDrawCurve.CurveType
Case kLineCurve:
Set oIntent = oSheet.CreateGeometryIntent(oDrawCurve)
Set oPoint = oApp.TransientGeometry.CreatePoint2d(oDrawCurve.MidPoint.x + 1, oDrawCurve.MidPoint.y + 1)
Set oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPoint, oIntent, , kAlignedDimensionType, True)
Case kLineSegmentCurve:
Set oIntent = oSheet.CreateGeometryIntent(oDrawCurve)
Set oPoint = oApp.TransientGeometry.CreatePoint2d(oDrawCurve.MidPoint.x + 1, oDrawCurve.MidPoint.y + 1)
Set oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPoint, oIntent, , kAlignedDimensionType, True)
Case kCircleCurve:
Set oIntent = oSheet.CreateGeometryIntent(oDrawCurve)
Set oPoint = oApp.TransientGeometry.CreatePoint2d(oDrawCurve.centerPoint.x + 2, oDrawCurve.centerPoint.y + 2)
Set oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddDiameter(oPoint, oIntent, , False, True)
Case kCircularArcCurve:
Set oIntent = oSheet.CreateGeometryIntent(oDrawCurve)
Set oPoint = oApp.TransientGeometry.CreatePoint2d(oDrawCurve.centerPoint.x + 2, oDrawCurve.centerPoint.y + 2)
Set oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddDiameter(oPoint, oIntent, , False, True)
End Select
Next
oTrans.End
End Sub
R. Krieg
RKW Solutions
www.rkw-solutions.com