TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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?
-
Have you tried :
(setq rtosidx (rtos (float idx) 2 0))
-
Have you checked sysvar QAFLAGS... Should be set to 0...
HTH.
-
Try with
(command "_.-Layer" ...)
-
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..
(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)
)
;====
;------ 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.")
)
)
-
You could try entmaking the layer instead of using command call:
(defun EmakeLayer
( Nme
) ( (not (eq 'STR
(type Nme
))) (princ "\nString argument was not provided.") ) (
(entmake ; fragment taken from LM's entmake functions (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme
) (cons 70 0) )
)
)
); cond
); defun
And ofcourse determine the cause of the error.
-
Thanks for this 'blueprint'..! Think that is a good idea
-
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.
-
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 ;-)