Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

New LISP Routine

6 REPLIES 6
Reply
Message 1 of 7
cadmike
212 Views, 6 Replies

New LISP Routine

I am wanting to write a new routine for making layer changes based on what I type in the command line, since I dont use buttons for these functions. i have not written a LISP routine in about 4yrs and am very rusty on this. I would like the layer to change to DIM(does not need to be in all caps) when i type in DIM****(whatever is after dim, like linear, aligned) and hit enter. since I dont use the button for this, I dont want to add that step in the button command. any help would be appreciated.

Thanks,
Michael Reiter
www.reiterdrafting.com
michael@reiterdrafting.com
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: cadmike

here is one about as stripped down as you can get.

(defun c:DIML ()
(COMMAND "-layer" "M" "DIM" "" "._DIMLINEAR")
(princ)
)
Message 3 of 7
cadmike
in reply to: cadmike

thanks, I will try that and see how it works.
Message 4 of 7
Anonymous
in reply to: cadmike

Let's see if I understand: you already have layers dimaligned, dimlinear, etc. (or want to
create them if they don't exist.) Then you want the ensuing dimension to appear on the
appropriate layer. But you don't want to be stranded in that layer; you want to go back to
your original layer. Yes?

You can write a function named "dimlinear" that overrides to built-in one. I think that is
risky, because it depends on loading acad.lsp (or whatever self-loader). I would use
c:dl() or c:da() instead. Anyway, try this and let me know if it comes close:

(defun c:dl( / ) ; dimlinear to layer DIMLINEAR
(setq clay(getvar "clayer"))
(command "layer" "m" "dimlinear" "") ;this will either make it or activate it
(command "dimlinear"
(getpoint "\nSpecify the first extension line origin: ")
(getpoint "\nSpecify the second extension line origin: ")
(getpoint "\nSpecify dimension line location: ")
)
(command "layer" "s" clay "" )
(princ))

The reason for the getpoints is, if you just allow the dimension command to prompt, it
will quit and terminate the lisp function before it gets to the last line. Unfortunately,
you give up dragging the dimension lines this way.

rs
wrote in message news:5576074@discussion.autodesk.com...
I am wanting to write a new routine for making layer changes based on what I type in the
command line, since I dont use buttons for these functions. i have not written a LISP
routine in about 4yrs and am very rusty on this. I would like the layer to change to
DIM(does not need to be in all caps) when i type in DIM****(whatever is after dim, like
linear, aligned) and hit enter. since I dont use the button for this, I dont want to add
that step in the button command. any help would be appreciated.

Thanks,
Michael Reiter
www.reiterdrafting.com
michael@reiterdrafting.com
Message 5 of 7
Anonymous
in reply to: cadmike

Well I guess I have a different solution entirely to this than previous posters. Where I work we have a layer changing system built into the acad.mnl. It defines functions for AutoCAD by using something like SLD to change to your dimension layer meaning you put (SLD); in front of your dimlinear button, the final button appearance would be something like ^c^c_(SLD);_dimlinear;, and it will change to your dimension layer automatically for you. It will also create that layer and a set of other standard layers if it does not exist yet. This can also be used for hotkeys as well as can be seen at the end of the LISP routine. It uses (RL) to change to a recent layer as well.

Pretty neat little system that I cannot take credit for writing, as well as i'm not entirely sure who wrote it other than I keep bringing it in to the new version of AutoCAD at work and make modifications to it per peoples requests.




(DEFUN SLD ()
(CHKLAY)
(SETVAR "CMDECHO" 0)
(SETQ OL (GETVAR "CLAYER"))
(IF (AND (/= OL "REVISION") (/= OL "TEXT") (/= OL "DIM") (/= OL "HATCH") (/= OL "LEADER")) (SETQ ORIGLAY (GETVAR "CLAYER")))
(COMMAND "LAYER" "S" "DIM" "")
)
(DEFUN SLT ()
(CHKLAY)
(SETVAR "CMDECHO" 0)
(SETQ OL (GETVAR "CLAYER"))
(IF (AND (/= OL "REVISION") (/= OL "TEXT") (/= OL "DIM") (/= OL "HATCH") (/= OL "LEADER")) (SETQ ORIGLAY (GETVAR "CLAYER")))
(COMMAND "LAYER" "S" "TEXT" "")
)
(DEFUN SLR ()
(CHKLAY)
(SETVAR "CMDECHO" 0)
(SETQ OL (GETVAR "CLAYER"))
(IF (AND (/= OL "REVISION") (/= OL "TEXT") (/= OL "DIM") (/= OL "HATCH") (/= OL "LEADER")) (SETQ ORIGLAY (GETVAR "CLAYER")))
(COMMAND "LAYER" "S" "REVISION" "")
)
(DEFUN SLH ()
(SETVAR "CMDECHO" 0)
(CHKLAY)
(SETQ OL (GETVAR "CLAYER"))
(IF (AND (/= OL "REVISION") (/= OL "TEXT") (/= OL "DIM") (/= OL "HATCH") (/= OL "LEADER")) (SETQ ORIGLAY (GETVAR "CLAYER")))
(COMMAND "LAYER" "S" "HATCH" "")
)
(DEFUN SL ()
(SETVAR "CMDECHO" 0)
(CHKLAY)
(SETQ OL (GETVAR "CLAYER"))
(IF (AND (/= OL "REVISION") (/= OL "TEXT") (/= OL "DIM") (/= OL "HATCH") (/= OL "LEADER")) (SETQ ORIGLAY (GETVAR "CLAYER")))
(COMMAND "LAYER" "S" "LEADER" "")
)
(DEFUN RL ()
(SETVAR "CMDECHO" 0)
(IF (NULL ORIGLAY) (SETQ ORIGLAY "0"))
(SETQ OL (GETVAR "CLAYER"))
(IF (OR (= "DIM" OL) (= "TEXT" OL) (= "HATCH" OL) (= "LEADER" OL)) (COMMAND "LAYER" "S" ORIGLAY ""))
)
(DEFUN SLM ()
(SETVAR "CMDECHO" 0)
(IF (NULL ORIGLAY) (SETQ ORIGLAY "0"))
(SETQ OL (GETVAR "CLAYER"))
(IF (OR (/= OL "REVISION") (/= OL "TEXT") (/= OL "DIM") (/= OL "HATCH") (/= OL "LEADER")) (SETQ ORIGLAY (GETVAR "CLAYER")))
(COMMAND "LAYER" "S" "DefPoints" "")
)

