Help with Global Variable from Edit_Box

Help with Global Variable from Edit_Box

cbenner
Mentor Mentor
970 Views
3 Replies
Message 1 of 4

Help with Global Variable from Edit_Box

cbenner
Mentor
Mentor

Good morning,

 

At this point in my code, all I am trying to do is get user input in an edit_box in my dcl, and pass it to a global variable.  That's it.  Not trying to use that variable for anything yet... just capture it.  No matter what I try I get some sort of an error, mostly ; error: bad argument type: stringp nil, when trying to view Alert the value.

 

Eventually I will be using this with a block attribute increment program.  I found that code in these forums and it works great.... but I need to be able to use these global variables.

 

My dcl and lsp are attached, would someone have time to take a peek?  TIA!!

0 Likes
Accepted solutions (1)
971 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor

RE: pnum itinc etinc ltinc

To use these as global variables, don't localize them.

Change the first line of your code

from:

(defun C:setup ( pnum itinc etinc ltinc / )

to:

(defun C:setup ( )

 

Then load Dwg_Setup.lsp again

At the command prompt enter:

SETUP

 

Now the dialog should come up.

 

Go ahead & make some changes to the entries and click OK.

 

Now to see if the variables get set, at the command prompt precede each variable with an ! exclamation mark:

!pnum 

!itinc 

!etinc

!ltinc 

 

PS: As a convention, I would match the new lisp command name to the same as the file name ie:

(defun C:Dwg_setup ( )

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

1. In the DCL the kay values should have been strings

DWG_Setup : dialog {				//dialog name
    label = "P&ID Drawing Setup" ;	        //give it a label

    : row {					//*define row

        : edit_box { label = "Process Number"; key = "prnum"; width = 7; value = "100"; }
	: edit_box { label = "Inst Tag Incr"; key = "ininc"; width = 7; value = "1"; }
	: edit_box { label = "Equip Tag Incr"; key = "eqinc"; width = 7; value = "5"; }
	: edit_box { label = "Line Tag Incr"; key = "liinc"; width = 7; value = "10"; }
    }
    ok_cancel ;				        //predifined OK/Cancel

}					        //end dialog

2. You're talking about assigning global variable, but you're using the same symbols as the arguments of the function (that you never use in the code)

 

3. You do not need the (set_tile ...) statements in the LISP if you used Value = ... in the DCL

 

4. You should not have any expression after (done_dialog), use the value returned by start_dialog instead of userclick)

 

(defun C:setup (/ p i e l status)

  (setq dcl_id (load_dialog "DWG_setup.dcl"))
  (if (not (new_dialog "DWG_Setup" dcl_id))
    (exit)
  )

  (action_tile "prnum" "(setq p $value)")
  (action_tile "ininc" "(setq i $value)")
  (action_tile "eqinc" "(setq e $value)")
  (action_tile "liinc" "(setq l $value)")
  (action_tile "cancel" "(done_dialog 0)")
  (action_tile "accept" "(done_dialog 1)")

  (setq status (start_dialog))
  (unload_dialog dcl_id)

  ;; if the user clicked OK (done_dialog 1)
  ;; set the global variables
  (if (= status 1)
    (setq pnum p
          itinc i
          etinq e
          ltinc l
          userclick T
    )
    (setq userclick nil)
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

cbenner
Mentor
Mentor

@_gile wrote:

Hi,

 

1. In the DCL the kay values should have been strings

 

Thanks for that, I knew that and looked right at it, and didn't see it.  More coffee needed?

 

2. You're talking about assigning global variable, but you're using the same symbols as the arguments of the function (that you never use in the code)

 

That's because I don't know what I'm doing.  Smiley Wink

 

3. You do not need the (set_tile ...) statements in the LISP if you used Value = ... in the DCL

 

4. You should not have any expression after (done_dialog), use the value returned by start_dialog instead of userclick)

 

The code you modified works very nicely.  Thank you for the help.  I haven't done any kind of lisp in 25 years.  I like to try what I can first, and then ask for help when I get very lost.  I learn a lot from you guys who do this all the time.  SO, thank you!

 

 

0 Likes