• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1066
  • Last Modified:

Autocad Lisp Help Needed

I am very new to lisp programing and I am trying to know how to go about writing a lisp routine to freeze all layers and then turn certain layers back on and also zet the current layer to the zero layer. I was able to do all this, but gives me an error that you can not freeze the current layer. I was told by a guy in my office that I will need to do some kind of looping to get this to happen. can anyone send me in the right direction and mayme I would not have to do a loop since it is very confusion using if statements.
0
kierwright
Asked:
kierwright
  • 5
  • 2
1 Solution
 
dhsindy SparrowRetired considering supplemental income.Commented:
The program don't allow the current layer to be frozen but you can turn it "OFF" which has nearlly the same effect.

In your routine you can use variables that use wildcards characters to find things for you.  If you have a good naming system for your layers it really helps out.
0
 
darrenmcwiCommented:
Without looping, you can use a wildcard as dhsindy suggested. The Tilde "~" in "~0" tells it to match everything but the patten so it freezes everything but layer zero (0).
(defun c:test ()
  (setvar "clayer" "0")
  (command "layer" "f" "~0" "")
  (princ)
)

Open in new window

0
 
darrenmcwiCommented:
Here's one of many ways you could "loop" through the list of layers to do the same thing...
(defun c:test ()
  (setvar "clayer" "0")
  (setq rewind-flag T)
  (while (setq layer (tblnext "layer" rewind-flag))
    (setq rewind-flag nil)
    (if	(/= (setq layer-name (cdr (assoc 2 layer))) "0")
      (command "layer" "f" layer-name "")
    ) ;_END While-If
  ) ;_END While
  (princ)
)

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kierwrightAuthor Commented:
I like the first suggestion it is easy to understand, and i works great for the zero layer, but what I need is layer zero to be current and on and 7 or 8 other layers to be on also. I tried adding "~c-cntr-anno" and it did not work. what do i have to do to to turn on other layers as well?
0
 
darrenmcwiCommented:
Here's one way, you make also added code to verify layer zero is thawed before turning it on, then freeze all others, then a simple (foreach) loop to loop through the ones you want back thawed.
(defun c:test ()
  (command "layer" "t" "0" "")
  (setvar "clayer" "0")
  (command "layer" "f" "~0" "")
  (foreach item
		(list "layer1"
		      "layer3"
		      "layer5"
		)
    (command "layer" "t" item "")
  ) ;_ENDforeach
  (princ)
)

Open in new window

0
 
darrenmcwiCommented:
PS: There's more eligant ways to do this but being that yuo are new, you gotta start somehere. This also doesn't do anything with on/off status, just freeze/thaw but you get the idea.

Also note, that you can keep adding layers to "thaw" to the list fairly easily.
0
 
darrenmcwiCommented:
Here's yet another way without the loop. It's syntax is closer to what you are looking for. Note that the comma (,) and tilde (~) used earlier are special AutoCAD wildcards. You can learn more about the wildcards and others by looking up the (wcmatch) autolisp function in the Autolisp reference which is the only place they are documented despite being applicable in many places insode AutoCAD (even outside Autolisp)
(defun c:test ()
  (command "layer" "t" "0" "")
  (setvar "clayer" "0")
  (command "layer" "f" "~0" "")
  (command "layer" "t" "layer1,layer3,layer5" "")
  (princ)
)

Open in new window

0
 
kierwrightAuthor Commented:
Great Expert understood very well and easy to follow
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now