Accepting the default in AutoCAD LSP Files
Accepting the default in AutoCAD LSP Files
(OP)
Hey there,
I have written the following lsp file (see below), Not too advanced at writing them, But I have an idea, Well the problem is once the titleblock is inserted (Block "text"). Its asks me for the scale and rotation, Is there any way of writing into the Lsp File a way to accept these defaults.....Much appreciate anything you may be able to suggest,
Cheers...Its a basic one, But yet a problem...
;; it.LSP
;; This program will insert the titleblock with editable attributes
;;
(defun C:it (/ ce)
(setq ce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "undo" "m")
(command "i" "text")
(command "0,0")
(command "1")
(command "1")
(command "0")
(setvar "cmdecho" ce)
(princ)
)
I have written the following lsp file (see below), Not too advanced at writing them, But I have an idea, Well the problem is once the titleblock is inserted (Block "text"). Its asks me for the scale and rotation, Is there any way of writing into the Lsp File a way to accept these defaults.....Much appreciate anything you may be able to suggest,
Cheers...Its a basic one, But yet a problem...
;; it.LSP
;; This program will insert the titleblock with editable attributes
;;
(defun C:it (/ ce)
(setq ce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "undo" "m")
(command "i" "text")
(command "0,0")
(command "1")
(command "1")
(command "0")
(setvar "cmdecho" ce)
(princ)
)





RE: Accepting the default in AutoCAD LSP Files
(setq ce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "undo" "begin")
(command ".-insert" "titleblk" "r" "0" "s" "1" "0,0")
(setvar "cmdecho" ce)
(command "undo" "end")
(princ)
)
;;;;;;;;;;;;;;;;;Don't name blocks, variables, or functions with names that have been reserved by the program.
You don't need a command line for each response. R presets rotation and S presets scale. Both can be used at the command line as well.
RE: Accepting the default in AutoCAD LSP Files
(command ".-insert" "titleblk" "0,0" "" "" "")
The "" reads like an <enter>.
RE: Accepting the default in AutoCAD LSP Files
You cna get the insertion point earlier in your code, and input that later during the command
like this:
(setq pt1 (getpoint "insertion point:"))
(command "-insert" "name of block" pt1 "" "" "" )
Everything within " " is what you would type, and anything without comes from a vriable in your routine.
So in this case you: insert, input name of block, insertion point is pt1 which was defined earlier, then you have the x scale factor "", and y scale factor "" and rotation ""
Each double "" is like an enter.
Here is a complete example of one of my lisps. It has some extra stuff, but it should give you an idea:
(defun c:TSA-narrow (/ om cmd scf os tm atd)
(setq cmd (getvar "cmdecho"))
(setq om (getvar "orthomode"))
(setq as (getvar "autosnap"))
(setq tm (getvar "tilemode"))
(setq os (getvar "osmode"))
(setq lay1 (getvar "clayer"))
(setq atd (getvar "attdia"))
(if (= tm 1)
(setq scf (getvar "dimscale"))
(setq scf 1)
)
(setvar "cmdecho" 0)
(setvar "orthomode" 1)
(setvar "osmode" 0)
(setvar "attdia" 1)
(command "_.layer" "n" "G-ANNO-SYMB" "c" "123" "G-ANNO-SYMB" "s" "G-ANNO-SYMB" "")
(command "_.layer" "t" "G-ANNO-SYMB" "s" "G-ANNO-SYMB" "")
(setq pt1 (getpoint "insertion point:"))
(setq pt2 (list (car pt1) (- (cadr pt1) (* scf 0.75))))
(setq pt3 (list (car pt2) (- (cadr pt1) scf)))
(setq pt4 (list (+ (car pt1) scf) (+ (cadr pt1) scf)))
(setq pt5 (list (- (car pt1) scf) (- (cadr pt1) scf)))
(command "insert" "p:/2k2_SUPT/LISP/GENERAL/TSA-narrow" pt1 scf "" "" )
(command "rotate" "last" "" pt1 pause)
(command "attedit" "Y" "TSA-NARROW" "LINE2" "*" "L" "a" "0" "p" pt3 "")
(command "attedit" "Y" "TSA-NARROW" "LINE1" "*" "C" pt5 pt4 "a" "0" "p" pt2 "")
(setvar "orthomode" om)
(setvar "cmdecho" cmd)
(setvar "osmode" os)
(setvar "clayer" lay1)
(setvar "autosnap" as)
(setvar "attdia" atd)
(print "DONE!")
(terpri)
(print)
)
RE: Accepting the default in AutoCAD LSP Files
You don't need multiple calls to SETQ or COMMAND. INstead of:
(setq pt1 (getpoint "insertion point:"))
(setq pt2 (list (car pt1) (- (cadr pt1) (* scf 0.75))))
(setq pt3 (list (car pt2) (- (cadr pt1) scf)))
You can use:
(setq pt1 (getpoint "insertion point:"))
pt2 (list (car pt1) (- (cadr pt1) (* scf 0.75)))
pt3 (list (car pt2) (- (cadr pt1) scf))
)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And you can write a subfunction for the system variable collection and return.
(defun vars-get ()
(setq cmd (getvar "cmdecho")
om (getvar "orthomode")
as (getvar "autosnap")
tm (getvar "tilemode")
os (getvar "osmode")
lay1 (getvar "clayer")
atd (getvar "attdia")
)
(command "cmdecho" 0
"orthomode" 1
"osmode" 0
"attdia" 1
)
)
(defun vars-ret ()
(command "cmdecho" cmd
"orthomode" om
"autosnap" as
"osmode" os
"attdia" atd
"clayer" layl
)
)
;;;;;;;;;;;;;;;;;
You can expand on these as required, then at the start of every routine, just after (command "undo" "begin") add (vars-get) and at the end just before (command "undo" "end") add (vars-ret)
You can use them in your error trap as well.
RE: Accepting the default in AutoCAD LSP Files
RE: Accepting the default in AutoCAD LSP Files
Thanks for pointing that out. This was an older routine of mine, and when I first started learning lisp, it was easier for me to keep track of what I was doing, by doing it this way, kind of like "one step at a time" Maybe that's just me though:)
Anyway, that is a good suggestion that I always seem to forget about!
Thanks
Chris
RE: Accepting the default in AutoCAD LSP Files
RE: Accepting the default in AutoCAD LSP Files
One question I do have is, what does the (command "undo" "begin") and (command "undo" "end")
exactly do. I think I know, but I have never used it, and I am always looking for a better way to do things!
Thanks
Chris
RE: Accepting the default in AutoCAD LSP Files
I have a MAKEVIEW routine that creates and saves a couple dozen views from different viewpoints of a 3D model. Without the UNDO begin/end, I'd have to undo each (command call the routine used to get back before the MAKEVIEW command was issued. With the UNDO begin/end, it treats the MAKEVIEW as a single function requiring one UNDO. It, also, doesn't stop an UNDO <count> like an UNDO MARK will.
I just got in the habit of adding it to everything except those that I use "MY" VARS-GET/VARS-RET functions. I've built it into those.