Time will tell how valuable this page becomes, for now it is just a stub.
Many people don't write LISP 24/8. Unless you have a very good memory. Why not collect snippets and partial solutions? They are part of real life solutions for BricsCAD (and AutoCAD). If you have trouble understanding, just search the net, the intend is to keep the snippets compact.
DIESEL? Okay, it has not much to do with LISP and yet it does. If you write DIESEL in menu-items, they can be used transparent while running a LISP program - you can't enter LISP twice. That is a good reason to not put LISP in menu-items that can interact with other LISP programs. For example, use DIESEL for object snap. In other words: If you can do it in DIESEL, then don't do it in LISP!
Testing DIESEL on the command line
- Command: MODEMACRO.
- Then paste your "$strings" thing.
What does it say on the lower left of the CAD screen?
Remember, DIESEL is a string language and very easy (and limited).
In menu's, MODEMACRO command can be translated to "$M=".
First issuing a command (verb) and then selection (noun) was the old way until window oriented programs got popular, where the order was: First select (noun) and the do something like move (verb). Autodesk solved this with DIESEL by changing for example Move as below, first line old, second line "new":
This in still in use today. BricsCAD does not need this construction, smart enough to deal internally with handling the command, whether a selection set exists or should be asked for later.
One menu for both BricsCAD and AutoCAD
DIESEL can also be used to overcome small differences in commands between BricsCAD and AutoCAD. Example, BricsCAD does not have command MLEDIT, but you can edit multi lines via properties:
Automatically getting entities on the right layer
Suppose you made an environment variable "layerstring":
You can do this by hand or let LISP do it at program start. The next DIM command gets on the "dimensions" layer without intervention.
Switching PDMODE between 0 and 3:
$M=$(if,$(and,$(>,$(getvar,pdmode),0)),'pdmode 0,'pdmode 3)
Ways to deal with dialogues when closing a drawing. Two possibilities, chooce one:
(if (> (getvar "dbmod") 0) (command "._close" "_no") (command "._close")) (if (> (getvar "dbmod") 0) (command "._quit" "_yes") (command "._quit"))
Find out if your drawing is named (is ever saved is 1, never saved is 0):
Clients says: If operating system environment variable "StartApp" is "FALSE", don't run App. So run App means no variable or not "FALSE".
What we do:
(if (= "FALSE" (strcase (getenv "StartApp"))) (progn (defun *error*(msg) (setq *error* nil) (princ (strcat "\nProcessed environment variable StartApp for " appfullname ". "))) (exit)))
If you don't like (exit), create a big if...
Everything works fine... Until someone switches the environment variable to TRUE with the setenv function and the code is not executed!
What happened? The first time the value is read from the operating system and stored in the registry. The second time it is read from the registry entries of your CAD program because setenv did put it there.
That is wrong and we need a way to read it from the OS. How? There are two ways:
- Delete the registry entry of the CAD program.
- VERY IMPORTANT: Never use setenv to write the same variable name you retrieved with getenv, simply use a different name with setenv.
So we have setenv, getenv, but no... delenv. What we do have is vl-registry-delete:
(vl-registry-delete reg-key [val-name] )
The reg-key: This is different in BricsCAD, see second two lines, first two lines is AutoCAD. Please check, things can change in time, run regedit and search for your "StartApp". This is it:
Command: (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\FixedProfile\\General") "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R20.1\\ACAD-F001:409\\FixedProfile\\General" : (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Environment") "HKEY_CURRENT_USER\\Software\\Bricsys\\BricsCAD\\V17x64\\en_US\\Environment"
So for BricsCAD, this line should be before you issue a new getenv function:
(vl-registry-delete (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Environment") "StartApp" )
Again, this construction is not needed as long as you don't issue a (setenv "StartApp" "Whatever") function.
You may consider using a registry check first by issuing an (if (vl-registry-read ...)) function.