Ilogic automated centerlines doesn't work in 2021

Ilogic automated centerlines doesn't work in 2021

Kassenbouw
Enthusiast Enthusiast
1,401 Views
10 Replies
Message 1 of 11

Ilogic automated centerlines doesn't work in 2021

Kassenbouw
Enthusiast
Enthusiast

Hi guys,

 

I've been using some Ilogic code on my drawnings to trigger the automated centerlines function. This worked fine in Inventor 2019 but doesn't work anymore in Inventor 2021. 

 

This is the Ilogic code:
' toggle hiddenline view on

ActiveSheet.View("VIEW1").View.ViewStyle = kHiddenLineDrawingViewStyle

 

' Automated Centerlines

ActiveSheet.View("VIEW1").View.SetAutomatedCenterlineSettings()

 

' Delete all unattached centerlines

For Each centerLine In ActiveSheet.Sheet.Centerlines

If (Not Centerline.Attached) Then

Centerline.Delete()

End If

Next

 

' toggle hiddenline view off

ActiveSheet.View("VIEW1").View.ViewStyle = kHiddenLineRemovedDrawingViewStyle

 

One of the reasons I'm using this per view and not on the whole drawing it that I dont want centerlines in my isometric view. 

 

I believe the problem is in the toggle hiddenline view on function. When I manually put on hiddenline on and then run the rule this works. 

 

Does anyone have an idea how to make this work again in 2021?

 

Thanks a lot!

 

0 Likes
1,402 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor

I'm using Inventor Pro 2021.2.2 and the SetAutomatedCenterLineSettings() method still works OK for me.  Also I may be able to help you out with the whole (single view at a time vs all views on a sheet at a time) issue.  I have been using similar iLogic rules and VBA macro's for years also, and have further developed the code to avoid any ISO views, for the same reasons.

Here's my external iLogic rule's code:

Dim oDoc As DrawingDocument = ThisDrawing.Document

'make sure settings are the way I want them
Dim oACS As AutomatedCenterlineSettings = oDoc.DrawingSettings.AutomatedCenterlineSettings
oACS.ApplyToBends = False
oACS.ApplyToCircularPatterns = True
oACS.ApplyToCylinders = False
oACS.ApplyToFillets = False
oACS.ApplyToHoles = True
oACS.ApplyToPunches = True
oACS.ApplyToRectangularPatterns = True
oACS.ApplyToRevolutions = False
oACS.ApplyToSketches = False
oACS.ApplyToWorkFeatures = False
'oACS.ArcAngleThreshold = 
'oACS.CircularEdgeMaximumThreshold = 
'oACS.CircularEdgeMinimumThreshold = 
'oACS.FilletRadiusMaximumThreshold = 
'oACS.FilletRadiusMinimumThreshold = 
oACS.ProjectionNormalAxis = True
oACS.ProjectionParallelAxis = True
'oACS.RadiusThresholdPrecision = 

Dim oSheet As Sheet = oDoc.ActiveSheet
For Each oCM As Centermark In oSheet.Centermarks
	oCM.Delete
Next
For Each oCL As Centerline In oSheet.Centerlines
	oCL.Delete
Next

Dim oViewOrient As ViewOrientationTypeEnum
For Each oView As DrawingView In oSheet.DrawingViews
	oViewOrient = oView.Camera.ViewOrientationType
	If oViewOrient <> ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation And _
		oViewOrient <> ViewOrientationTypeEnum.kIsoBottomRightViewOrientation And _
		oViewOrient <> ViewOrientationTypeEnum.kIsoTopLeftViewOrientation And _
		oViewOrient <> ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
		oView.SetAutomatedCenterlineSettings(oACS)
	End If
Next

And here's the code for the VBA macro:

