Stair Calculator dcl assistance

Stair Calculator dcl assistance

DC-MWA
Collaborator Collaborator
3,183 Views
13 Replies
Message 1 of 14

Stair Calculator dcl assistance

DC-MWA
Collaborator
Collaborator

I have a cool stair calculation routine and I'm trying to add some dialog interface to.

I'm close but can't figure out what I'm missing.

As always, forgive my "Franken-lisp" programming.

I have attached the original lisp (no dialog) called "stca.lsp" so you can see what it does.

I have also attached the new "staircalc.lsp" and "staircalc.dcl" that I have so far. My tests using print seem to pass the numbers but I cannot get it function. I get an error message "bad argument type: numberp: nil".

Thanks in advance for your assistance.

0 Likes
Accepted solutions (1)
3,184 Views
13 Replies
Replies (13)
Message 2 of 14

dbhunia
Advisor
Advisor

Hi

 

Try with this Code.......(Only few modification.....).... But in your code "enter" is required in every "text box" to get the values into variables....

 


@DC-MWA wrote:

I have a cool stair calculation routine and I'm trying to add some dialog interface to.

I'm close but can't figure out what I'm missing.

As always, forgive my "Franken-lisp" programming.

I have attached the original lisp (no dialog) called "stca.lsp" so you can see what it does.

I have also attached the new "staircalc.lsp" and "staircalc.dcl" that I have so far. My tests using print seem to pass the numbers but I cannot get it function. I get an error message "bad argument type: numberp: nil".

Thanks in advance for your assistance.


 

This error message is due to when you getting the value from text box, the value is "string" type so you need to convert those into Integer/Float to do Mathematical calculations........


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 14

DC-MWA
Collaborator
Collaborator

Not sure what you mean or how to solve the "enter required" portion.

 

I tried using atoi on the string, now i get

"bad argument type: stringp nil"

 

0 Likes
Message 4 of 14

dbhunia
Advisor
Advisor

Hi

 

You just use the attached .LSP file.......of my previous attachment........(Some modification is there) and use your .DCL file....

 

when the dialog box appears......given below...

 

Capture.PNG

 

According to your Code you have to hit enter into each input box...... Here you have to hit enter after each entry (means 10+enter, 7+enter, 11+enter then press okay).....

 

Try like this.....

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 14

DC-MWA
Collaborator
Collaborator

Well that gets closer and reaches the test portion...

How do I get rid of the need to hit enter?

 

Also, I do not know where to convert string to int.

 

"test: Floor to Floor= 12'  Riser= 7  Tread= 11" bad argument type: numberp: "12'"

0 Likes
Message 6 of 14

DC-MWA
Collaborator
Collaborator

Ok I got past the enter issue.

0 Likes
Message 7 of 14

DC-MWA
Collaborator
Collaborator

Atoi seems like the way to go with this but I do not where to address this. It seems that the do_work portion does this already.

 

0 Likes
Message 8 of 14

dbhunia
Advisor
Advisor

Hi

 

As you asked.....

 


@DC-MWA wrote:

I have a cool stair calculation routine and I'm trying to add some dialog interface to.

I'm close but can't figure out what I'm missing.

As always, forgive my "Franken-lisp" programming.

I have attached the original lisp (no dialog) called "stca.lsp" so you can see what it does.

I have also attached the new "staircalc.lsp" and "staircalc.dcl" that I have so far. My tests using print seem to pass the numbers but I cannot get it function. I get an error message "bad argument type: numberp: nil".

Thanks in advance for your assistance.


 

So after runntng your "stca.lsp" i got this........

 

My input was.....

Capture1.PNG

 

And output was .....

Capture2.PNG

 

So according to your need I made the necessary changes (Type conversion of input data getting from DCL) in your code in "do_work" function......After that when I run the "staircalc.lsp"......

 

My input was.....

Capture3.PNG

 

And output was .....

Capture4.PNG

 

Both output are same......as you needed....

 

So if you go through your function "do_work" in code, you will get the changes I made .........Basically Type conversion of input data getting from DCL to do desire calculations.......

Also I made some changes in your function "staircalc"....... Check the function.......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 14

DC-MWA
Collaborator
Collaborator

We're so close...

See attached image describing minor issues.

Thank you for your assistance.

 

0 Likes
Message 10 of 14

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

To get Feet-Inch input in "Floor to Floor Ht".........Try this........

 

(defun do_work(/ );ftof riser tread steps steps2 run txtpt)
;;do work

(setq oldlayer (getvar "clayer"))
(setq oldtextsz (getvar "textsize"))
(command ".-layer" "make" "A-ANNO-STRS-CALC" "C" "2" "" "")

(setq flr2flr (distof flr2flr 4));String convertion

(setq steps (atoi (rtos (/ flr2flr (atof riser)) 2)))
(if (> (rem flr2flr (atof riser)) 0) (setq steps (1+ steps)))
(setq riser (/ flr2flr steps))
(setq steps2 (1- steps))
(setq run (* steps2 (atof tread)))

(setvar "textsize" (* (getvar "dimscale") 0.8334))
(setq txtpt (getpoint "\nSelect location for calculations:"))
(command "text" txtpt "" "0.0" "%%uSTAIR DATA: ")
(command "text" "" (strcat "Total Rise = "(rtos flr2flr 4 5)))
(command "text" "" (strcat (itoa steps) " Risers @ " (rtos riser 5 5) "\"")) 
(command "text" "" (strcat (itoa steps2) " Treads @ " (rtos (atoi tread) 5 5) "\""))
(command "text" "" (strcat "Total Run is " (rtos run 4 5)))

(setvar "clayer" oldlayer)
(setvar "textsize" oldtextsz)
(setvar "cmdecho" 1)
(princ "\nCalculations complete.")
)

Rest your calculation part ......... hopefully you can take care of it........

 

And check this.......http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-A38E30D4-684E-44FA-A910-E08522876414


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 11 of 14

DC-MWA
Collaborator
Collaborator

Here is the final product.

Awesome!

Thanks again!

Capture.JPG

0 Likes
Message 12 of 14

scot-65
Advisor
Advisor

>> How do I get rid of the need to hit enter?

 

@Anonymous-WMA and others reading this...

 

Setting a user defined variable at the time of tile selection will not seamlessly
work on an edit_box. For this, we have to restructure our thoughts and come up
with a better solution that not only gathers the present state of ALL the tiles
in the dialog, but also allows one to perform tests to ensure the user input is
correct. When the user input is incorrect, issue an alert (which prevents the
dialog from closing):

 (action_tile "accept" "(if (XXX_GET) (done_dialog 1))")


Where the following function is placed somewhere ABOVE "new_dialog" and not
buried inside a PROGN, COND, WHILE or any other function other than another DEFUN:

 (vl-load-com)

 (defun XXX_GET ( / eb1 )
  ;first get the tile's value and remove any leading and trailing spaces.
  ;optional is to also remove any undesired leading/trailing characters (such as ', " or .).
  ;it is assumed that the edit_box has been initiated a value in the "set_tile"
  ;area (between "new_dialog" and "start_dialog").

  (if (setq eb1 (get_tile "Edit_Box_1")) (setq eb1 (vl-string-trim " " eb1)))

  ;now, enter a COND and perform necessary tests.
  ;if one of the tests is true, mode_tile the edit box and alert user [in this order].

  (cond
   ;<not eb1> tile was not initiated. this is an unacceptable dialog execution.
   (<test eb1 for empty string (STRLEN)> (mode_tile "Edit_Box_1" 2) (alert "Please enter a value."))
   (<test eb1 for not a real [or not an integer] (DISTOF)> ...mode_tile and alert)
   (<test eb1 for illegal characters if file or folder naming (SNVALID)> ...mode_tile and alert)
   (<test eb1 for other characters not allowed (WCMATCH)> ...mode_tile and alert)
   (<test eb1 for only lower case letters, etc. (ASCII)> ...mode_tile and alert)
   (<test eb1 for minimum or maximum number of characters, etc. (STRLEN)> ...mode_tile and alert)
   (<test eb1 for minimum and/or maximum real or integer values (< #1 eb1 #2)> ...mode_tile and alert)
   (<test eb1 if layer name does not exist (TBLSEARCH)> ...mode_tile and alert)
   (<test eb1 if linetype is not loaded (TBLSEARCH)> ...mode_tile and alert)
   (<other tests to eb1 as required> ...mode_tile and alert)
   (T (setq MyVariable eb1)) ;all is OK.
  );cond

 );defun


Alert returns nil - which will not cause the done_dialog to execute where
action_tile accept. The dialog remains open and the incorrect edit box is
highlighted (after the user presses the "OK" button inside the issued alert).


Other Notes:
- (atoi "a") returns 0.
- (atoi "0") returns 0 ...ATOI is not the most desirable test to determine if integer.
- Where possible, employ a list_box, popup_list, or radio_button in lieu of an edit_box.
- Do not "talk to" a radio_button. Instead, assign a key to the radio_column or
  radio_row and get_tile the radio_column or radio_row for the value. Set_tile
  the radio_column or radio_row will also work in this manner.

The objective of the dialog box is to gather user input. Once the dialog's state
has been recorded, proceed to the "Main Program" of the utility and interpret the
values that have been gathered (GET) from the dialog box.
- By setting user defined variables at the time of tile selection, the ability
  to restore the dialog's state after the Cancel button is pressed is lost.
- By recording the dialog's state when the OK button is pressed, restoring the
  dialog to the previous state the next time the utility is run can be achieved.
- Action_tile other than "accept" "cancel" and "help" shall only be used to
  manipulate the dialog's behavior (start_image, start_list, set_tile, mode_tile,
  etc.) or switching to another dialog.

Further down the thread list you posted a revised LSP. Inside there is

no initializing of any of the edit boxes. A simple (set_tile "EditBox1" "")

may be used as a minimum.

 

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 13 of 14

Jonathan3891
Advisor
Advisor

This is cool. Can you share the finished product?


Jonathan Norton
Blog | Linkedin
0 Likes
Message 14 of 14

DC-MWA
Collaborator
Collaborator

Here you go. Enjoy!

0 Likes