Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to Set Layer Color In LSP?

edited April 16 in LISP Codes

Hi.
I have this lsp that create 3 layers and I can't set the layers color. can anyone point me to what I'm doing Wrong?

(defun c:SETL1 (/ cnt int lname pref L1 L2 L3 C1 C2 C3 oldlayer)
(setq oldlayer (getvar "CLAYER"))

(setq L1 "Contour Major")
(setq L2 "Contour Minor")
(setq L3 "Contour Labels")
(setq C1 7)
(setq C2 8)

(setq lname L1)
(if (not (tblsearch "LAYER" lname))
(command "._layer" "_M" L1 "_C" (itoa C1) "_Lt" "Continuous" L1 ""))

(setq lname L2)
(if (not (tblsearch "LAYER" lname))
(command "._layer" "_M" L2 "_C" (itoa C2) "_Lt" "Continuous" L2 ""))

(setq lname L3)
(if (not (tblsearch "LAYER" lname))
(command "._layer" "_M" L3 "_C" (itoa C1) "_Lt" "Continuous" L3 ""))

(setvar "CLAYER" oldlayer)
(princ)
)

Thanks,
Ari.

Best Answers

  • Answer ✓

    Hi,
    it is not necessary to set the layer current to change it's properties.
    When I paste this code in the command line, the color of layer '0' is changed to white, even if it was another color and it was not active.

    (setq C1 7)
    (command "._layer" "_C" (itoa C1) "0" "")

    Instead of putting all changes in one line you can try doing it in separate lines and then later you can join them if you see that everything works.

  • edited April 27 Answer ✓

    Much easier is to make a defun that accepts the new layer (mklayer "layer1" 7 "DASHED") the mklayer defun can check does it exist etc I have a couple the simplest is (mklayer1 "Newlayer") the next (mklayer2 "newlayer" color) and so on. also color can be just a number no need for C1.

    I have this as part of the autoload so available for every new code

Answers

  • edited April 16

    @Piet
    Thanks.
    so the issue was I didn't put the layer name after the color....
    I've changed the lisp according to your comment and it is working.

    (command "._layer" "_M" L1 "_C" C1 L1 "_Lt" "Continuous" L1 ""))

    L1 - layer name
    C1 - integer that store the layer color.

Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam