TheSwamp
Code Red => .NET => Topic started by: Jeff H on August 02, 2011, 04:52:08 PM
-
Any idea why this works in 2011 and not 2012?
To be more specific when you use the 'ToggleOverrule' comand below in 2011 it changes all lines to circles and call it again then they change back to lines and keeps changing each time you call it.
In 2012 when you call 'ToggleOverrule' it changes the lines to circles but will never change back. It will not turn off the overrule in 2012
The line
Overrule.Overruling = Not Overrule.Overruling
and have tried hard-coding to false but it never changes it false.
Code is from Stephen Preston's class
http://au.autodesk.com/?nd=class&session_id=7560
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(MyFirstOverrule_VB.MyCommands))>
Namespace MyFirstOverrule_VB
'This is our custom DrawableOverrule class.
'In this case we're just overruling WorldDraw
Public Class MyDrawOverrule
Inherits Autodesk.AutoCAD.GraphicsInterface.DrawableOverrule
Public Overrides Function WorldDraw(ByVal drawable As Autodesk.AutoCAD.GraphicsInterface.Drawable, ByVal wd As Autodesk.AutoCAD.GraphicsInterface.WorldDraw) As Boolean
'Cast Drawable to Line so we can access its methods and properties
Dim thisLine As Line = drawable
'Draw some graphics primitives
wd.Geometry.Circle(thisLine.StartPoint + 0.5 * thisLine.Delta, thisLine.Length / 2, thisLine.Normal)
'In this case we don't want the line to draw itself, nor do we want ViewportDraw called
Return True
'Return MyBase.WorldDraw(drawable, wd)
End Function
End Class
Public Class myCommands
'Shared member variable to store our Overrule instance
Private Shared mDrawOverrule As MyDrawOverrule
' Define Command "TOGGLEOVERRULE"
<CommandMethod("TOGGLEOVERRULE")> _
Public Shared Sub MyCommand()
' Initialize Overrule if this is the first time this function has run
If mDrawOverrule Is Nothing Then
mDrawOverrule = New MyDrawOverrule
Overrule.AddOverrule(RXObject.GetClass(GetType(Line)), mDrawOverrule, False)
End If
'Toggle Overruling on/off
Overrule.Overruling = Not Overrule.Overruling
'Regen is required to update changes on screen.
Application.DocumentManager.MdiActiveDocument.Editor.Regen()
End Sub
End Class
End Namespace
-
Not sure if this is best way but this makes it work 2012
Changing
Overrule.Overruling = Not Overrule.Overruling
to
If mDrawOverrule Is Nothing Then
mDrawOverrule = New MyDrawOverrule
Overrule.AddOverrule(RXObject.GetClass(GetType(Line)), mDrawOverrule, False)
Else
Overrule.Overruling = False
Overrule.RemoveOverrule(RXObject.GetClass(GetType(Line)), mDrawOverrule)
mDrawOverrule = Nothing
End If