Author Topic: LISP works for one command, but not another...  (Read 3283 times)

0 Members and 1 Guest are viewing this topic.

PitchBlack98

  • Guest
LISP works for one command, but not another...
« on: April 01, 2009, 10:52:21 AM »
I am working on some simple lisps to make drafting layouts go a little quicker.

I have it set to get the current layer and then change the layer to the layer I need. Then it runs the command I want to run on the new layer. When that command is done I want it to reset back to the original layer. It is working great for my quick leader command, but then isnt working for other commands I want to use... I am using the same code for the other commands and just editing them slighty to do what I want to do. I appreciate any info on this.

Here is the quick leader code that is working.
Code: [Select]
;Draws a Quick Leader on the DIM layer with current dimstyle.
;Resets back to layer that was current before command.
(defun c:AS ()
  (setq userlyr (getvar "CLAYER"))
  (command "-layer" "set" "DIM" "")
  (command "qleader")
  ;;===Reset layer back to previous layer===
  (setvar "CLAYER" userlyr)
  (princ)
)

and here is the code for doing a linear dim, drawing a dropped beam, and another for inserting a block that doesnt work.
Code: [Select]
;Draws a Linear Dim on the DIM layer with current dimstyle.
;Resets back to layer that was current before command.
(defun c:DIML ()
  (setq userlyr (getvar "CLAYER"))
  (command "-layer" "set" "DIM" "")
  (command "DIMLINEAR")
  ;;===Reset layer back to previous layer===
  (setvar "CLAYER" userlyr)
  (princ)
)

Code: [Select]
;Inserts a post.4x4 on the COLUMN layer.
;Resets back to layer that was current before command.
(defun c:C4 ()
  (setq userlyr (getvar "CLAYER"))
  (command "-layer" "set" "COLUMN" "")
  (command "INSERT" "post.4x4")
  ;;===Reset layer back to previous layer===
  (setvar "CLAYER" userlyr)
  (princ)
)

Code: [Select]
;Draws a Dropped Beam on the BEAM.DROP layer.
(defun c:BD ()
  (setq userlyr (getvar "CLAYER"))
  (command "-layer" "set" "BEAM.DROP" "")
  (command "LINE")
  ;;===Reset layer back to previous layer===
  (setvar "CLAYER" userlyr)
  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LISP works for one command, but not another...
« Reply #1 on: April 01, 2009, 11:07:54 AM »
You could use a reactor to manage your layers:
http://www.theswamp.org/index.php?topic=22733.msg273953#msg273953
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: LISP works for one command, but not another...
« Reply #2 on: April 01, 2009, 11:10:41 AM »
Another though is to put the object on the layer after it's drawn and not mess with the clayer:

Code: [Select]
(command "INSERT" "post.4x4")
(setq el (entget (entlast)))
(if (wcmatch (strcase (cdr (assoc 2 el))) (strcase "post.4x4"))
  (entmod (subst (cons 8 "column") (assoc 8 el) el))
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LISP works for one command, but not another...
« Reply #3 on: April 01, 2009, 11:14:18 AM »
The problem you are having with your lisp is that the ACAD commands you start in the lisp are not
allowed to finish before the lisp continues to its completion.

For example the LINE command requires the user to pick two points. You must provide a pause in the
lisp to allow the user to pick the points.
Code: [Select]
(command "._line" pause pause "")The last "" is used to terminate the command as ACAD will continue the line command to another point.

To allow the user to terminate the command with ENTER key you would need this code.
Code: [Select]
(command "._line" )
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
)

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LISP works for one command, but not another...
« Reply #4 on: April 01, 2009, 11:20:47 AM »
Ron's suggestion is a good one because it allows for the case where the user may use the
Escape key to exit the lisp and the layer will not reset to previous layer. That is usually
handles in an Error Handler Routine.

One caution, I would use equals in place of wcmatch in case the block name contained
some reserved wild card characters.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

PitchBlack98

  • Guest
Re: LISP works for one command, but not another...
« Reply #5 on: April 01, 2009, 11:27:55 AM »
Thanks for the input guys. I will see what I can put together with some of your suggestions.

I am self taught/teaching lisp and dont quite understand some of the more complicated functions. I seem to be ok with very simple Lisps, but some of the more complicated ones get me frustrated and I give up. lol... I am pretty good with macros and think I have a hard time of not thinking about macros when I am trying to put together a lisp.

Anyone recommend some good books or tutorials that can help me along. Ive gone thru the AutoCAD help section many times and something more detailed would be great.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: LISP works for one command, but not another...
« Reply #6 on: April 01, 2009, 11:45:42 AM »
I am self taught/teaching lisp ...

As are 99% of us. :)

