Author Topic: Help Improve Code  (Read 1105 times)

0 Members and 1 Guest are viewing this topic.

Ambo

  • Mosquito
  • Posts: 20
Help Improve Code
« on: October 24, 2015, 12:39:06 PM »
Hi there, I'm trying to write a subroutine on renaming a viewport layer by searching a viewport for specific frozen layer names.  It's working but the list of layers to be included in the search keeps on growing and ending up with so many "(and" on my code.  I know that there's a much better way of writing this but I just don't know how.  Could someone show me a more efficient way of writing the below lines please. OR... is there a similar function to express tool's "acet-viewport-frozen-layer-list" but for thawed layers? I've already searched to no avail. I'm thinking that if I can get a subroutine to do the opposite then I don't need the long list of frozen layers anymore.   Thank you.

Code: [Select]
(setq layer_list (acet-viewport-frozen-layer-list
(acet-currentviewport-ename)))

(if (and (and (member "Layer 1" layer_list)
(member "Layer 2" layer_list)
(member "Layer 3" layer_list)))
(progn
(setq lname "For Tender")
(setq lname "For Draft")))
« Last Edit: October 24, 2015, 02:05:35 PM by Ambo »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Help Improve Code
« Reply #1 on: October 24, 2015, 01:03:50 PM »
There is no need for:
Code - Auto/Visual Lisp: [Select]
  1. (and (and ...))
It is the same as:
Code - Auto/Visual Lisp: [Select]
  1. (and ...)

Alternative for your code:
Code - Auto/Visual Lisp: [Select]
  1.     '(lambda (lay) (vl-position lay layer_list))
  2.     '("Layer 1" "Layer 2" "Layer 3")
  3.   )
  4.   (setq lname "For Tender")
  5.   (setq lname "For Draft")
  6. )

When posting code, please use code tags.

Ambo

  • Mosquito
  • Posts: 20
Re: Help Improve Code
« Reply #2 on: October 24, 2015, 02:15:09 PM »
Thanks roy_043!  I'm learning a lot from kind people like you in this forum and apologies for forgetting to use the code tags.