.NET

.NET

Reply
Valued Contributor
mario.rosenbohm
Posts: 56
Registered: ‎12-06-2006
Message 1 of 2 (132 Views)

set undo-functionality off for current transaction

132 Views, 1 Replies
02-17-2014 12:45 AM

Hello,

 

how can i turn off the undo-functionality in the current / next started transaction?

 

regards Mario

Valued Contributor
mario.rosenbohm
Posts: 56
Registered: ‎12-06-2006
Message 2 of 2 (87 Views)

Found a Solution, but without transaction

02-18-2014 11:30 AM in reply to: mario.rosenbohm

Hello,

 

i have found a working solution. Based on this AutoCAD Devblog.

 

For the UndoOnOff-Class i using a Singleton-pattern, than can i call only one "Undo-SetOff()".

 

All code-comments in german, .. i am from .... ;-)

 

Using Undo-Off-On Class:

 

clUndoOnOff.Instance.SetOff();

... Start Transaction
... Work
... Commit Transaction

clUndoOnOff.Instance.SetOn();

 

Code (Singleton-Pattern):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace KPlusS.KaliGmbH.CSharpTools.Pattern
{
    /// <summary>Basisklasse für ThreadSafe Sigleton.
    /// Bei den Ableitungen IMMER den Konstruktor auf private setzten !!"</summary>
    /// <typeparam name="T">Type(KlassenName der Klasse die Singleton werden soll)</typeparam>
    public abstract class SingletonBase<T>
      where T : SingletonBase<T>
    {
        /// <summary>Die Instance</summary>
        private static volatile T instance = null;
        /// <summary>Thrad-Safe Lock-Object</summary>
        private static object syncRoot = new object();

        /// <summary>Getter der ThreadSafe-Instance der Sigleton</summary>
        public static T Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            object obj = FormatterServices.GetUninitializedObject(typeof(T));
                            if (obj != null)
                            {
                                instance = obj as T;
                                instance.Init();
                            }
                        }
                    }
                }
                else
                {
                    instance.Refresh();
                }
                return instance;
            }
        }

        /// <summary>Initialisierung der abgeleiteten Klasse</summary>
        protected virtual void Init()
        { }

        /// <summary>Aktualisierung der abgeleiteten Klasse</summary>
        protected virtual void Refresh()
        { }
    }
}

 

 

Code (Class-UndoOnOff):

 

!!! The Commands is only for German AutoCAD (tested on 2011) !!!

On German Autocad work the english command "_undo" but not the english parameter "_control","_all" and other. :smileyfrustrated:

 

The command-text after "// english" .. should work at english AutoCAD.

 

 

using System;                                       
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPlusS.KaliGmbH.CSharpTools.Pattern;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

namespace KPlusS.KaliGmbH.AutoCAD.V2011.Dbs
{
    /// <summary>Undo ein und Ausschalten.
    /// Bitte mit Beadcht verwenden !!</summary>
    public class clUndoOnOff : SingletonBase<clUndoOnOff>
    {
        #region Eigenschaften
        /// <summary>Wurde bereits ausgeschaltet?</summary>
        private Boolean haveSetOff;

        /// <summary>Command UNDO Auto ein</summary>
        private const String cmdAutoOn = "_undo g "; // english "_undo _all "
        /// <summary>Command UNDO Auto aus</summary>
        private const String cmdAutoOff = "_undo s n "; // english "_undo _Control _None "

        /// <summary>Command UNDO OnlyOneCommand ein</summary>
        private const String cmdOnlyOneCommandOn = "_undo e "; // english "_undo _one "
        /// <summary>Command UNDO OnlyOneCommand aus</summary>
        private const String cmdOnlyOneCommandOff = "_undo s n "; // Identisch mit cmdAutoOff!! english "_undo _Control _None "
        /// <summary>Command UNDO Layer ein</summary>
        private const String cmdLayerOn = "_undo l j "; // english "_undo _Layer _Yes"
        /// <summary>Command UNDO Layer aus</summary>
        private const String cmdLayerOff = "_undo l n "; // english "_undo _Layer _No"
        /// <summary>Command UNDO ZoomPan ein</summary>
        private const String cmdZoomPanOn = "_undo k j "; // english "_undo _C _Yes"
        /// <summary>Command UNDO ZoomPan aus</summary>
        private const String cmdZoomPanOff = "_undo k n "; // english "_undo _C _No"

        #endregion Eigenschaften

        #region Properties
        /// <summary>Undo ist ein?</summary>
        public Boolean UndoIsOn { get; private set; }
        /// <summary>Undo-EinKommando ist ein? ?</summary>
        public Boolean UndoIsOneCmd { get; private set; }
        /// <summary>Undo-Auto ist ein ?</summary>
        public Boolean UndoIsAuto { get; private set; }
        /// <summary>Undo-Group ist ein ?</summary>
        public Boolean UndoIsGroup { get; private set; }
        /// <summary>Undo-Zoom/Pan ist ein?</summary>
        public Boolean UndoIsZoomPan { get; private set; }
        /// <summary>Undo-Layer ist ein?</summary>
        public Boolean UndoIsLayer { get; private set; }
        /// <summary>SystemVariable Undo for ausschalten</summary>
        public Int16 UndoValue { get; private set; }
        #endregion Properties

        #region Konstruktoren
        /// <summary>Konstruktor = TOT</summary>
        private clUndoOnOff() { }
        #endregion Konstruktoren

        #region Methoden
        /// <summary></summary>
        protected override void Init()
        {
            base.Init();
            haveSetOff = false;
        }

        /// <summary>Testet die Systemvariable UNDO</summary>
        private void parseCurrentUndo()
        {
            this.UndoValue = (Int16)Application.GetSystemVariable("UNDOCTL");
            this.UndoIsOn = (UndoValue & 1) == 1;
            this.UndoIsOneCmd = (UndoValue & 2) == 2;
            this.UndoIsAuto = (UndoValue & 4) == 4;
            this.UndoIsGroup = (UndoValue & 8) == 8;
            this.UndoIsZoomPan = (UndoValue & 16) == 16;
            this.UndoIsLayer = (UndoValue & 32) == 32;
        }

        /// <summary>Undo ausschalten</summary>
        public void SetOff()
        {
            if (haveSetOff) return;
            parseCurrentUndo();
            if (!UndoIsOn) return;
            // zu erst immer Auto und OnlyOneCommand aus
            String commandString = "";
            if (this.UndoIsAuto || this.UndoIsOneCmd) commandString += cmdAutoOff;
            if (this.UndoIsLayer) commandString += cmdLayerOff;
            if (this.UndoIsZoomPan) commandString += cmdZoomPanOff;
            Application.DocumentManager.MdiActiveDocument.SendStringToExecute(commandString, false, false, false);
            haveSetOff = true;
        }

        /// <summary>Reaktiviert UNDOCTR auf den Stand den es vor dem SetOff hatte</summary>
        public void SetOn()
        {
            if (haveSetOff)
            {
                if (this.UndoValue > 0)
                {
                    String commandString = "";
                    if (this.UndoIsZoomPan) commandString += cmdZoomPanOn;
                    if (this.UndoIsLayer) commandString += cmdLayerOn;
                    if (this.UndoIsAuto)
                    {
                        commandString += cmdAutoOn;
                    }
                    else
                    {
                        if (this.UndoIsOneCmd) commandString += cmdOnlyOneCommandOn;
                    }
                    Application.DocumentManager.MdiActiveDocument.SendStringToExecute(commandString, false, false, false);
                }
                haveSetOff = false;
            }
        }

        #endregion Methoden

    }
}

 

 

regards Mario

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.