About Using AutoLISP to Set MODEMACRO

Set MODEMACRO values with AutoLISP.

Note: AutoLISP is not available in AutoCAD LT for Mac OS and the MODEMACRO system variable is not available on Mac OS.

AutoLISP can be used to assign a string to the MODEMACRO system variable and display the results to the status bar. Use the AutoLISP strcat function to assemble the complete MODEMACRO string from shorter component strings.

(defun C:ACADMODE()
  (setvar "modemacro"
    (strcat
        "Layer $(substr,$(getvar,clayer),1,8)"
        "$(if,$(getvar,orthomode), Ortho)"
        "$(if,$(getvar,snapmode), Snap)"
        "$(if,$(=,$(getvar,tilemode),0),"
        "$(if,$(=,$(getvar,cvport),1), P)"
        ")"
    )
  )
)

The following sample uses the S::STARTUP function to load an AutoLISP file named mode1.lsp and it sets a string to the MODEMACRO system variable.

;;; S::STARTUP loads the file MODE1.LSP which defines a MODEMACRO string
(defun S::STARTUP ( )
  (load "mode1")
 (princ)
)
;;; Additional AutoLISP files can also be defined or loaded here

When the AutoLISP file mode1.lsp is loaded, it sets the MODEMACRO system variable to display information at the status bar. The text displayed starts with L: followed by the first eight characters of the current layer name, the drawing name and a portion of the path, and the first letter of each name of the currently active modes. The position of the drawing name remains constant, regardless of the length of the layer name.

;;; MODE1.LSP
(setvar "modemacro" 
  (strcat
    "L:$(substr,$(getvar,clayer),1,30)"
    "$(substr,        ,1,$(-,30,$(strlen,$(getvar,clayer)))) "
    ;;            ^^^^^^^^ Note the 8 spaces here
    "<.."
      "$(if,$(eq,$(getvar,dwgname),UNNAMED),UNNAMED,"
        "$(substr,$(getvar,dwgname),"
          "$(if,$(>,$(strlen,$(getvar,dwgprefix)),29),"
            "$(-,$(strlen,$(getvar,dwgprefix)),29),1"
          "),"
          "$(strlen,$(getvar,dwgname))"
        ")"
      ")"
    ">"
    "$(if,$(getvar,orthomode), O, )"
    "$(if,$(getvar,snapmode), S, )"
    "$(if,$(and,"
    "$(=,$(getvar,tilemode),0),$(=,$(getvar,cvport),1)),P)"
  )
)

DIESEL expressions can also be evaluated by AutoLISP routines through the use of the AutoLISP menucmd function.