Sub Add_All_Centermarks()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oACS As AutomatedCenterlineSettings
    Set oACS = oDoc.DrawingSettings.AutomatedCenterlineSettings
            
    oACS.ApplyToBends = False
    oACS.ApplyToCircularPatterns = True
    oACS.ApplyToCylinders = True
    oACS.ApplyToFillets = False
    oACS.ApplyToHoles = True
    oACS.ApplyToPunches = True
    oACS.ApplyToRectangularPatterns = True
    oACS.ApplyToRevolutions = False
    oACS.ApplyToSketches = False
    oACS.ApplyToWorkFeatures = False
    'oACS.ArcAngleThreshold =
    'oACS.CircularEdgeMaximumThreshold =
    'oACS.CircularEdgeMinimumThreshold =
    'oACS.FilletRadiusMaximumThreshold =
    'oACS.FilletRadiusMinimumThreshold =
    oACS.ProjectionNormalAxis = True
    oACS.ProjectionParallelAxis = True
    'oACS.RadiusThresholdPrecision =
            
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    Dim oCM As Centermark
    Dim oCL As Centerline
    For Each oCM In oSheet.Centermarks
        oCM.Delete
    Next
    For Each oCL In oSheet.Centerlines
        oCL.Delete
    Next
    
    Dim oView As DrawingView
    Dim oViewOrient As ViewOrientationTypeEnum
    For Each oView In oSheet.DrawingViews
        oViewOrient = oView.Camera.ViewOrientationType
        If oViewOrient <> ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation And _
            oViewOrient <> ViewOrientationTypeEnum.kIsoBottomRightViewOrientation And _
            oViewOrient <> ViewOrientationTypeEnum.kIsoTopLeftViewOrientation And _
            oViewOrient <> ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
            oView.SetAutomatedCenterlineSettings (oACS)
        End If
    Next oView
End Sub

Give these a spin and see if they work OK for you.

 

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 11

Kassenbouw
Enthusiast
Enthusiast

Thanks for your reply . I have tried your code but this does not work with the hidden lines. When i manually put the style to hidden lines it works fine. 

Do I need to use a other way to get the hidden lines visible or is there a way to get the centerlines without having to put the style on hidden line?

0 Likes
Message 4 of 11

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 11

Kassenbouw
Enthusiast
Enthusiast

This code works fine per view, but is there a way to run this rule on all views except the isometric view?

If the only way is to use a messagebox is there a way to run the messagebox on the background with the answer 'Yes'?

 

Thanks for your help. 

0 Likes
Message 6 of 11

WCrihfield
Mentor
Mentor

Well...I modified that rule so it will effect all views on the active sheet, except the ISO views, instead of having you select a single view.  But I still haven't figured out any better alternative to using either a MsgBox or MessageBox.Show to make it work between switching view style and setting automated center lines.  You can't even say OK to the MsgBox or MessageBox.Show by code, because they are 'modal' by design, so you can't use SendKeys or execute 'AppContextual_OKCmd' to say OK to the message in the following lines of code, because it is waiting for the user to click OK manually, before it will even move on to any following code.

So, I just moved the MsgBox down to right above where it sets the automated center lines, then removed all text from the message to simplify it a bit.  It will still show that annoying MsgBox for each view it acts upon, but at least  it does what you want it to do pretty quickly.  My original rule didn't have this problem because I wasn't modifying the ViewStyle.

Here's the updated rule:

Sub Main
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oView As DrawingView
	
	'this will help bundle all actions into one item in your UNDO list
	Dim oTrans As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "iLogic - Set Automated Centerlines")
	
	Dim oViewOrient As ViewOrientationTypeEnum
	Dim oOrigStyle As DrawingViewStyleEnum
	For Each oView In oSheet.DrawingViews
		oViewOrient = oView.Camera.ViewOrientationType
		If oViewOrient = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation Or _
			oViewOrient = ViewOrientationTypeEnum.kIsoBottomRightViewOrientation Or _
			oViewOrient = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation Or _
			oViewOrient = ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
			Continue For
		End If
		
		'record view's 'original' view style, so we can restore it later
		oOrigStyle = oView.ViewStyle
		
		'make sure it is set to show hidden lines
		If oOrigStyle <> DrawingViewStyleEnum.kHiddenLineDrawingViewStyle Then
			oView.ViewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
		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
		
		MsgBox("", , "") 'needed for some reason
		
		'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
	Next

	oTrans.End 'ends the Transaction (for UNDO menu item)
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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 11

WCrihfield
Mentor
Mentor

Hi @Kassenbouw.  Thanks to this other post, I've at least figured out how to automatically close a MessageBox.Show() type message after x amount of time.  So I incorporated that into that last rule code I just posted above, to at least eliminate the user's need to manually click all the message boxes away.

However, there's still a slight variable you may have to play with to get it to work just right for your situation.  The amount of time specified within the 'TimedMessage' Sub may need to be slightly adjusted to suit your needs.  I've attempted to set it as low as possible, but there appears to be a threshold, where it stops being long enough to make the rest of the code still work.  For me that time was about .2 (two tenths) of a second.  If I go lower than that, it seems to start causing the other code to stop working for every view.  If I go higher, you start seeing the message boxes flashing on the screen, but the code still works OK.

Imports System.Threading.Tasks
Sub Main
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oView As DrawingView
	
	'this will help bundle all actions into one item in your UNDO list
	Dim oTrans As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "iLogic - Set Automated Centerlines")
	
	Dim oViewOrient As ViewOrientationTypeEnum
	Dim oOrigStyle As DrawingViewStyleEnum
	For Each oView In oSheet.DrawingViews
		oViewOrient = oView.Camera.ViewOrientationType
		If oViewOrient = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation Or _
			oViewOrient = ViewOrientationTypeEnum.kIsoBottomRightViewOrientation Or _
			oViewOrient = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation Or _
			oViewOrient = ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
			Continue For
		End If
		
		'record view's 'original' view style, so we can restore it later
		oOrigStyle = oView.ViewStyle
		
		'make sure it is set to show hidden lines
		If oOrigStyle <> DrawingViewStyleEnum.kHiddenLineDrawingViewStyle Then
			oView.ViewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
		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
		
		TimedMessge
		
		'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
	Next

	oTrans.End 'ends the Transaction (for UNDO menu item)
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

Sub TimedMessge()
	Dim oSecs As Double = .2 ' seconds
	Dim oForm As New Form With { .Enabled = True }
	Task.Delay(TimeSpan.FromSeconds(oSecs)).ContinueWith(Sub(t) 
			oForm.Close() 
		End Sub ,
	TaskScheduler.FromCurrentSynchronizationContext())
	MessageBox.Show(oForm, "Closing after " & oSecs & " seconds...")
End Sub

 

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 11

Kassenbouw
Enthusiast
Enthusiast

Hi WCrihfield

I've combined your 2 codes to this one. I noticed the function does work without a messagebox. This code works in my part and iam drawning but gives me an error in the iam drawning. 

 

This is the error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

This is the rule: 

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")
        
Dim oViewOrient As ViewOrientationTypeEnum
Dim oOrigStyle As DrawingViewStyleEnum
For Each oView In oSheet.DrawingViews
        oViewOrient = oView.Camera.ViewOrientationType
        If oViewOrient = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation Or _
               oViewOrient = ViewOrientationTypeEnum.kIsoBottomRightViewOrientation Or _
               oViewOrient = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation Or _
               oViewOrient = ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
               Continue For
        End If
        
        'record view's 'original' view style, so we can restore it later
        oOrigStyle = oView.ViewStyle

        'make sure it is set to show hidden lines
        If oOrigStyle <> DrawingViewStyleEnum.kHiddenLineDrawingViewStyle Then
               oView.ViewStyle = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
        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
Next
        oSheet.Update
        oTrans.End 'ends the Transaction (for UNDO menu)
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 

 

0 Likes
Message 9 of 11

WCrihfield
Mentor
Mentor

I'm not sure why it would matter which type of model document is being shown within the views.

Do you know if it is doing anything to your drawing, before it throws the error?  You could try inserting something simple like MsgBox(1), MsgBox(2) throughout the code, then when you run it, see which MsgBox is the last one to show before the error is thrown.  This will better help you find where in the code the error is being thrown.

Is this iLogic rule being used as a 'local' rule, or 'external' rule?  Is it possible that another document (maybe a model document) is sometimes 'active' when you run this rule?  If that were the case, then the first line would likely be pointing to that other 'active' document, instead of the target drawing document, and therefore causing problems.

 

Another thought is that maybe it does not like attempting to loop through all center marks or all center lines in a view/sheet if none exist, so you could try checking the .Count of the collection first to see if it is zero before attempting to loop through them.  I kind of doubt that's the problem though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 11

Kassenbouw
Enthusiast
Enthusiast

I've placed messagebox counters and noticed the error appears before the update.

 

        'make sure view style is back to original
        If oView.ViewStyle <> oOrigStyle Then
               oView.ViewStyle = oOrigStyle
        End If
		MsgBox("2", , "")
Next
        oSheet.Update
        oTrans.End 'ends the Transaction (for UNDO menu)
End Sub

This is the same for a local rule as an external rule. 

I've changed the first rule to 

Dim oDDoc As DrawingDocument = Thisdoc.Document

This makes no difference.

Is there a way to ignore the error like Try and Catch ex As Exception?

 

 

 

 

 

0 Likes
Message 11 of 11

Kassenbouw
Enthusiast
Enthusiast

I see now that this rule also deleted some of my dimensions and it deleted the origin of my origin indicator. 

When I run it without the delete old centermarks and centerline part the rule does nothing. 

0 Likes