TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: lamarn on February 10, 2017, 09:46:01 AM

Title: Create layer - can't get it to work..
Post by: lamarn on February 10, 2017, 09:46:01 AM
I'm trying all kinds of things to make a layer that has is a number as name.
For some reason i get this back the whole time..
I tried layer, _layer and -layer ..


"..
Command: ; error: AutoCAD command rejected: "_Layer"
.."


Any advice?



Title: Re: Create layer - can't get it to work..
Post by: ribarm on February 10, 2017, 10:04:14 AM
Have you tried :
(setq rtosidx (rtos (float idx) 2 0))
Title: Re: Create layer - can't get it to work..
Post by: ribarm on February 10, 2017, 10:19:03 AM
Have you checked sysvar QAFLAGS... Should be set to 0...

HTH.
Title: Re: Create layer - can't get it to work..
Post by: Grrr1337 on February 10, 2017, 10:23:02 AM
Try with
Code: [Select]
(command "_.-Layer" ...)
Title: Re: Create layer - can't get it to work..
Post by: lamarn on February 10, 2017, 10:33:17 AM
Thanks for replying!

still get  Command: ; error: AutoCAD command rejected: "_.-Layer" with float and QAflags 0

I think my problem is that idx comes from another defun and somehow the value is lost.. (?) Beneith the pieces of code
(i'm not so advanced in lisp programming as i would like to be.. ;-) thanks anyway

*EDIT* but then again, this "test" code give me it.. I don't understand..
Code: [Select]
(defun ColorButtonOnClick (idx)
    (dcl-Form-Close color_swatch/COLOR_SWATCH idx)
    (setq itoaidx (itoa idx))
    (setq rtosidx (rtos (float idx) 2 0))
    (if (not (tblsearch "layer" rtosidx))
        (progn (command "_.-Layer" "New" "test" "")
               (princ (strcat "\nLayer \"" "test" "\"Created ."))
        )
        (princ "\nLayer Name Already exist.")
    )                                             ;   (c:csw)
                                                  ;   (c:lac)
)


Code: [Select]

;====
;------ assigning menu buttons (Roy_043)
(defun c:CSW ( / idx ret)
  (setq idx 0)
  (repeat 4
    (eval
      (read
        (strcat
          "(defun c:color_swatch/COLOR_SWATCH/COLOR" (itoa (setq idx (1+ idx))) "#OnClicked ()"
            "(ColorButtonOnClick " (itoa idx) ")"
          ")"
        )
      )
    )
  )
  (dcl-LoadProject "color_swatch")
  (setq ret (dcl-Form-Show color_swatch/COLOR_SWATCH))
  (cond
    ((= 1000 ret) ; Exit.
      nil
    )
    ((= 0 ret)
     (progn
      (princ "\nByBlock")
      (command "color" "byblock")
      (c:lac_byblock)
    )
     )
    ((= 256 ret)
     (progn
      (princ "\nByLayer")
      (command "color" "bylayer")
      (c:lac_bylayer)
      )
    )

    (T
     (progn
         (princ "CSW menu loaded")
       )
     )
  );_cond
);_defun

;====
; making the layers
;====

(defun ColorButtonOnClick (idx)

    (dcl-Form-Close color_swatch/COLOR_SWATCH idx)
    (setq itoaidx (itoa idx))
    (setq rtosidx (rtos (float idx) 2 0))
    (if (not (tblsearch "layer" rtosidx))
    (progn
      (command "_.-Layer" "New" rtosidx "c" rtosidx rtosidx "")
      (princ(strcat "\nLayer \"" rtosidx "\"Created ."))
    )
    (princ "\nLayer Name Already exist.")
)
)


Title: Re: Create layer - can't get it to work..
Post by: Grrr1337 on February 10, 2017, 10:47:57 AM

You could try entmaking the layer instead of using command call:
Code - Auto/Visual Lisp: [Select]
  1. (defun EmakeLayer ( Nme )
  2.   (cond
  3.     ( (not (eq 'STR (type Nme))) (princ "\nString argument was not provided.") )
  4.     ( (not (snvalid Nme)) (princ "\nInvalid layer name was provided.") )
  5.     ( (tblsearch "LAYER" Nme) (princ (strcat "\nLayer \"" Nme "\" already exist.")) )
  6.     (
  7.       (entmake ; fragment taken from LM's entmake functions
  8.         (list
  9.           (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0)
  10.         )
  11.       )
  12.     )
  13.   ); cond
  14. ); defun
  15.  
And ofcourse determine the cause of the error.
Title: Re: Create layer - can't get it to work..
Post by: lamarn on February 10, 2017, 11:02:08 AM
Thanks for this 'blueprint'..! Think that is a good idea
Title: Re: Create layer - can't get it to work..
Post by: roy_043 on February 10, 2017, 02:05:20 PM
Hans, I think you should have mentioned that you are using this code in the context of an OpenDCL project, as that is most likely the reason for the problems you experience.

As I have already explained (here (http://www.opendcl.com/forum/index.php?topic=1945.msg12368#msg12368)) you cannot use command calls in event handlers for modal OpenDCL forms.

For modeless OpenDCL forms the Event Invoke property of controls must be set to Asynchronous if you want to use commands in their event handlers.
Title: Re: Create layer - can't get it to work..
Post by: lamarn on February 12, 2017, 05:20:03 PM
Yes, you are right Roy. I didn't think the fact that this code was used i opendcl had anything to do with it.
I've set it to be Asynchronous and then it works! Still i have some difficulties assigning colornumber to layers using entmod.
Can't get (cons 62 var. for color ) to work..

Therefore i decided to use a command call for now.

More details here:
http://www.opendcl.com/forum/index.php?topic=1945.msg12372#msg12372

Hope you like it, and thanks for commenting ;-)