Update - I have managed to place the Origin point now and it fixes to the correct location, and I have continued to now add ordinates to the view, It will iterate through each line on the form sketch of the part creating an ordinate dimension at the start and end point of each line in its respected direction, dependant on the line/curve orientation. However when I attempt to define the geometry Intent "oDimIntent1" and "oDimIntent2" it fails to define the intent and exits the code (between the debug message boxes "Test1" and "Test2", I believe it is due to me calling my sketch Line SkLine and it not being an entity name but the entity itself, see code below.
Sub Main()
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim drw As DrawingDocument = ThisDoc.Document
Dim activeSheet As Sheet = drw.ActiveSheet
For Each drwView As DrawingView In activeSheet.DrawingViews
Try
oSheet = ThisDrawing.ActiveSheet
If IsNothing(drwView) Then
Exit Sub
End If
'Set Model View to standard - Unshaded - Hidden Line Removed
drwView.ViewStyle = kHiddenLineRemovedDrawingViewStyle
'Get Model Form Sketch
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisDoc.Document
Dim oPart As Document
oPart = drwView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oPartDef As PartComponentDefinition
oPartDef = oPart.ComponentDefinition
Dim oSketch As PlanarSketch
'Include Formsketch on drawing View
Dim oFormSketch As PlanarSketch = oPartDef.Sketches.Item("Form Sketch")
drwView.SetIncludeStatus(oFormSketch, True)
drwView.SetVisibility(oFormSketch, True)
'Set View to Pull Intents from model for ordination
oViewName = drwView.Name
oView = ThisDrawing.ActiveSheet.View(oViewName)
'Create Origin Indicator if one does not exist
If drwView.HasOriginIndicator = False Then
'Run Create Ordinate Origin Indicator Subroutine
Create_Origin_Indicator(oView, drwView)
End If
'Add Ordinate Dims
Try
'Create a X-Axis Vector to check for Horizontal Lines
Dim oXAxis As Vector2d
oXAxis = ThisApplication.TransientGeometry.CreateVector2d(1, 0)
'Create a Y-Axis Vector to check for Vertical Lines
Dim oYAxis As Vector2d
oYAxis = ThisApplication.TransientGeometry.CreateVector2d(0, 1)
'Create Text Origin For Text placement of Ord Dim
Dim oTextOrigin1 As Point2d
Dim oTextOrigin2 As Point2d
'Dim Type Variable For Horizontal or Vertical Dependant on Line Direction
Dim DimType As DimensionTypeEnum
'Iterate all sketch entity to check for Lines
For Each SkLine As SketchLine In oFormSketch.SketchLines
Dim StartPoint As Point2d = SkLine.StartSketchPoint.Geometry
Dim EndPoint As Point2d = SkLine.EndSketchPoint.Geometry
'Create Curve Vectors for Line to check if parallel
Dim oCurveVector As Vector2d
oCurveVector = StartPoint.VectorTo(EndPoint)
If oCurveVector.IsParallelTo(oXAxis) Then
MsgBox("Test")
'Set Dim Direction
DimType = DimensionTypeEnum.kVerticalDimensionType
MsgBox("Test 1")
Dim oDimIntent1 As GeometryIntent = oView.GetIntent(SkLine, PointIntentEnum.kStartPointIntent)
Dim oDimIntent2 As GeometryIntent = oView.GetIntent(SkLine, PointIntentEnum.kEndPointIntent)
MsgBox("Test 2")
'Set the Text Points for the 2 Dimensions
oTextOrigin1 = ThisApplication.TransientGeometry.CreatePoint2d(SkLine.StartSketchPoint.X, oView.Top + 5)
oTextOrigin2 = ThisApplication.TransientGeometry.CreatePoint2d(SkLine.EndSketchPoint.X, oView.Top + 5)
'Create First Ordinate Dimension
drwView.OrdinateDimensions.Add(oDimIntent1, oTextOrigin1, DimType)
'Create Second Ordinate Dimension
drwView.OrdinateDimensions.Add(oDimIntent2, oTextOrigin2, DimType)
MsgBox("Parallel to X")
Else If oCurveVector.IsParallelTo(oYAxis) Then
'Set Dim Direction
DimType = kHorizontalDimensionType
MsgBox("Test3")
'Set Dim Direction
DimType = kVerticalDimensionType
MsgBox("Test 4")
Dim oDimIntent1 As GeometryIntent = oView.GetIntent(SkLine, kStartPointIntent)
Dim oDimIntent2 As GeometryIntent = oView.GetIntent(SkLine, kEndPointIntent)
MsgBox("Test 5")
'Set the Text Points for the 2 Dimensions
oTextOrigin1 = ThisApplication.TransientGeometry.CreatePoint2d(SkLine.StartSketchPoint.X, oView.Top + 5)
oTextOrigin2 = ThisApplication.TransientGeometry.CreatePoint2d(SkLine.EndSketchPoint.X, oView.Top + 5)
'Create First Ordinate Dimension
drwView.OrdinateDimensions.Add(oDimIntent1, oTextOrigin1, DimType)
'Create Second Ordinate Dimension
drwView.OrdinateDimensions.Add(oDimIntent2, oTextOrigin2, DimType)
MsgBox("Parallel to Y")
Else
MsgBox("Parallel to none")
End If
'Debug Coords
' Format the start point coordinates as a string
' Dim startPointString As String = "Start Point: (" & StartPoint.X.ToString() & ", " & StartPoint.Y.ToString() & ")"
' ' Format the end point coordinates as a string
' Dim endPointString As String = "End Point: (" & EndPoint.X.ToString() & ", " & EndPoint.Y.ToString() & ")"
' ' Display the start point in a message box
' MsgBox(startPointString)
' ' Display the end point in a message box
' MsgBox(endPointString)
Next
Catch
End Try
Catch
End Try
Next
End If
End Sub
'Set Ordinate Origin Subroutine
Sub Create_Origin_Indicator(oView, drwView)
'Set Intent for ordinate origin
Dim Ord_Origin_Intent As GeometryIntent = oView.GetIntent("Corner 3")
'Create Ordinate Origin
drwView.CreateOriginIndicator(Ord_Origin_Intent)
End Sub
I ran an excerpt of the code with a try seen below with the exit message of "operation is not valid due to the current state of the object"