Maybe I don't fully understand your situation then. Obviously, if you don't have the hidden lines shown, it won't be able to put a centerline through the side view of a hole, because there will be no straight hole profile geometry being shown to bisect with a centerline. But why would you want to have centerlines shown through the side views of holes, if you don't intend to leave the hidden lines of those holes shown in the view shown after the fact?
The code I posted works for me, no matter which way I have the view style set (Hidden Line, Hidden Line Removed, or Shaded). Any holes that are 'visible' in any of the views are getting the expected centermarks. And if any of my views are set to show hidden lines, it will put the centerlinens through the side views of its holes, as expected. And my code is effecting all the straight views on my page (front, right, top) without effecting my ISO view.
I attempted to create a new smarter code to do what you seem to be trying to do, even though I may not understand why. This code lets you manually select a view to apply the code to, and loops at the end to allow you to select another view to do it to, if you want to continue to do multiple views. This code also attempts to change the view's style to show hidden lines before attempting to set the automated cemtermarks & centerlines, like you are currently trying to achieve, then attempts to set the view back to the view style it was originally when done. I also incorporated some code to delete all existing centermarks & centerlines within the selected view, before creating the new ones. In order to only target the centermarks & centerlines in the selected view, I created a few custom Functions which are used to make sure they are within the bounds of the selected view.
While I was creating this alternate code to suit your 'unique' needs, I came across an odd situation. This situation may be part of why your code isn't working too. I found that if I place a MsgBox() after where I'm changing the view's style, but before it uses the SetAutomatedCenterlineSettings, it will work as expected. But if I don't include that MsgBox() it won't work. I've tried many other alternatives in place of that MsgBox, in an attempt to simulate whatever effect it is having, but none of the alternatives I've tried so far seem to work. I've tried oSheet.Update, UserInterfaceManager.DoEvents, ActiveView.Update, Thread.Sleep(1000), oDDoc.Update2(True), but none of those work like the using the MsgBox does.
Here's the iLogic code I've got right now:
Sub Main
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oView As DrawingView
Repeat :
'this will help bundle all actions into one item in your UNDO list
Dim oTrans As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "Set View's Automated Centerlines")
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view to apply centerlines to.")
If oView Is Nothing Then Exit Sub
'record view's 'original' view style, so we can restore it later
Dim oOrigStyle As DrawingViewStyleEnum = oView.ViewStyle
'make sure it is set to show hidden lines
If oOrigStyle <> DrawingViewStyleEnum.kHiddenLineDrawingViewStyle Then
oView.ViewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
MsgBox("Changed view style to show hidden lines.", , "")
'none of the following methods allow the code to work, but the MsgBox above does:
'oSheet.Update
'ThisApplication.UserInterfaceManager.DoEvents
'ThisApplication.ActiveView.Update
'System.Threading.Thread.Sleep(1000)
'oDDoc.Update2(True)
End If
'delete old centermarks within this view
For Each oCM As Centermark In oSheet.Centermarks
If Not oCM.Attached Then oCM.Delete
If CMIsWithinView(oCM, oView) Then oCM.Delete
Next
'delete old centerlines within this view
For Each oCL As Centerline In oSheet.Centerlines
If Not oCL.Attached Then oCL.Delete
If CLIsWithinView(oCL, oView) Then oCL.Delete
Next
'create the new centermarks & centerlines
oView.SetAutomatedCenterlineSettings
'make sure view style is back to original
If oView.ViewStyle <> oOrigStyle Then
oView.ViewStyle = oOrigStyle
End If
oSheet.Update
oTrans.End 'ends the Transaction (for UNDO menu)
'create a repeatable process by asking if you want to do it again
If MsgBox("Done. Do it again?", vbYesNo + vbQuestion, "AGAIN?") = vbYes Then GoTo Repeat
End Sub
Function ViewBounds(oDView As DrawingView) As Box2d
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oBox2d As Box2d = oTG.CreateBox2d
oBox2d.MinPoint = oTG.CreatePoint2d(oDView.Left, (oDView.Top - oDView.Height))
oBox2d.MaxPoint = oTG.CreatePoint2d((oDView.Left + oDView.Width), oDView.Top)
Return oBox2d
End Function
Function CMIsWithinView(oCMk As Centermark, oDView As DrawingView) As Boolean
Dim oPt As Point2d = oCMk.Position
Dim oBox2d As Box2d = ViewBounds(oDView)
If oBox2d.Contains(oPt) Then
Return True
Else
Return False
End If
End Function
Function CLIsWithinView(oCLn As Centerline, oDView As DrawingView) As Boolean
Dim oPt As Point2d = oCLn.StartPoint
Dim oBox2d As Box2d = ViewBounds(oDView)
If oBox2d.Contains(oPt) Then
Return True
Else
Return False
End If
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) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)