Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Beginners' error

8 REPLIES 8
Reply
Message 1 of 9
ries
388 Views, 8 Replies

Beginners' error

Can someone help me. I'm having trouble reading the outcome of radio buttons into my lisp-script.
The radio buttons are located in the dcl-file and are to be read by the function defun buttons. But that doens't work...

Why doesn't this work....

Thnx in advance...

LISP:

(defun SEARCHHOME()
(setq FILE "C:/prestolisp/window.dcl")
(setq WELKOM "C:/prestolisp/welkom.dcl")
)

(defun EMPTY()
(COMMAND "-layer" "set" "0" "")
(COMMAND "-layer" "off" "bel" "")
(COMMAND "-layer" "off" "buitenband" "")
(COMMAND "-layer" "off" "buitenband1" "")
(COMMAND "-layer" "off" "buitenband2" "")
(COMMAND "-layer" "off" "defpoints" "")
(COMMAND "-layer" "off" "framebuizen" "")
(COMMAND "-layer" "off" "gsm-houderding" "")
(COMMAND "-layer" "off" "handvaten" "")
(COMMAND "-layer" "off" "hartlijnen" "")
(COMMAND "-layer" "off" "lagers" "")
(COMMAND "-layer" "off" "opklapbeugel" "")
(COMMAND "-layer" "off" "plank" "")
(COMMAND "-layer" "off" "reflector" "")
(COMMAND "-layer" "off" "rembordje" "")
(COMMAND "-layer" "off" "remhendel" "")
(COMMAND "-layer" "off" "remkabel" "")
(COMMAND "-layer" "off" "remveer" "")
(COMMAND "-layer" "off" "stuurpen" "")
(COMMAND "-layer" "off" "velg" "")
(COMMAND "-layer" "off" "velg1" "")
)

(defun FRAME()
(COMMAND "-layer" "set" "0" "")
(COMMAND "-layer" "on" "bel" "")
(COMMAND "-layer" "off" "buitenband" "")
(COMMAND "-layer" "off" "buitenband1" "")
(COMMAND "-layer" "off" "buitenband2" "")
(COMMAND "-layer" "on" "defpoints" "")
(COMMAND "-layer" "on" "framebuizen" "")
(COMMAND "-layer" "off" "gsm-houderding" "")
(COMMAND "-layer" "on" "handvaten" "")
(COMMAND "-layer" "on" "hartlijnen" "")
(COMMAND "-layer" "on" "lagers" "")
(COMMAND "-layer" "on" "opklapbeugel" "")
(COMMAND "-layer" "on" "plank" "")
(COMMAND "-layer" "on" "reflector" "")
(COMMAND "-layer" "on" "rembordje" "")
(COMMAND "-layer" "on" "remhendel" "")
(COMMAND "-layer" "on" "remkabel" "")
(COMMAND "-layer" "on" "remveer" "")
(COMMAND "-layer" "on" "stuurpen" "")
(COMMAND "-layer" "off" "velg" "")
(COMMAND "-layer" "off" "velg1" "")
)

(defun BUTTONS ()
(FRAME)
(action_tile "Velg1" (COMMAND "-layer" "on" "velg" ""))
(action_tile "Velg2" (COMMAND "-layer" "on" "velg1" ""))
)

(defun HELLO (/ dcl_id )
(setq dcl_id (load_dialog WELKOM))
(if (not (new_dialog "window" dcl_id) ) (exit))
(action_tile "accept" "(done_dialog)")
(start_dialog)
(unload_dialog dcl_id)
(princ)
)

(defun WIZARD (/ dcl_id )
(setq dcl_id (load_dialog FILE))
(if (not (new_dialog "window" dcl_id) ) (exit))
(start_dialog)
(BUTTONS)
(unload_dialog dcl_id)
(princ)
)

(defun c:main (/ dcl_id )
(SEARCHHOME)
(HELLO)
(EMPTY)
(WIZARD)
)

DCL:

window : dialog {
label = "Presto Step Wizard";
: text {
label = "Maak uw keuze";
}
: radio_column {
label = "Velg soort";
: radio_button {
label = "Velg 1";
mnemonic = "1";
key = "Velg1";
}
: radio_button {
label = "Velg 2";
mnemonic = "2";
key = "Velg2";
}
}
: column {
: row {
fixed_width = true;
alignment = centered;
ok_button;
: spacer { width = 2; }
key = "accept";
is_default = true;
fixed_width = true;
cancel_button;
key = "decline";
is_default = true;
fixed_width = true;
: spacer { width = 2; }
help_button;
}
}
}
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: ries


(defun WIZARD (/ dcl_id

  (FRAME) 
  (setq dcl_id (load_dialog
FILE)) 
  (if (not (new_dialog "window" dcl_id) )
(exit)) 
  (action_tile "Velg1" (COMMAND "-layer" "on" "velg"
"")) 
  (action_tile "Velg2" (COMMAND "-layer" "on" "velg1"
"")) 
  (action_tile "accept"
"(done_dialog)") 
  (start_dialog) 
  (unload_dialog
dcl_id)
  (princ) 
)


--
Jim Claypool

href="mailto:jclaypool@kc.rr.com">jclaypool@kc.rr.com


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Can
someone help me. I'm having trouble reading the outcome of radio buttons into
my lisp-script.
The radio buttons are located in the dcl-file and are to
be read by the function defun buttons. But that doens't work...

Why doesn't this work....

Thnx in advance...

LISP:

(defun SEARCHHOME()
  (setq FILE "C:/prestolisp/window.dcl")

  (setq WELKOM "C:/prestolisp/welkom.dcl")
)

(defun EMPTY()
        (COMMAND
"-layer" "set" "0" "")

        (COMMAND "-layer" "off"
"bel" "")
        (COMMAND
"-layer" "off" "buitenband" "")

        (COMMAND "-layer" "off"
"buitenband1" "")
        (COMMAND
"-layer" "off" "buitenband2" "")

        (COMMAND "-layer" "off"
"defpoints" "")
        (COMMAND
"-layer" "off" "framebuizen" "")

        (COMMAND "-layer" "off"
"gsm-houderding" "")

        (COMMAND "-layer" "off"
"handvaten" "")
        (COMMAND
"-layer" "off" "hartlijnen" "")

        (COMMAND "-layer" "off"
"lagers" "")
        (COMMAND
"-layer" "off" "opklapbeugel" "")

        (COMMAND "-layer" "off"
"plank" "")
        (COMMAND
"-layer" "off" "reflector" "")

        (COMMAND "-layer" "off"
"rembordje" "")
        (COMMAND
"-layer" "off" "remhendel" "")

        (COMMAND "-layer" "off"
"remkabel" "")
        (COMMAND
"-layer" "off" "remveer" "")

        (COMMAND "-layer" "off"
"stuurpen" "")
        (COMMAND
"-layer" "off" "velg" "")

        (COMMAND "-layer" "off"
"velg1" "")
)

(defun FRAME()
        (COMMAND
"-layer" "set" "0" "")

        (COMMAND "-layer" "on"
"bel" "")
        (COMMAND
"-layer" "off" "buitenband" "")

        (COMMAND "-layer" "off"
"buitenband1" "")
        (COMMAND
"-layer" "off" "buitenband2" "")

        (COMMAND "-layer" "on"
"defpoints" "")
        (COMMAND
"-layer" "on" "framebuizen" "")

        (COMMAND "-layer" "off"
"gsm-houderding" "")

        (COMMAND "-layer" "on"
"handvaten" "")
        (COMMAND
"-layer" "on" "hartlijnen" "")

        (COMMAND "-layer" "on"
"lagers" "")
        (COMMAND
"-layer" "on" "opklapbeugel" "")

        (COMMAND "-layer" "on"
"plank" "")
        (COMMAND
"-layer" "on" "reflector" "")

        (COMMAND "-layer" "on"
"rembordje" "")
        (COMMAND
"-layer" "on" "remhendel" "")

        (COMMAND "-layer" "on"
"remkabel" "")
        (COMMAND
"-layer" "on" "remveer" "")

        (COMMAND "-layer" "on"
"stuurpen" "")
        (COMMAND
"-layer" "off" "velg" "")

        (COMMAND "-layer" "off"
"velg1" "")
)

(defun BUTTONS ()
   (FRAME)

   (action_tile "Velg1" (COMMAND "-layer" "on" "velg" ""))

   (action_tile "Velg2" (COMMAND "-layer" "on" "velg1" ""))

)

(defun HELLO (/ dcl_id )
  (setq dcl_id (load_dialog WELKOM))

  (if (not (new_dialog "window" dcl_id) ) (exit))

  (action_tile "accept" "(done_dialog)")

  (start_dialog)
  (unload_dialog dcl_id)

  (princ)
)

(defun WIZARD (/ dcl_id )
  (setq dcl_id (load_dialog FILE))

  (if (not (new_dialog "window" dcl_id) ) (exit))

  (start_dialog)
  (BUTTONS)

  (unload_dialog dcl_id)
  (princ)
)

(defun c:main (/ dcl_id )
  (SEARCHHOME)

  (HELLO)
  (EMPTY)
  (WIZARD)
)

DCL:

window : dialog {
    label = "Presto Step Wizard";

: text {
label = "Maak uw keuze";
}
: radio_column {
label
= "Velg soort";
: radio_button {
label = "Velg 1";
mnemonic = "1";

key = "Velg1";
}
: radio_button {
label = "Velg 2";

mnemonic = "2";
key = "Velg2";
}
}

            :
column {
: row {
fixed_width = true;
alignment = centered;

ok_button;
: spacer { width = 2; }
key = "accept";
is_default
= true;
fixed_width = true;
cancel_button;
key = "decline";

is_default = true;
fixed_width = true;
: spacer { width = 2; }

help_button;
}
}
}

Message 3 of 9
ries
in reply to: ries

Tnx for willing to help me out here...Though AutoCAD pops up an error with you're resolution, wich I can't quite follow;

Command: error: incorrect request for command list data
(COMMAND "-layer" "on" "velg" "")
(ACTION_TILE "Velg1" (COMMAND "-layer" "on" "velg" ""))
(WIZARD)

Ries.
Message 4 of 9
Anonymous
in reply to: ries

Sorry, I didn't look far enough

 

Try this

 

(ACTION_TILE
"Velg1" "(COMMAND \"-layer\" \"on\" \"velg\" \"\")")



 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Tnx
for willing to help me out here...Though AutoCAD pops up an error with you're
resolution, wich I can't quite follow;

Command: error: incorrect request for command list data
(COMMAND
"-layer" "on" "velg" "")
(WIZARD)

Ries.

Message 5 of 9
Anonymous
in reply to: ries

Mr. Claypool's solution doesn't work because you cannot call the
(command ...) function while the dialog box is displayed. You could
temporarily hide the dialog box and then call (command ...), but that
is a lot of code and complexity that you should avoid if possible. You
really should not do anything when the radio button is picked ... you
should wait until the user picks OK.

Try the following.

DCL: (Note that I gave the radio column a key, and I gave each radio
button a key that is the name of the layer to turn on)

window : dialog {
label = "Presto Step Wizard";
: text {
label = "Maak uw keuze";
}
: radio_column {
label = "Velg soort";
key = "LayerName";
: radio_button {
label = "Velg";
mnemonic = "V";
key = "Velg";
}
: radio_button {
label = "Velg 1";
mnemonic = "1";
key = "Velg1";
}
}
ok_cancel;
}

(defun WIZARD (/ dcl_id LayerToTurnOn)
(setq dcl_id (load_dialog FILE))
(if (not (new_dialog "window" dcl_id) ) (exit))
;; Make sure a radio button is selected
(set_tile "LayerName" "Velg")
(action_tile "accept" "(WizardOKCallBack)")
;; If the user picks OK ...
(if (= 1 (start_dialog))
;; Then do the layer settings
(progn
(Frame)
(LayerOn LayerToTurnOn)
)
)
(unload_dialog dcl_id)
(princ)
)

(defun WizardOKCallBack ()
;; Collect the state of the dialog box. It is simple
;; because I chose a good key for each radio button.
(setq LayerToTurnOn (get_tile "LayerName"))
;; The argument of done_dialog will re-surface
;; later as the return value of start_dialog.
;; The default action for the Cancel button is
;; (done_dialog 0)
(done_dialog 1)
)

;;; Turn a layer on. Safe to call while a dialog box is
;;; active.
(defun LayerOn (LayerName / EntityList EntityName EntityColor)
;; If the layer exists ...
(if (setq EntityName (tblobjname "LAYER" LayerName))
(progn
;; Get the Entity Association List and the layer's color
(setq EntityList (entget EntityName)
EntityColor (cdr (assoc 62 EntityList))
)
;; If the color is negative, the layer is off.
;; Set the color to a positive value
(entmod
(list (assoc -1 EntityList) (cons 62 (abs EntityColor)))
)
)
;; If the layer doesn't exist, tell the user
(alert (strcat "Layer \""
LayerName
"\" does not exist."
)
)
)
)

Your EMPTY and FRAME functions probably cause a lot of screen
flickering. Faster and easier is:

(defun Frame ()
;; A "." in front of a command name makes it work even if
;; someone has redefined the command. A "_" in front of
;; a command or option name makes it work in non-English
;; versions of AutoCAD
;; Start the layer command but DON'T end it
(command "._-layer" "_set" "0")
(foreach LayerName '("bel" "defpoints" "framebuizen" "handvaten"
"hartlijnen" "lagers" "opklapbeugel" "plank"
"reflector" "rembordje" "remhendel" "remkabel"
"remveer" "stuurpen"
)
(command "_on" LayerName)
)
(foreach LayerName '("buitenband" "buitenband1" "buitenband2"
"gsm-houderding" "velg" "velg1"
)
(command "_off" LayerName)
)
;; End the command
(command "")
;; No return value
(prin1)
)


jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

In article , Ries wrote:
> Can someone help me. I'm having trouble reading the outcome of radio
> buttons into my lisp-script.
> The radio buttons are located in the
> dcl-file and are to be read by the function defun buttons. But that
> doens't work...
> Why doesn't this work....
> Thnx in advance...
>
> LISP:
> (defun SEARCHHOME()
> (setq FILE
> "C:/prestolisp/window.dcl")
> (setq WELKOM
> "C:/prestolisp/welkom.dcl")
> )
> (defun EMPTY()
> (COMMAND
> "-layer" "set" "0" "")
> (COMMAND "-layer" "off" "bel" "")
>
> (COMMAND "-layer" "off" "buitenband" "")
> (COMMAND
> "-layer" "off" "buitenband1" "")
> (COMMAND "-layer" "off"
> "buitenband2" "")
> (COMMAND "-layer" "off" "defpoints" "")
>
> (COMMAND "-layer" "off" "framebuizen" "")
> (COMMAND
> "-layer" "off" "gsm-houderding" "")
> (COMMAND "-layer"
> "off" "handvaten" "")
> (COMMAND "-layer" "off" "hartlijnen"
> "")
> (COMMAND "-layer" "off" "lagers" "")
>
> (COMMAND "-layer" "off" "opklapbeugel" "")
>
> (COMMAND "-layer" "off" "plank" "")
> (COMMAND
> "-layer" "off" "reflector" "")
> (COMMAND "-layer" "off"
> "rembordje" "")
> (COMMAND "-layer" "off" "remhendel" "")
>
> (COMMAND "-layer" "off" "remkabel" "")
> (COMMAND
> "-layer" "off" "remveer" "")
> (COMMAND "-layer" "off"
> "stuurpen" "")
> (COMMAND "-layer" "off" "velg" "")
>
> (COMMAND "-layer" "off" "velg1" "")
> )
> (defun FRAME()
>
> (COMMAND "-layer" "set" "0" "")
> (COMMAND "-layer"
> "on" "bel" "")
> (COMMAND "-layer" "off" "buitenband" "")
>
> (COMMAND "-layer" "off" "buitenband1" "")
> (COMMAND
> "-layer" "off" "buitenband2" "")
> (COMMAND "-layer" "on"
> "defpoints" "")
> (COMMAND "-layer" "on" "framebuizen" "")
>
> (COMMAND "-layer" "off" "gsm-houderding" "")
>
> (COMMAND "-layer" "on" "handvaten" "")
> (COMMAND
> "-layer" "on" "hartlijnen" "")
> (COMMAND "-layer" "on"
> "lagers" "")
> (COMMAND "-layer" "on" "opklapbeugel" "")
>
> (COMMAND "-layer" "on" "plank" "")
> (COMMAND
> "-layer" "on" "reflector" "")
> (COMMAND "-layer" "on"
> "rembordje" "")
> (COMMAND "-layer" "on" "remhendel" "")
>
> (COMMAND "-layer" "on" "remkabel" "")
> (COMMAND
> "-layer" "on" "remveer" "")
> (COMMAND "-layer" "on"
> "stuurpen" "")
> (COMMAND "-layer" "off" "velg" "")
>
> (COMMAND "-layer" "off" "velg1" "")
> )
> (defun BUTTONS ()
>
> (FRAME)
> (action_tile "Velg1" (COMMAND "-layer" "on" "velg"
> ""))
> (action_tile "Velg2" (COMMAND "-layer" "on" "velg1" ""))
>
> )
> (defun HELLO (/ dcl_id )
> (setq dcl_id (load_dialog WELKOM))
>
> (if (not (new_dialog "window" dcl_id) ) (exit))
> (action_tile
> "accept" "(done_dialog)")
> (start_dialog)
> (unload_dialog
> dcl_id)
> (princ)
> )
> (defun WIZARD (/ dcl_id )
> (setq dcl_id
> (load_dialog FILE))
> (if (not (new_dialog "window" dcl_id) )
> (exit))
> (start_dialog)
> (BUTTONS)
> (unload_dialog dcl_id)
>
> (princ)
> )
> (defun c:main (/ dcl_id )
> (SEARCHHOME)
>
> (HELLO)
> (EMPTY)
> (WIZARD)
> )
> DCL:
> window : dialog {
>
> label = "Presto Step Wizard";
> : text {
> label = "Maak uw
> keuze";
> }
> : radio_column {
> label = "Velg soort";
> :
> radio_button {
> label = "Velg 1";
> mnemonic = "1";
> key =
> "Velg1";
> }
> : radio_button {
> label = "Velg 2";
> mnemonic =
> "2";
> key = "Velg2";
> }
> }
> : column {
> : row {
>
> fixed_width = true;
> alignment = centered;
> ok_button;
> : spacer
> { width = 2; }
> key = "accept";
> is_default = true;
> fixed_width
> = true;
> cancel_button;
> key = "decline";
> is_default = true;
>
> fixed_width = true;
> : spacer { width = 2; }
> help_button;
> }
> }
>
> }
>
Message 6 of 9
ries
in reply to: ries

What I really don't understand I the fact that every other program uses an If-statement is this case. And all the above mentioned options don't have them....I mean, I had this in mind:

If layertoturnon = 1, then show layer x, y and z

Basically this should do the program I trying to write.

Why is that? That in programs like Visual Basic and C++ this is different to LISP???

And why is it when I try to recall the value of !layertoturnon within autocad, it show nil. Also something I don't wuite get, since this value should have a value when it has been chosen through the radio_button...

Tnx for u're help....

Ries.
Message 7 of 9
Anonymous
in reply to: ries

In article , Ries wrote:
> What I really don't understand I the fact that every other program
> uses an If-statement is this case.

My program used an if statement ... if the user presses "OK", carry out
the task.

>And all the above mentioned
> options don't have them....I mean, I had this in mind:
> If
> layertoturnon = 1, then show layer x, y and z

In my program, "LyerToTurnOn" is a string that contains the key of the
selected radio button, which happens to be the name of the layer to
turn on. If you want to turn on more than one layer, there are several
ways of doing it. You could put the names of the layers to turn in a
list (just using a setq at the beginning of the program), then make
LayerToTurnOn contain the name of the variable that contains that list,
then make the LayerOn function accept a lit of layers instead of one
layer name.

> Basically this
> should do the program I trying to write.
> Why is that? That in
> programs like Visual Basic and C++ this is different to LISP???

Well, LISP works differently from VBA or C++, and Visual LISP dialog
boxes work differently from other LISPs. However, any dialog box
function in any language should follow the same general plan:

Allow the user to make changes and entries but DO NOT do anything to
the drawing or global settings until the user presses "OK".


> And why is it when I try to recall the value of !layertoturnon
> within autocad, it show nil. Also something I don't wuite get, since
> this value should have a value when it has been chosen through the
> radio_button...

Look at the line "(defun WIZARD (/ dcl_id LayerToTurnOn)". The
variables named after the "/" are "local variables". They are only
defined while the wizard function (and any functions it calls) is
running. If you remove LayerToTurnOn from that line, LayerToTurnOn
will have a value after wizard finishes. However, it's good
programming practice to use local variables and not leave garbage lying
around. You can use the Visual LISP Watch Window and breakpoints to
watch the values of variables while the program is running.

> Tnx for u're help....
> Ries.
>

jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services
Message 8 of 9
Anonymous
in reply to: ries

Direct, to the point, and ice cold.

--

Bill DeShawn
bdeshawn@prodigy.net
http://pages.prodigy.net/bdeshawn/bdeshawn.htm

> Please do not email questions unless you wish to hire my services
Message 9 of 9
Anonymous
in reply to: ries

In article ,
William J Deshawn wrote:
> Direct, to the point, and ice cold.

Indeed. Also not noticed or understood by a few.

jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost