Jump to content

Recall inputs in DCL, LISP


joemcanciller

Recommended Posts

Hi there! I am exploring lisp and dcl at the same time.

I have this DCL as shown below. Whenever the command is done and doing the same command again, values reset (pic2).

I want the values to remain whenever I used the dcl again after I press "Ok" to edit particular inputs instead of typing the whole data again. How could I possibly do that?

pic3.JPG.2652697aab4c7be6d1b24138480271bf.JPGpic4.JPG.97df3f2b9f7b84a8d64def88cee91f2e.JPG

 

Here is the dcl code I used.
 

CHECKING : dialog { 
          label = "CHECKING"; 
            : row {
		:boxed_row {
			label = "PARAMETERS";
			: edit_box { key = "a"; label = "Wind Pressure (kPa)"; edit_width = 8;}
			: edit_box {key = "b"; label = "Tributary Width (mm)"; edit_width = 8;}
			: edit_box {key = "c"; label = "Unsupported Length (mm)"; edit_width = 8;}
			      }
		}
	    : row {
		:boxed_column {
			label = "SECTION PROPERTIES (ALUMINUM)";
			: edit_box { key = "d"; label = "Moment of Inertia (mm^4)"; edit_width = 8;}
			: edit_box {key = "e"; label = "Area (mm^2)"; edit_width = 8;}
			: edit_box {key = "f"; label = "Extreme Fiber (mm)"; edit_width = 8;}
			: edit_box {key = "g"; label = "Allowable Stress (MPa)"; edit_width = 8;}			
			      }
		:boxed_column {
			label = "SECTION PROPERTIES (STEEL)";
			: edit_box { key = "h"; label = "Moment of Inertia (mm^4)"; edit_width = 8;}
			: edit_box {key = "i"; label = "Area (mm^2)"; edit_width = 8;}
			: edit_box {key = "j"; label = "Extreme Fiber (mm)"; edit_width = 8;}
			: edit_box {key = "k"; label = "Allowable Stress (MPa)"; edit_width = 8;}			
			      }
		}
		: button {
                key = "accept";
                label = " &OK ";
                is_default = true;
		mnemonic = "S";
              }
              : button {
                key = "cancel";
                label = " Cancel ";
                is_default = false;
                is_cancel = true;
              }


}

 

and here is the lisp code:

 

(defun saveVars()
	(setq wp(distof(get_tile "a")))
	(setq tw(distof(get_tile "b")))
	(setq L(distof(get_tile "c")))
	(setq Im(distof(get_tile "d")))
	(setq Am(distof(get_tile "e")))
	(setq cm(distof(get_tile "f")))
	(setq Fbm(distof(get_tile "g")))
	(setq Is(distof(get_tile "h")))
	(setq As(distof(get_tile "i")))
	(setq cs(distof(get_tile "j")))
	(setq Fbs(distof(get_tile "k")))
)

(defun C:CC()
	 
  	(if(not(setq dcl_id (load_dialog "CHECKING.dcl")))
    		(progn
      			(alert "The DCL file could not be loaded!")
      			(exit)
    		) 
   		(progn
      			(if (not(new_dialog "CHECKING" dcl_id))
        			(progn
       					(alert "CHECKING.DCL file could not be loaded!")
          				(exit)
       				)
       				(progn    						
         				(action_tile "accept" "(saveVars)(done_dialog 2)")
          				(action_tile "cancel" "(done_dialog 1)")
					(setq ddiag(start_dialog))
					(unload_dialog dcl_id)
					(if(= ddiag 1)
            				(princ "\n END")
					)
        		 		(if(= ddiag 2)
            					(progn
							(setq IT(+ Im (* 2.87 Is)))
							(setq moment(/ (* wp tw L L) 8000))
							(setq stress(/ (* moment cm) Im))
							(setq stressratio(/ stress Fbm))							
							(setq deflection(/ (* 5 wp tw L L L L) (* 384000 69600 IT))) 
							(setq allowdeflection(/ L 175))
							(setq defratio(/ deflection allowdeflection))
							(setq pt1 (getpoint))
							(setq pt2 (getpoint))
							(command "_mtext" pt1 pt2 "\n Actual Bending Stress =" (rtos stress 2 2)
									"\n Allowable Bending Stress =" (rtos Fbm 2 2)
									"\n Stress Ratio =" (rtos stressratio 2 2)
									"\n Actual Deflection =" (rtos deflection 2 2)
									"\n Allowable Deflection =" (rtos allowdeflection 2 2)
									"\n Deflection Ratio =" (rtos defratio 2 2) ""
							)
						)	
       		 			)
        			)
      			)
		)
	)
)

 

 

