Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accepting the default in AutoCAD LSP Files 1

Status
Not open for further replies.

alanpward

Electrical
Jun 3, 2003
2
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)
)
 
Replies continue below

Recommended for you

(defun c:it (/ce)
(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.
 
BTW, if the line is accepting the defaults (which was your original question) use:

(command ".-insert" "titleblk" "0,0" "" "" "")

The &quot;&quot; reads like an <enter>.



 
Basically you just need to type all of it out in one line just like you would be typing it at the command line.
You cna get the insertion point earlier in your code, and input that later during the command

like this:
(setq pt1 (getpoint &quot;insertion point:&quot;))
(command &quot;-insert&quot; &quot;name of block&quot; pt1 &quot;&quot; &quot;&quot; &quot;&quot; )

Everything within &quot; &quot; 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 &quot;&quot;, and y scale factor &quot;&quot; and rotation &quot;&quot;
Each double &quot;&quot; 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 &quot;cmdecho&quot;))
(setq om (getvar &quot;orthomode&quot;))
(setq as (getvar &quot;autosnap&quot;))
(setq tm (getvar &quot;tilemode&quot;))
(setq os (getvar &quot;osmode&quot;))
(setq lay1 (getvar &quot;clayer&quot;))
(setq atd (getvar &quot;attdia&quot;))
(if (= tm 1)
(setq scf (getvar &quot;dimscale&quot;))
(setq scf 1)
)
(setvar &quot;cmdecho&quot; 0)
(setvar &quot;orthomode&quot; 1)
(setvar &quot;osmode&quot; 0)
(setvar &quot;attdia&quot; 1)
(command &quot;_.layer&quot; &quot;n&quot; &quot;G-ANNO-SYMB&quot; &quot;c&quot; &quot;123&quot; &quot;G-ANNO-SYMB&quot; &quot;s&quot; &quot;G-ANNO-SYMB&quot; &quot;&quot;)
(command &quot;_.layer&quot; &quot;t&quot; &quot;G-ANNO-SYMB&quot; &quot;s&quot; &quot;G-ANNO-SYMB&quot; &quot;&quot;)
(setq pt1 (getpoint &quot;insertion point:&quot;))
(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 &quot;insert&quot; &quot;p:/2k2_SUPT/LISP/GENERAL/TSA-narrow&quot; pt1 scf &quot;&quot; &quot;&quot; )
(command &quot;rotate&quot; &quot;last&quot; &quot;&quot; pt1 pause)
(command &quot;attedit&quot; &quot;Y&quot; &quot;TSA-NARROW&quot; &quot;LINE2&quot; &quot;*&quot; &quot;L&quot; &quot;a&quot; &quot;0&quot; &quot;p&quot; pt3 &quot;&quot;)
(command &quot;attedit&quot; &quot;Y&quot; &quot;TSA-NARROW&quot; &quot;LINE1&quot; &quot;*&quot; &quot;C&quot; pt5 pt4 &quot;a&quot; &quot;0&quot; &quot;p&quot; pt2 &quot;&quot;)
(setvar &quot;orthomode&quot; om)
(setvar &quot;cmdecho&quot; cmd)
(setvar &quot;osmode&quot; os)
(setvar &quot;clayer&quot; lay1)
(setvar &quot;autosnap&quot; as)
(setvar &quot;attdia&quot; atd)
(print &quot;DONE!&quot;)
(terpri)
(print)
)
 
CDH,
You don't need multiple calls to SETQ or COMMAND. INstead of:
(setq pt1 (getpoint &quot;insertion point:&quot;))
(setq pt2 (list (car pt1) (- (cadr pt1) (* scf 0.75))))
(setq pt3 (list (car pt2) (- (cadr pt1) scf)))

You can use:

(setq pt1 (getpoint &quot;insertion point:&quot;))
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 &quot;cmdecho&quot;)
om (getvar &quot;orthomode&quot;)
as (getvar &quot;autosnap&quot;)
tm (getvar &quot;tilemode&quot;)
os (getvar &quot;osmode&quot;)
lay1 (getvar &quot;clayer&quot;)
atd (getvar &quot;attdia&quot;)
)
(command &quot;cmdecho&quot; 0
&quot;orthomode&quot; 1
&quot;osmode&quot; 0
&quot;attdia&quot; 1
)
)
(defun vars-ret ()
(command &quot;cmdecho&quot; cmd
&quot;orthomode&quot; om
&quot;autosnap&quot; as
&quot;osmode&quot; os
&quot;attdia&quot; atd
&quot;clayer&quot; layl
)
)
;;;;;;;;;;;;;;;;;

You can expand on these as required, then at the start of every routine, just after (command &quot;undo&quot; &quot;begin&quot;) add (vars-get) and at the end just before (command &quot;undo&quot; &quot;end&quot;) add (vars-ret)

You can use them in your error trap as well.
 
Cheers lads, worked like a treat........Owe you all a pint some day
 
CADaver,
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 &quot;one step at a time&quot; Maybe that's just me though:)

Anyway, that is a good suggestion that I always seem to forget about!

Thanks
Chris
 
See, I'm just the opposite. Using the SETQ for a group and indenting them like I've shown above makes it easier for ME to keep track. But that's just me.
 
Well, I will have to say, it does make it easier now!
One question I do have is, what does the (command &quot;undo&quot; &quot;begin&quot;) and (command &quot;undo&quot; &quot;end&quot;)
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
 
It sets the function as a single undo.

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 &quot;MY&quot; VARS-GET/VARS-RET functions. I've built it into those.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor