If - Then based on the color of a specific layer

If - Then based on the color of a specific layer

jpCADconsulting
Advocate Advocate
362 Views
6 Replies
Message 1 of 7

If - Then based on the color of a specific layer

jpCADconsulting
Advocate
Advocate
Hiya folks, long time no Code. I have need for an if/then operation based on the color of a specific layer (in my case L-ANNO-SYMB). So... this will be some code in acaddoc.lsp On fileopen I want AutoCAD to check for the color of layer L-ANNO-SYMB in the current file If it's 150, it will import page setups from one file Else it will load page setups from a different file I have the code for importing page setups form a file and it work fine, I just need the if/them bit and I'm not quite sure how to do it. Thanks as always!
0 Likes
363 Views
6 Replies
Replies (6)
Message 2 of 7

BlackBox_
Advisor
Advisor
Accepted solution
(if
  (and
    (setq var (tblsearch "layer" "L-ANNO-SYMB"))
    (setq var (cdr (assoc 62 var)))
  )
   (if (= 150 var)
     ;; import from one
     ;; import from the other
   )
)


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

More concisely:

(if (member '(62 . 150) (tblsearch "layer" "L-ANNO-SYMB"))

  (then -- load from one file)

  (else -- load from other file)

)

The (if) test will return nil if either the Layer's color is not 150 or the Layer does not exist, all in one, and without involving a variable.

Kent Cooper, AIA
0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

@BlackBox_ wrote:


(if
  (and
    (setq var (tblsearch "layer" "L-ANNO-SYMB"))
    (setq var (cdr (assoc 62 var)))
  )
   (if (= 150 (abs var))
     ;; import from one
     ;; import from the other
   )
)

 

In case it's off.

0 Likes
Message 5 of 7

BlackBox_
Advisor
Advisor
Accepted solution

@Kent1Cooper wrote:

More concisely:

(if (member '(62 . 150) (tblsearch "layer" "L-ANNO-SYMB"))

  (then -- load from one file)

  (else -- load from other file)

)

The (if) test will return nil if either the Layer's color is not 150 or the Layer does not exist, all in one, and without involving a variable.


Excellent point @Kent1Cooper, I feel like my .NET is creeping into my LISP these days. Haha

 

Cheers


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 6 of 7

BlackBox_
Advisor
Advisor
Accepted solution

@ВeekeeCZ wrote:

@BlackBox_ wrote:


(if
  (and
    (setq var (tblsearch "layer" "L-ANNO-SYMB"))
    (setq var (cdr (assoc 62 var)))
  )
   (if (= 150 (abs var))
     ;; import from one
     ;; import from the other
   )
)

 

In case it's off.


Thanks, @ВeekeeCZ !


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@ВeekeeCZ wrote:
...
   (if (= 150 (abs var))
...

In case it's off.


Good point.  It can still be done without a variable:

(if (member (cdr (assoc 62 (tblsearch "layer" "L-ANNO-SYMB"))) '(150 -150))
  (then -- load from one file)
  (else -- load from other file)
)
Kent Cooper, AIA
0 Likes