... dont quite understand some of the more complicated functions.

As is it for all of us: it comes with practice (there is no other way imo). :)

Anyone recommend some good books or tutorials that can help me along.

In my biased opinion this site is one of the best places to learn LISP because of the outstanding peer support and tons of example programs / functions that reside herein.

If you're looking for a static tutorial / reference try www.afralisp.net, lots there and written pretty well by a nice guy.

Welcome to the swamp. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: LISP works for one command, but not another...
« Reply #7 on: April 01, 2009, 11:57:22 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

curmudgeon

  • Newt
  • Posts: 194
Re: LISP works for one command, but not another...
« Reply #8 on: April 01, 2009, 12:28:48 PM »
suggestion - explore entmake. years ago I wrote my own leader command, as many have I think. I force the layer I want in the entmake list. same approach for everything I draw parametrically, like windows in elevation, the code draws everything at once in the appropriate layer in the first place. as for inserting blocks, same story. entmake the block and (cons 8 "layer_name") you want it to be inserted in.

hope that helps.

roy

totally irresponsible of me to leave this point out. while you are new at constructing the lists for various entities, just create an example entity and (entget (car (entsel))) to see what the list that created it looks like. I went for years without having to understand what a subclass marker was for, and what I could safely NOT put in the list.
Never express yourself more clearly than you are able to think.

PitchBlack98

  • Guest
Re: LISP works for one command, but not another...
« Reply #9 on: April 01, 2009, 02:55:10 PM »
wow thanks for all the information! I owe you guys a beer if you are every out my way (Colorado).

This is a great site and everything I have learned about lisp has pretty much come from this site. I actually think this is the only site I have bookmarked for lisp.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: LISP works for one command, but not another...
« Reply #10 on: April 01, 2009, 02:56:48 PM »
wow thanks for all the information! I owe you guys a beer if you are every out my way (Colorado).

This is a great site and everything I have learned about lisp has pretty much come from this site. I actually think this is the only site I have bookmarked for lisp.

I live in Colorado AND I like beer  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PitchBlack98

  • Guest
Re: LISP works for one command, but not another...
« Reply #11 on: April 01, 2009, 03:06:21 PM »
I live in Colorado AND I like beer  :-)

Really? where at? I'm in Littleton.

I think I may have found a personal tutor... haha

ronjonp

  • Needs a day job
  • Posts: 7529
Re: LISP works for one command, but not another...
« Reply #12 on: April 01, 2009, 03:14:51 PM »
I live in Colorado AND I like beer  :-)

Really? where at? I'm in Littleton.

I think I may have found a personal tutor... haha

I'm in Fort Collins  :kewl: ....Here at the swamp you'll have many tutors.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PitchBlack98

  • Guest
Re: LISP works for one command, but not another...
« Reply #13 on: April 01, 2009, 04:35:35 PM »
I live in Colorado AND I like beer  :-)

Really? where at? I'm in Littleton.

I think I may have found a personal tutor... haha

I'm in Fort Collins  :kewl: ....Here at the swamp you'll have many tutors.

Thats cool. Maybe we can meet up sometime and grab a beer or 4. lol