One more thing. About the mtext output. The output is this. Numerical results always appear on the next line.

pic5.JPG.b0d3c2a16ebac39309ce2b92e259f471.JPG

 

 

and I want the result to be like this with units as text (MPa, mm, etc)

 

pic6.JPG.be6ccc56771adc11b6925ba71c299cb4.JPG

 

Does someone has a thing about this? Thank you in advance. :)

 

Link to comment
Share on other sites

2 hours ago, joemcanciller said:

Another one. The label in dcl with mm^4 and mm^2, how to do superscript without the "^" sign. I can't find it in web. 😮

 

dcl is very limited so probably not possible , haven't looked into it.

Just a quickfix , haven't got much time at this moment


(defun C:CC  () ; normally you would declare all your variables here
  (if (not(setq dcl_id (load_dialog "CHECKING.dcl")))
    (progn (alert "The DCL file could not be loaded!") (exit))
    (progn (if (not (new_dialog "CHECKING" dcl_id))
             (progn (alert "CHECKING.DCL file could not be loaded!") (exit))
             (progn (cc_set_tiles);;; added this to set your variables
                    (action_tile "accept" "(saveVars)(done_dialog 2)")
                    (action_tile "cancel" "(done_dialog 1)")
                    (setq ddiag (start_dialog))
                    (unload_dialog dcl_id)
                    (if (= ddiag 1)
                      (princ "\n END"))
                    (if (= ddiag 2)
                      (progn (setq IT (+ Im (* 2.87 Is)))
                             (setq moment (/ (* wp tw L L) 8000))
                             (setq stress (/ (* moment cm) Im))
                             (setq stressratio (/ stress Fbm))
                             (setq deflection (/ (* 5 wp tw L L L L) (* 384000 69600 IT)))
                             (setq allowdeflection (/ L 175))
                             (setq defratio (/ deflection allowdeflection))
                             (setq pt1 (getpoint "\nGet 1st point : "))
                             (setq pt2 (getcorner pt1 "\nGet 2nd point : "))
                             (setq msg (strcat "\nActual Bending Stress = "
                                               (rtos stress 2 2)
                                               "\nAllowable Bending Stress = "
                                               (rtos Fbm 2 2)
                                               "\nStress Ratio = "
                                               (rtos stressratio 2 2)
                                               "\nActual Deflection = "
                                               (rtos deflection 2 2)
                                               "\nAllowable Deflection = "
                                               (rtos allowdeflection 2 2)
                                               "\nDeflection Ratio = "
                                               (rtos defratio 2 2)))
                             (apply 'vl-cmdf (list "_mtext" pt1 pt2 msg "")))))))))


; tl = tile list / vl = variable list
(defun cc_set_tiles ( / tl vl)
  (mapcar '(lambda (x y)  (set_tile x (if (null (vl-symbol-value y)) "" (vl-princ-to-string (vl-symbol-value y)))))
           (list "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k") (list 'wp 'tw 'L 'Im 'Am 'cm 'Fbm 'Is 'As 'cs 'Fbs))
)

Link to comment
Share on other sites

Rlx was faster, anyway heres another way:

 


(defun C:CC ( / ) ; like Rlx said, normally you would declare all your variables here
  
  ;; This subfunction will get all the tile's values and will return an association list of (<desired symbol> <tile's value>)
  ;; The list will look like this:
  ;; ((WP "<value_a>") (TW "<value_b>") (L "<value_c>") (IM "<value_d>") (AM "<value_e>") (CM "<value_f>") (FBM "<value_g>") (IS "<value_h>") (AS "<value_i>") (CS "<value_j>") (FBS "<value_k>"))
  (defun SaveVars ()
    (mapcar 'list '(wp tw L Im Am cm Fbm Is As cs Fbs)
      (mapcar '(lambda (x) (distof (get_tile (strcase (vl-symbol-name x) t))))
        '(a b c d e f g h i j k)
      )
    )
  ); defun SaveVars
  
  ;; (exit) function will interrupt the whole routine, so you don't need nested wrapping of (if <...> (progn <...>))
  (if (not (setq dcl_id (load_dialog "CHECKING.dcl")))
    (progn
      (alert "The DCL file could not be loaded!")
      (exit)
    ) 
  )
  (if (not (new_dialog "CHECKING" dcl_id))
    (progn
      (alert "CHECKING.DCL file could not be loaded!")
      (exit)
    )
  )
  
  ;; check if our list is present and set default values for the tiles
  (if *MyList* 
    (foreach x (mapcar 'cons '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k") *MyList*)
      (set_tile (car x) (caddr x))
    ); foreach 
  ); if
  
  ;; Normaly (done_dialog 1) stands for "accept" and (done_dialog 0) stands for "cancel"
  (action_tile "accept" 
    (strcat
      ;; All the variables are stored into an association list
      ;; the list looks like this:
      ;; ((WP "<value_a>") (TW "<value_b>") (L "<value_c>") (IM "<value_d>") (AM "<value_e>") (CM "<value_f>") (FBM "<value_g>") (IS "<value_h>") (AS "<value_i>") (CS "<value_j>") (FBS "<value_k>"))
      "(setq *MyList* (saveVars))" 
      "(done_dialog 1)"
    ); strcat
  ); action_tile
  (action_tile "cancel" "(done_dialog 0)")
  (setq ddiag (start_dialog))
  (unload_dialog dcl_id)
  
  (if (= ddiag 1)
    (progn
      ;; iterate through our list and assign values to your symbols, its like:
      ;; (setq WP "<value_a>") (setq TW "<value_b>") (setq L "<value_c>") ... 
      (foreach x *MyList*
        (apply 'set x)
      ); foreach
      (setq IT(+ Im (* 2.87 Is)))
      (setq moment(/ (* wp tw L L) 8000))
      (setq stress(/ (* moment cm) Im))
      (setq stressratio(/ stress Fbm))							
      (setq deflection(/ (* 5 wp tw L L L L) (* 384000 69600 IT))) 
      (setq allowdeflection(/ L 175))
      (setq defratio(/ deflection allowdeflection))
      (setq pt1 (getpoint))
      (setq pt2 (getpoint))
      (command "_mtext" pt1 pt2 "\n Actual Bending Stress =" (rtos stress 2 2)
        "\n Allowable Bending Stress =" (rtos Fbm 2 2)
        "\n Stress Ratio =" (rtos stressratio 2 2)
        "\n Actual Deflection =" (rtos deflection 2 2)
        "\n Allowable Deflection =" (rtos allowdeflection 2 2)
        "\n Deflection Ratio =" (rtos defratio 2 2) ""
      )
      (foreach x *MyList*
        (set (car x) nil)
      ); foreach
    )
    (princ "\nUser cancelled the dialog")
  ); if (= ddiag 1)
); defun 

 

Link to comment
Share on other sites

4 hours ago, joemcanciller said:

Another one. The label in dcl with mm^4 and mm^2, how to do superscript without the "^" sign. I can't find it in web. 😮

 

i wrote a utf-8 function for some asian languages, so i'm pretty sure dcl supports unicode 🙂

 

mm^2 = mm\U+00B2

mm^4 = mm\U+2074

 

 

Link to comment
Share on other sites

I agree with Grrr that I would rather store a list of values to one variable (*MyList*) than have a flog of variables having a party in my drawing. But just beginning with lisp this might be a little challenging. Nevertheless , why not learn it the right way right away on the highway , hey 🙂 

Link to comment
Share on other sites

2 minutes ago, hanhphuc said:

 

i wrote a utf-8 function for some asian languages, so i'm pretty sure dcl supports unicode 🙂

 

mm^2 = mm\U+00B2

mm^4 = mm\U+2074

 

 

 

Jip that works just fine! Good to know! thanx!

Link to comment
Share on other sites

BTW Op's code has no data (input) checking what so ever but lets give him (or her) a break (for now) :beer:

 

oh forgot about the last question in Op's first post : you create a mtext , so the shape of your getpoints (I use getpoint + getcorner) determines if your lines are cut short. Just select a wider rectangle... and if its still too short , just click on the just created mtext and drag it... dig it?

Edited by rlx
Link to comment
Share on other sites

1 hour ago, rlx said:

I agree with Grrr that I would rather store a list of values to one variable (*MyList*) than have a flog of variables having a party in my drawing. But just beginning with lisp this might be a little challenging.

 

Yea, its a pain writing too many codes for the variables, when its enough to store them in a list.

Probably everyone was on OP's level, so thats why I tried not to confuse him too much and on purpose avoided using too many mapcars and lambdas.

 

 

1 hour ago, rlx said:

BTW Op's code has no data (input) checking what so ever but lets give him (or her) a break (for now) :beer:

 

Noticed that aswell, but I would suggest for OP attempting to shorten and better understand his code and then go for any future improvements/fixes. 

So I think that a simple list manipulation and using the foreach function would be a good start for him. :)

 

 

1 hour ago, hanhphuc said:

mm^4 = mm\U+2074

 

I didn't knew that one could write quartic unicode character, nice one!

 

Edited by Grrr
Link to comment
Share on other sites

9 minutes ago, Grrr said:

I didn't knew that one could write quartic unicode character, nice one!

 

 

Ah, just remembered (where I went wrong) , while back I tried to work with CHR for some special characters and it did work (for some) but when I ran the same code at home , the result was totally different. So indeed I should have used UTF-8 (if I ever gonna use it, rarely use special characters) But it's always good to know 🙂 

Awel, almost weekend , have a nice weekend y'all :beer:

 

🐉

Link to comment
Share on other sites

11 minutes ago, rlx said:

So indeed I should have used UTF-8 (if I ever gonna use it, rarely use special characters) But it's always good to know 🙂 

 

I use UTF-8 only to display the squared symbol or the plus-minus one,

but I define any of them as a list like this '(92 85 43 48 48 66 50) to reconvert it into a string with the vl-list->string function.

A  piece of advise I remember from @Tharwat was that you could just start creating mtext and use the text formatting editor dialog

to populate with custom character symbol(s) and then just investigate that mtext's string content with LISP. :beer:

 

Link to comment
Share on other sites

Thank you very much @Grrr, @rlx and @hanhphuc for the response. I'll try to understand each line you guys did. Greatly appreciated. It's my second time posting here. More to go. lol. BTW, what does OP means? :D

Edited by joemcanciller
Link to comment
Share on other sites

5 hours ago, joemcanciller said:

Thank you very much @Grrr, @rlx and @hanhphuc for the response. I'll try to understand each line you guys did. Greatly appreciated. It's my second time posting here. More to go. lol. BTW, what does OP means? :D

 

well you're either a #HeToo (probably 99%) , a #SheToo (very unlikely) or an #EtToo so to be on the safe side we call you OPerator :-)

 

Link to comment
Share on other sites

9 minutes ago, rlx said:

 

well you're either a #HeToo (probably 99%) , a #SheToo (very unlikely) or an #EtToo so to be on the safe side we call you OPerator 🙂

 

 

How complicated!

 

For years I thought that OP was shorthand for Original Poster, instead of having to type out the Original Poster's name (which also can be very complicated!!) when replying.

Link to comment
Share on other sites

4 minutes ago, eldon said:

 

How complicated!

 

For years I thought that OP was shorthand for Original Poster, instead of having to type out the Original Poster's name (which also can be very complicated!!) when replying.

 

Original Poster will do nicely too :-) , was just having fun :-)

Link to comment
Share on other sites

On 10/12/2018 at 9:22 PM, Grrr said:

 

I use UTF-8 only to display the squared symbol or the plus-minus one,

but I define any of them as a list like this '(92 85 43 48 48 66 50) to reconvert it into a string with the vl-list->string function.

 

 

FWIW they're not the same thing - UTF-8 is a particular way of encoding Unicode

post#163 explained :)

 

 

On 10/13/2018 at 3:40 PM, rlx said:

 

Original Poster will do nicely too 🙂 , was just having fun 🙂

 

OP.. OPpa gangnam style  🎧🎶 

 

  • Like 1
Link to comment
Share on other sites

5 hours ago, hanhphuc said:

 

FWIW they're not the same thing - UTF-8 is a particular way of encoding Unicode

post#163 explained :)

 

 

 

OP.. OPpa gangnam style  🎧🎶 

 

 

must admit most of the gangnam style thingy has kinda passed me by , I know of it but I did like to watch the Jayesslee cover :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...