Well, I did run into an interesting situation when creating this. For some reason, this local rule in the drawing wasn't finding any 'iFeature' objects in the model, even though I used the 'Punch Tool' in the Sheet Metal tools of the model to create the feature, and the feature was named "iFeature1:1". I later remembered that those PunchTools are a bit harder to find, because you first have to define then dig into the 'SheetMetalComponentDefinition' object, then define and dig into the 'SheetMetalFeatures' object below that to find them. So, instead I just specified the feature by its name, which worked for my test at the time.
There are definitely some things that can be done to make this rule more robust. I updated my rule code a bit to help eliminate some potential error prone areas. Now it also loops through all views, and will also add the side profile centerlines, and add centerpoints in the ISO view (although not angled/rotated), but you can easily eliminate that loop to just process a single view if needed. I also added a Transaction in there to help control the length of the Undo list, but it doesn't appear to be working as expected yet.
Here's my updated rule code as it is now:
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbCritical, "iLogic")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDDoc.ActiveSheet
'Dim oView As DrawingView = oDDoc.SelectSet.Item(1)
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "PunchCenterPoints")
For Each oView As DrawingView In oSheet.DrawingViews
AddCentermarksToPunchToolHoles(oView)
Next
oTrans.End
End Sub
Sub AddCentermarksToPunchToolHoles(oDView As DrawingView)
If oDView.ReferencedDocumentDescriptor.ReferencedDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Exit Sub
End If
Dim oPDoc As PartDocument = oDView.ReferencedDocumentDescriptor.ReferencedDocument
If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Exit Sub
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
If oSMFeats.PunchToolFeatures.Count = 0 Then Exit Sub
For Each oPunch As PunchToolFeature In oSMFeats.PunchToolFeatures
Dim oCurves As DrawingCurvesEnumerator
Try
oCurves = oDView.DrawingCurves(oPunch)
Catch
End Try
If IsNothing(oCurves) Then Continue For
If oCurves.Count = 0 Then Continue For
Dim oList As New List(Of Inventor.Centermark)
For Each oDCurve As DrawingCurve In oCurves
oIntent = oDView.Parent.CreateGeometryIntent(oDCurve)
Dim oCM As Centermark
Try
oCM = oDView.Parent.Centermarks.Add(oIntent, True, True)
Catch
Continue For
End Try
If oList.Count = 0 Then
oList.Add(oCM)
Else
Dim oFound As Boolean = False
For Each oCMk As Centermark In oList
If oCMk.Position.IsEqualTo(oCM.Position) Then
oFound = True
oCM.Delete
End If
Next
If Not oFound Then oList.Add(oCM)
End If
Next
Next
End Sub
Wesley Crihfield

(Not an Autodesk Employee)