Author Topic: Create layer - can't get it to work..  (Read 1628 times)

0 Members and 1 Guest are viewing this topic.

lamarn

  • Swamp Rat
  • Posts: 636
Create layer - can't get it to work..
« 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?



Design is something you should do with both hands. My 2d hand , my 3d hand ..

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Create layer - can't get it to work..
« Reply #1 on: February 10, 2017, 10:04:14 AM »
Have you tried :
(setq rtosidx (rtos (float idx) 2 0))
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Create layer - can't get it to work..
« Reply #2 on: February 10, 2017, 10:19:03 AM »
Have you checked sysvar QAFLAGS... Should be set to 0...

HTH.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Create layer - can't get it to work..
« Reply #3 on: February 10, 2017, 10:23:02 AM »
Try with
Code: [Select]
(command "_.-Layer" ...)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

lamarn

  • Swamp Rat
  • Posts: 636
Re: Create layer - can't get it to work..
« Reply #4 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.")
)
)


« Last Edit: February 10, 2017, 10:46:32 AM by lamarn »
Design is something you should do with both hands. My 2d hand , my 3d hand ..

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Create layer - can't get it to work..
« Reply #5 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.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

lamarn

  • Swamp Rat
  • Posts: 636
Re: Create layer - can't get it to work..
« Reply #6 on: February 10, 2017, 11:02:08 AM »
Thanks for this 'blueprint'..! Think that is a good idea
Design is something you should do with both hands. My 2d hand , my 3d hand ..

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create layer - can't get it to work..
« Reply #7 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) 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.

lamarn

  • Swamp Rat
  • Posts: 636
Re: Create layer - can't get it to work..
« Reply #8 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 ;-)
Design is something you should do with both hands. My 2d hand , my 3d hand ..