Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
cadmike
Posts: 9
Registered: ‎05-04-2007
Message 1 of 7 (81 Views)

New LISP Routine

81 Views, 6 Replies
05-04-2007 03:40 PM
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
*Jason Rhymes
Message 2 of 7 (81 Views)

Re: New LISP Routine

05-04-2007 04:01 PM in reply to: cadmike
here is one about as stripped down as you can get.

(defun c:smileyvery-happy:IML ()
(COMMAND "-layer" "M" "DIM" "" "._DIMLINEAR")
(princ)
)
Active Member
cadmike
Posts: 9
Registered: ‎05-04-2007
Message 3 of 7 (81 Views)

Re: New LISP Routine

05-04-2007 06:19 PM in reply to: cadmike
thanks, I will try that and see how it works.
*tcebob
Message 4 of 7 (81 Views)

Re: New LISP Routine

05-05-2007 11:52 AM 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
Contributor
Hypnotix
Posts: 13
Registered: ‎03-23-2007
Message 5 of 7 (81 Views)

Re: New LISP Routine

05-07-2007 07:56 AM 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:smileytongue:L()(COMMAND (RL) "PLINE"))
(DEFUN C:REC()(COMMAND (RL) "RECTANGLE"))
(DEFUN C:A()(COMMAND (RL) "ARC"))
(DEFUN C:smileyvery-happy:O()(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:smileyvery-happy:T()(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:smileyvery-happy:LI()(COMMAND (SLD) "DIM"))
(DEFUN C:smileyvery-happy:AR()(COMMAND (SLD) "DIM"))
(DEFUN C:smileyvery-happy:AL()(COMMAND (SLD) "DIM"))
(DEFUN C:smileyvery-happy:RA()(COMMAND (SLD) "DIM"))
Active Member
cadmike
Posts: 9
Registered: ‎05-04-2007
Message 6 of 7 (81 Views)

Re: New LISP Routine

05-07-2007 08:39 AM 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.
Contributor
Hypnotix
Posts: 13
Registered: ‎03-23-2007
Message 7 of 7 (81 Views)

Re: New LISP Routine

05-07-2007 09:25 AM 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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.