Hi @gerrardhickson. As you have noticed, there are several possible 'types' of Centermarks (Link1, Link2), making the task of figuring out which view it is associated with a much more complicated that it seems like it should be. I now have a custom function for this task, which combines the method shown in my code above, with the idea of the Centermark's position on the sheet being within the bounds of a view. That position tactic doesn't work well with dimensions, because they can be positioned outside of the bounds of a view, but Centermarks can not be (as far as I know). However, there is still the possibility of 2 or more views having overlapping boundaries, so this technique is still not 100% accurate. I very rarely have view boundaries overlapping each other though, so it's not really a big issue for me. Below is an example of its use:
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oCMs As Centermarks = oSheet.Centermarks
If oCMs.Count = 0 Then Exit Sub
Dim oDict As New Dictionary(Of Inventor.DrawingView, List(Of Inventor.Centermark))
For Each oCM As Centermark In oCMs
Dim oView As DrawingView = GetCentermarkParentView(oCM)
If oView Is Nothing Then Continue For
If oDict.Keys.Contains(oView) Then
oDict.Item(oView).Add(oCM)
Else
oDict.Add(oView, New List(Of Inventor.Centermark) From {oCM})
End If
Next 'oCM
If oDict.Count > 0 Then
For Each oEntry In oDict
MsgBox("View Name = " & oEntry.Key.Name & vbCrLf & _
"Centermarks Count = " & oEntry.Value.Count)
Next 'oEntry
End If
End Sub
Function GetCentermarkParentView(oCM As Centermark) As DrawingView
If oCM.Attached Then
Dim oEnt As Object = oCM.AttachedEntity
If TypeOf oEnt Is GeometryIntent Then
Dim oGI As GeometryIntent = oEnt
If oGI.Geometry IsNot Nothing AndAlso _
TypeOf oGI.Geometry Is DrawingCurve Then
Dim oDC As DrawingCurve = oGI.Geometry
Return oDC.Parent
End If
ElseIf TypeOf oEnt Is DrawingCurve Then
Dim oDC As DrawingCurve = oEnt
Return oDC.Parent
End If
End If
Dim oSheet As Inventor.Sheet = oCM.Parent
Dim oViews As DrawingViews = oSheet.DrawingViews
Dim oP2D As Point2d = oCM.Position
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
For Each oView As DrawingView In oViews
Dim oBox2D As Box2d = oTG.CreateBox2d
oBox2D.MinPoint = oTG.CreatePoint2d(oView.Left, (oView.Top - oView.Height))
oBox2D.MaxPoint = oTG.CreatePoint2d((oView.Left + oView.Width), oView.Top)
If oBox2D.Contains(oP2D) Then Return oView
Next
Return Nothing
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)