;;LAYER CHECK AND CREATION SECTION

(DEFUN CHKLAY ()
(IF (NULL NEWLAYERFLAG)
(PROGN
(SETVAR "CMDECHO" 0)
(SETQ NEWLAYERFLAG 1)
(SETQ DIM 0)
(SETQ TEXT 0)
(SETQ HATCH 0)
(SETQ LEADER 0)
(SETQ REVISION 0)
(SETQ LAYS (CDR (ASSOC 2 (TBLNEXT "LAYER" T))))
(SETQ LAYS (LIST (CDR (ASSOC 2 (TBLNEXT "LAYER"))) LAYS))
(WHILE (SETQ TMP (TBLNEXT "LAYER"))
(SETQ LAYS (CONS (CDR (ASSOC 2 TMP)) LAYS))
);WHILE
(FOREACH N LAYS (IF (= N "DIM") (SETQ DIM 1)))
(FOREACH N LAYS (IF (= N "TEXT") (SETQ TEXT 1)))
(FOREACH N LAYS (IF (= N "HATCH") (SETQ HATCH 1)))
(FOREACH N LAYS (IF (= N "LEADER") (SETQ LEADER 1)))
(FOREACH N LAYS (IF (= N "REVISION") (SETQ REVISION 1)))
(IF (/= DIM 1) (COMMAND "LAYER" "N" "DIM" "C" "2" "DIM" ""))
(IF (/= TEXT 1) (COMMAND "LAYER" "N" "TEXT" "C" "2" "TEXT" ""))
(IF (/= HATCH 1) (COMMAND "LAYER" "N" "HATCH" "C" "171" "HATCH" ""))
(IF (/= LEADER 1) (COMMAND "LAYER" "N" "LEADER" "C" "31" "LEADER" ""))
(IF (/= REVISION 1) (COMMAND "LAYER" "N" "REVISION" "C" "43" "REVISION" ""))
(PRINT "LAYERS INSTALLED")
);PROGN
);IF
)

;;HOTKEY LAYER CHANGES
;;
;;SET TO RECENT LAYER

(DEFUN C:L()(COMMAND (RL) "LINE"))
(DEFUN C:PL()(COMMAND (RL) "PLINE"))
(DEFUN C:REC()(COMMAND (RL) "RECTANGLE"))
(DEFUN C:A()(COMMAND (RL) "ARC"))
(DEFUN C:DO()(COMMAND (RL) "DONUT"))
(DEFUN C:CI()(COMMAND (RL) "CIRCLE"))

;;SET TO HATCH LAYER

(DEFUN C:H()(COMMAND (SLH) "BHATCH"))

;;SET TO TEXT LAYER

(DEFUN C:DT()(COMMAND (SLT) "DTEXT"))
(DEFUN C:MT()(COMMAND (SLT) "MTEXT"))

;;SET TO LEADER LAYER

(DEFUN C:QLEADER()(COMMAND (SL) "QLEADER"))
(DEFUN C:LE()(COMMAND (SL) "QLEADER"))

;;SET TO DEFPOINTS LAYER

(DEFUN C:MV()(COMMAND (SLM) "VPORTS"))

;;SET TO DIM LAYER

(DEFUN C:DLI()(COMMAND (SLD) "DIM"))
(DEFUN C:DAR()(COMMAND (SLD) "DIM"))
(DEFUN C:DAL()(COMMAND (SLD) "DIM"))
(DEFUN C:DRA()(COMMAND (SLD) "DIM"))
Message 6 of 7
cadmike
in reply to: cadmike

the layer that I have is called DIM, when I type in DIMLINEAR or DIMALIGNED I want it to change to layer DIM, that is already created. I think this routine should work for that, then I can modify it to work with other command/layers. i am not using my buttons for this.
Message 7 of 7
Anonymous
in reply to: cadmike

Yes, the routine I posted is designed with multiple styles in mind. It is used to support 80 or so people that differ between hotkeying and button driven styles.

I posted it mainly because it seemed a little more versatile than the other examples provided as it works around having to pick points for dimensions and you can still see it as you normally would.

The layer preferences can be changed by changing it to the name you prefer wherever it would appear. DIM for example could be changed to S-anno-DIM if that is the standard used. Message was edited by: Hypnotix

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost