Author Topic: Layere issue with LISP routine please help ...  (Read 1411 times)

0 Members and 1 Guest are viewing this topic.

Aerdvark

  • Guest
Layere issue with LISP routine please help ...
« on: October 09, 2009, 05:32:50 AM »
Hello,

This routine is what I use to create layers in a certain way.
It works perfectly. There is only one thing that bothers me.

Lets say I open a new drawing: the current layer is "0" and the colour is "bylayer". I manually set the color to "Red".

Then, at any time, whenever I call the createlayer function and there is a layer created, ie. "Test" with colour 33 the coulor is created but not set to 33. It stays "Red" as I set manually...

How to overrule? That whatever layer is set / created: allways set the colour to the disired valu, in this example I want it to be "33".

With Lee's help this routine was created !!
Tnx in advance.
Marco.

By the way: ";; Another Option for Layer Creation to Consider:"
Does it matter to have it as shown? I mean both and not one specific?
Maybe conflict or so?


Code: [Select]
(defun c:createlayer (/ ltname layname laycol cmdold lay)
  (vl-load-com)
  (setq ltname (getstring "\nPlease enter the name of the linetype: ")
        layname (getstring "\nPlease enter the name of the layer: ")
        laycol (getint "\nPlease enter the colour of the layer: ")
layplot (getstring "\nDo you want the layer to be <Plot> or <Non plot>: ")
        cmdold (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  ;; Loading Linetype  ~ Another option to consider:

  (if (not (tblsearch "LTYPE" ltname))
    (vla-load
      (vla-get-Linetypes
        (vla-get-ActiveDocument
          (vlax-get-acad-object))) ltname "acadiso.lin"))

  ;; Layer Checking & Creation

  (if (not (tblsearch "LAYER" layname))
    (command "_.-layer" "_M" layname "_L" ltname layname "_C" laycol layname "_P" layplot "" "")
    (setvar "CLAYER" layname))

  ;; Another Option for Layer Creation to Consider:

  (if (not (tblsearch "LAYER" layname))
    (progn
      (setq lay (vla-add
                  (vla-get-layers
                    (vla-get-ActiveDocument
                      (vlax-get-acad-object))) layname))
      (vla-put-color lay laycol)
      (vla-put-linetype lay ltname)))
  (setvar "CLAYER" layname)

  ;; Reset CMDECHO

  (setvar "CMDECHO" cmdold)
  (princ))




Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Layere issue with LISP routine please help ...
« Reply #1 on: October 09, 2009, 06:59:27 AM »
I remember helping you with this Marco, over on CADTutor.net, but I included two methods for layer creation - one using Visual LISP, and the other using the command line... - they should not conflict, as there is an IF statement present - but it is meaningless to have both.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Layere issue with LISP routine please help ...
« Reply #2 on: October 09, 2009, 07:00:37 AM »
By the way, the colour issue you are having is because the routine is setting the layer colour, which is overridden by the sys var CECOLOR  :-)

Aerdvark

  • Guest
Re: Layere issue with LISP routine please help ...
« Reply #3 on: October 09, 2009, 08:15:48 AM »
Hi Lee,

oops it was that simple... 8-)

This is how I fixed it:

Code: [Select]
(defun c:createlayer (/ ltname layname laycol cmdold lay)
  (vl-load-com)
  (setq ltname (getstring "\nPlease enter the name of the linetype: ")
        layname (getstring "\nPlease enter the name of the layer: ")
        laycol (getint "\nPlease enter the colour of the layer: ")
layplot (getstring "\nDo you want the layer to be <Plot> or <Non plot>: ")
        cmdold (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  ;; Loading Linetype  ~ Another option to consider:

  (if (not (tblsearch "LTYPE" ltname))
    (vla-load
      (vla-get-Linetypes
        (vla-get-ActiveDocument
          (vlax-get-acad-object))) ltname "acadiso.lin"))

  ;; Layer Checking & Creation

  (if (not (tblsearch "LAYER" layname))
    (command "_.-layer" "_M" layname "_L" ltname layname "_C" laycol layname "_P" layplot "" "")
    (setvar "CLAYER" layname))


  ;; Reset CMDECHO

  (setvar "CMDECHO" cmdold)
  [color=red](setvar "CECOLOR" "bylayer")[/color]
 (princ))