Veto() + Call Other Commands No History

BlackBox_
Advisor

Veto() + Call Other Commands No History

BlackBox_
Advisor
Advisor

The code I have works fine functionally and just trying to clean it up, so when others simply hit Enter to run PREVIEW again, it does that instead of the other Command I've invoked w/ Veto().

 

I am also certain that @ActivistInvestor has written about this before, but I either failed to find it, or Autodesk recently deleted it.

 

I'm working in 2022 again (new employer), I've resolved the LevelOfDetail issue sending command line input to inactive drawings (fixed in newer versions) by Veto()-ing PREVIEW, etc, but want user to be able to hit enter again, and it go back to PREVIEW.

 

It's been a few years since I've written code (spending most of my time with wife & toddler), so thanks for the guidance in advance! :beer:

 

Cheers

 

 

        public static void onCommandEnded(object sender, CommandEventArgs e)
        {
            try
            {
                //if sysvar == 1
                if (CoreUtils.WcMatch(e.GlobalCommandName.ToUpper(), "PREVIEW") &&
                    1 == Convert.ToInt16(acApp.GetSystemVariable(varName)))
                {
                    acDocs.MdiActiveDocument.CommandCancelled -= onCommandEnded;
                    acDocs.MdiActiveDocument.CommandEnded -= onCommandEnded;
                    acDocs.MdiActiveDocument.CommandFailed -= onCommandEnded;
                    acDocs.DocumentLockModeChanged += onDocumentLockModeChanged;

                    if (!levelOfDetail)
                    {
                        //acDocs.MdiActiveDocument.SendStringToExecute("LEVELOFDETAIL" + " ", false, false, false);
                        acDocs.MdiActiveDocument.SendStringToExecute("LODPREVIEW" + " ", false, false, false);

                        //levelOfDetail = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (acDocs.MdiActiveDocument != null)
                    acDocs.MdiActiveDocument.Editor.WriteMessage("\n; error: System.Exception: " + ex.Message + "\n");
            }
        }
        public static void onDocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
        {
            try
            {
                if (CoreUtils.WcMatch(e.GlobalCommandName.ToUpper(), "PREVIEW"))
                {
                    if (1 == Convert.ToInt16(acApp.GetSystemVariable(varName))
                        && levelOfDetail)
                    {
                        acDocs.DocumentLockModeChanged -= onDocumentLockModeChanged;
                        acDocs.MdiActiveDocument.CommandCancelled += onCommandEnded;
                        acDocs.MdiActiveDocument.CommandEnded += onCommandEnded;
                        acDocs.MdiActiveDocument.CommandFailed += onCommandEnded;

                        e.Veto();

                        //levelOfDetail = false;

                        acDocs.MdiActiveDocument.SendStringToExecute("LODPREVIEW" + " ", false, false, false);
                        //acDocs.MdiActiveDocument.SendStringToExecute("LEVELOFDETAILOFF" + " ", false, false, false);
                        //acDocs.MdiActiveDocument.SendStringToExecute("PREVIEW" + " ", false, false, false);
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (acDocs.MdiActiveDocument != null)
                    acDocs.MdiActiveDocument.Editor.WriteMessage("\n; error: System.Exception: " + ex.Message + "\n");
            }
        }

// this isn't working:
        [CommandMethod("LODPREVIEW", CommandFlags.NoHistory)]
        public void LevelOfDetailPreview()
        {
            Editor ed = acDocs.MdiActiveDocument.Editor;

            try
            {
                if (levelOfDetail)
                {
                    levelOfDetail = false;

                    acDocs.MdiActiveDocument.SendStringToExecute("LEVELOFDETAILOFF" + " ", false, false, false);
                    acDocs.MdiActiveDocument.SendStringToExecute("PREVIEW" + " ", false, false, false);
                }
                else
                {
                    levelOfDetail = true;

                    acDocs.MdiActiveDocument.SendStringToExecute("LEVELOFDETAIL" + " ", false, false, false);
                }
            }
            catch (System.Exception ex)
            {
                if (acDocs.MdiActiveDocument != null)
                    acDocs.MdiActiveDocument.Editor.WriteMessage("\n; error: System.Exception: " + ex.Message + "\n");
            }
        }

 



"How we think determines what we do, and what we do determines what we get."

0 Likes
Reply
Accepted solutions (1)
228 Views
4 Replies
Replies (4)

ActivistInvestor
Advisor
Advisor

I'm not sure I can understand what your intent is, by using SendStringToExecute() to run commands from the document context. Those calls do not execute until after the method that makes them returns control to AutoCAD.

 

What are they? Built-in commands, LISP-based commands, or something else?

BlackBox_
Advisor
Advisor

They're all built in (C3D) commands... Except for the LODPREVIEW, which was my failed attempt to invoke the native commands with no history.

 

For reference to this very old bug: https://forums.autodesk.com/t5/civil-3d-forum/level-of-detail/m-p/8912611/highlight/true#M403323

 

It's been a bit, and I recall there's multiple ways to invoke Commands; just didn't recall how to do so, so that the Command I've Veto()-ed (PREVIEW) is the last Command recognized, so when user hits Enter again, the Veto()-ed Command is what is done.

 

Wondering if I should simply redefine PREVIEW instead, but still unsure if that will do what I'm after.



"How we think determines what we do, and what we do determines what we get."

0 Likes

BlackBox_
Advisor
Advisor

If there is no solution to Veto()-ing PREVIEW Command, invoking LEVELOFDETAILOFF Command, re-invoking PREVIEW Command, then invoking LEVELOFDETAIL Command, so that PREVIEW Command is the last in history (replace the C3D Commands with any vanilla ACAD Commands, really)... that's fine.

 

This is admittedly a minor want to clean up an otherwise working solution (so far at least, in several days of testing) for C3D versions 2024 and older. I was more just frustrated I couldn't figure it out, TBH, and sought assistance here. Perhaps there is no way to do this. 

 

In C3D 2025 API, Autodesk exposed Surface.IsLevelOfDetailEnabled and SettingsSurface.Defaults.LevelOfDetail Properties, should this still be needed when new employer (eventually) upgrades from C3D 2022:

 

https://help.autodesk.com/view/CIV3D/2025/ENU/?guid=GUID-E032EFF9-8D28-4E72-867A-A6558CC8E7B7

 

Please and thank you!



"How we think determines what we do, and what we do determines what we get."

0 Likes

BlackBox_
Advisor
Advisor
Accepted solution

@BlackBox_ wrote:

If there is no solution to Veto()-ing PREVIEW Command, invoking LEVELOFDETAILOFF Command, re-invoking PREVIEW Command, then invoking LEVELOFDETAIL Command, so that PREVIEW Command is the last in history (replace the C3D Commands with any vanilla ACAD Commands, really)... that's fine.

 

<snip>


lmfao... there is a simple solution... love LISP right now:

 

 

(command ".undefine" "preview")

;;;(if (= 0 (getvar 'levelofdetailmode))    ; custom sysvar 
;;;  (setvar 'levelofdetailmode 0)
;;;)

(defun c:PREVIEW (/ *error* cmdecho nomutt)

  (defun *error* (msg)
    (if cmdecho (setvar 'cmdecho cmdecho))
    (if nomutt (setvar 'nomutt nomutt))
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )

  (setq cmdecho (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setq nomutt (getvar 'nomutt))
  (setvar 'nomutt 0)

  (command "LEVELOFDETAILOFF" ".PREVIEW" "LEVELOFDETAIL")

  (*error* nil)
)

 

 

 

 

 

 



"How we think determines what we do, and what we do determines what we get."

0 Likes