Hi @A.Acheson
Using your testfiles, when you get the curves of the face with a hole in it, the circle curve representing the hole is also in that collection. In this case, that curve is in the first position so the reason the code crashes there is that you're getting a circle curve as curve1 and a circle curve doesn't have a start point.
See my comments in the code:
Sub Main
Dim curve As DrawingCurve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a drawing segment").Parent
modelGeom = curve.ModelGeometry
Dim occ As ComponentOccurrence = modelGeom.ContainingOccurrence
Dim drawView As DrawingView = curve.Parent
Dim drawSheet As Sheet = drawView.Parent
MessageBox.Show(occ.Name, "Title")
Dim curve1 As DrawingCurve = Nothing
Dim curve2 As DrawingCurve = Nothing
curve1 = GetCurve("Face0", occ, drawView)
'this will tell you the curve type:
MsgBox([Enum].GetName(GetType(Inventor.CurveTypeEnum), curve1.CurveType))
'curve1 is the circle curve, doesn't have a StartPoint.
'It does however have a center point:
MsgBox("curve1 center point" & vbCrLf & curve1.CenterPoint.X & ";" & curve1.CenterPoint.Y)
'curve2 doesn't work because theres no entity named "Face1"
curve2 = GetCurve("Face1", occ, drawView)
'therefore its nothing:
If curve2 Is Nothing Then MsgBox("curve2 is nothing")
' 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
End Sub
Function GetCurve(faceName As String, occ As ComponentOccurrence, drawView As DrawingView) As DrawingCurve
Dim doc As PartDocument = occ.Definition.Document
Dim drawViewCurves As DrawingCurvesEnumerator
Dim partFaceProxy As FaceProxy
Dim namedEntities As NamedEntities
namedEntities = iLogicVb.Automation.GetNamedEntities(doc)
Try
namedFace = namedEntities.FindEntity(faceName)
Catch
Logger.Info("Error getting face entity")
End Try
For Each partFace As Face In doc.ComponentDefinition.SurfaceBodies(1).Faces
If partFace Is namedFace Then
MessageBox.Show("Found Face", "Title")
Try
If occ.HasBodyOverride
For Each oSurfBod As SurfaceBody In occ.SurfaceBodies
For Each oFace As Face In oSurfBod.Faces
If oFace.GetSourceFace Is namedFace Then partFaceProxy = oFace
Exit For
Next
If partFaceProxy IsNot Nothing Then Exit For
Next
Else
occ.CreateGeometryProxy(namedFace, partFaceProxy)
End If
drawViewCurves = drawView.DrawingCurves(partFaceProxy)
Logger.Info("Drawcurvecount: " & drawViewCurves.Count)
Return drawViewCurves(1)
Catch
Logger.Info("Error curve count")
End Try
End If
Next
End Function
I don't know your exact intentions with this code, but I'd suggest filtering out the curves based on type, direction etc. depending on your intentions.
Here's an example filtering out the horizontal lines and setting the dimension between them:
Sub Main
Dim curve As DrawingCurve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a drawing segment").Parent
modelGeom = curve.ModelGeometry
Dim occ As ComponentOccurrence = modelGeom.ContainingOccurrence
Dim drawView As DrawingView = curve.Parent
Dim drawSheet As Sheet = drawView.Parent
MessageBox.Show(occ.Name, "Title")
Dim curve1 As DrawingCurve = Nothing
Dim curve2 As DrawingCurve = Nothing
Dim horizontalLines As List(Of DrawingCurve) = GetHorizontalLines("Face0", occ, drawView)
curve1 = horizontalLines(0)
curve2 = horizontalLines(1)
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
End Sub
Function GetHorizontalLines(faceName As String, occ As ComponentOccurrence, drawView As DrawingView) As List(Of DrawingCurve)
Dim doc As PartDocument = occ.Definition.Document
Dim drawViewCurves As DrawingCurvesEnumerator
Dim partFaceProxy As FaceProxy
Dim namedEntities As NamedEntities
namedEntities = iLogicVb.Automation.GetNamedEntities(doc)
Try
namedFace = namedEntities.FindEntity(faceName)
Catch
Logger.Info("Error getting face entity")
End Try
For Each partFace As Face In doc.ComponentDefinition.SurfaceBodies(1).Faces
If partFace Is namedFace Then
MessageBox.Show("Found Face", "Title")
Try
If occ.HasBodyOverride
For Each oSurfBod As SurfaceBody In occ.SurfaceBodies
For Each oFace As Face In oSurfBod.Faces
If oFace.GetSourceFace Is namedFace Then partFaceProxy = oFace
Exit For
Next
If partFaceProxy IsNot Nothing Then Exit For
Next
Else
occ.CreateGeometryProxy(namedFace, partFaceProxy)
End If
drawViewCurves = drawView.DrawingCurves(partFaceProxy)
Return drawViewCurves.OfType(Of DrawingCurve).Where(Function(x As DrawingCurve) x.CurveType = CurveTypeEnum.kLineSegmentCurve AndAlso x.StartPoint.Y = x.EndPoint.Y).ToList()
Catch
Logger.Info("Error curve count")
End Try
End If
Next
End Function