Jump to content

Recommended Posts

Posted

Could someone guide me through this challenge:

I am trying to create a lisp to have sub commands (I am not even sure what you would call it) - and when I search sub command I get a bunch of none sense.

 

My first list is:

[Bolt/U-bolt/Pipe/Angle/Plate/Hss-square]

 

then under "Bolt":

[1-2/5-8/3-4]

under "U-bolt":

[1-2/5-8]

 

under "Pipe":

[General/73/89/102/114]

under "Angle": only on dynamic block with all sizes

under "Plate": only on dynamic block with all sizes

under "Hss-square":

[Square/Rectangle]

I have no idea how to make sub commands or how to call them in order to call insert command.

all blocks are on the same dwg, but they have funky name that does not represent their shape only the size.

 

so on this lisp:  each time I select a "sub-menu" for the lack of better words, I then would like to insert the block.

Example: Bolt > 5-8 > then magically insert "blah" block from its insertion point. 

(if(not ttc:Mode)(setq ttc:Mode "Pipe"))
    (initget "Bolt U-bolt Pipe Angle Plate Hss-square")
    (setq oldMode ttc:Mode
    ttc:Mode
     (getkword
       (strcat "\nSpecify mode [Bolt/U-bolt/Pipe/Angle/Plate/Hss-square] <" ttc:Mode ">: "))
    conFlag T
    paseStr ""
     ); end setq
    (if(null ttc:Mode)(setq ttc:Mode oldMode))

 

Could someone help me with this please?

Posted

I have adapted your code and formed a small function to give you an idea of what is possible. This makes use of a sub function to get the relevant keyword. Be aware that each item of each list needs a unique identifier. This is normally a capital letter, so I have changed "Plate" to "pLate"  to distinguish it from "Pipe". I have switched on dynamic mode system variables (if you didn't already have them on, and it resets them on exit/error if you didn't). The keywords for each menu will appear at the cursor to allow selection by mouse. Pressing return or right clicking the mouse (if set up that way) selects the default denoted by the solid dot in each menu.

 

(defun rh:get_kword ( msg lst d_val / tmp)
  (cond ( (and (= (type lst) 'LIST) (vl-position d_val lst) (= (type msg) 'STR))
          (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) lst))))
          (cond ( (setq tmp (getkword (strcat msg " ["(vl-string-right-trim "/"(apply 'strcat (mapcar '(lambda (x) (strcat x "/")) lst))) "] <" d_val "> : ")))) (d_val)) 
        )
  );end_cond
);end_defun

(defun c:test ( / *error* sv_lst sv_vals m_lst b_lst u_lst p_lst h_lst ttc:Mode cnFlag paseStr typ)

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );end_*error*_defun
  
  (setq sv_lst (list 'dynmode 'dynprompt)
        sv_vals (mapcar 'getvar sv_lst)
        m_lst (list "Bolt" "U-bolt" "Pipe" "Angle" "pLate" "Hss-square")
        b_lst (list "1-2" "5-8" "3-4")
        u_lst (list "1-2" "5-8")
        p_lst (list "General" "73" "89" "102" "114")
        h_lst (list "Square" "Rectangle")
  ); end setq

  (mapcar 'setvar sv_lst '(3 1))

  (if(not ttc:Mode)(setq ttc:Mode "Pipe"))

  (setq ttc:Mode (rh:get_kword "\nSpecify mode " m_lst ttc:Mode))

  (cond ( (= ttc:Mode "Bolt")
          (setq typ (rh:get_kword "\nSpecify type " b_lst (car b_lst)))
        )
        ( (= ttc:Mode "U-bolt")
          (setq typ (rh:get_kword "\nSpecify type " u_lst (car u_lst)))
        )
        ( (= ttc:Mode "Pipe")
          (setq typ (rh:get_kword "\nSpecify type " p_lst (car p_lst)))
        )
        ( (= ttc:Mode "Angle") )
        ( (= ttc:Mode "pLate") )
        ( (= ttc:Mode "Hss-square")
          (setq typ (rh:get_kword "\nSpecify type " h_lst (car h_lst)))
        )
  );end_cond

  (alert (strcat "You Chose   " ttc:mode " : " typ))
  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

 

Posted

now I get what it is called (initget and getword).

how do I deal with my sub > sub options here?

and can progn and condition is a issue for me!

can someone take a look - the command: circle is just a test (I do in fact want to insert blocks when called correctly)!

(initget "Bolt U-bolt Pipe Angle pLate Hss-square")
(if (null (setq ans (getkword "\nChoose [Bolt/U-bolt/Pipe/Angle/pLate/Hss-square] <Pipe>: ")))
    (setq ans "Pipe")
)
;** BOLT ** [1-2 5-8 3-4] **
 	(if (= ans "Bolt")
	;(initget "A1-2 B5-8 C3-4")  
		(progn  (setq ans (getkword "\nChoose [A 1-2/B 5-8/C 3-4]: "))
		(cond  
		(if (= ans "A 1-2") (progn (command "circle" pause "100")))
	  	(if (= ans "B 5-8") (progn (command "circle" pause "100")))
	  	(if (= ans "C 3-4") (progn (command "circle" pause "100")))
		)
		)  
	) ;enf if
 	(if (= ans "U-bolt")
		(progn (command "circle" pause "200"))
	) ;enf if
 	(if (= ans "Pipe")
		(progn (command "circle" pause "300"))
	) ;enf if
 	(if (= ans "Angle")
		(progn (command "circle" pause "300"))
	) ;enf if
 	(if (= ans "pLate")
		(progn (command "circle" pause "300"))
	) ;enf if
 	(if (= ans "Hss-square")
		(progn (command "circle" pause "300"))
	) ;enf if

 

Posted

Thank you dlanorh,

my perspective in things always comes back to command macros in order to execute my last commands.

on your lisp: how would the insertion - block name take place, how would you relate the option to the block?

 

Thanks again

Posted

i always forget that LISP is in fact list processing, yet I always try to force everything onto one statement. your code is teaching me a lot - thank you for that!

Posted
Just now, Sambuddy said:

Thank you dlanorh,

my perspective in things always comes back to command macros in order to execute my last commands.

on your lisp: how would the insertion - block name take place, how would you relate the option to the block?

 

Thanks again

 

Using you "circle" anology I have filled in the first 3 sub-conditions in the snippet below

 

  (cond ( (= ttc:Mode "Bolt")
          (setq typ (rh:get_kword "\nSpecify type " b_lst (car b_lst)))
          (cond ( (= typ "1-2") (command "circle" pause "100"))
                ( (= typ "5-8") (command "circle" pause "200"))
                (t (command "circle" pause "300")); if it reaches this point typ must = "3-4"
          );end_cond
        )
        ( (= ttc:Mode "U-bolt")
          (setq typ (rh:get_kword "\nSpecify type " u_lst (car u_lst)))
          (cond ( (= typ "1-2") (command "circle" pause "400"))
                (t (command "circle" pause "500"))
          );end_cond
        )
        ( (= ttc:Mode "Pipe")
          (setq typ (rh:get_kword "\nSpecify type " p_lst (car p_lst)))
          (cond ( (= typ "General") (command "circle" pause "600"))
                ( (= typ "73") (command "circle" pause "73"))
                ( (= typ "89") (command "circle" pause "89"))
                ( (= typ "102") (command "circle" pause "102"))
                (t (command "circle" pause "114"))
          );end_cond
        )
        ( (= ttc:Mode "Angle") )
        ( (= ttc:Mode "pLate") )
        ( (= ttc:Mode "Hss-square")
          (setq typ (rh:get_kword "\nSpecify type " h_lst (car h_lst)))
        )
  );end_cond

 

Posted (edited)
(if (test) (command "circle" pause "300")); only one thing to do (if ... then) no (progn) needed

(if (test) 
	(progn								; more than one thing to do (if ... then) (progn) needed
		(command "circle" pause "300")
		(command "circle" pause "600")
	);end_progn
);end_if

(if (test) 							; only one thing to do (if ... then.. else) no (progns) needed
	(command "circle" pause "300")	;if true do this
	(command "circle" pause "600")	;else do this
);end_if


(if (test) 							  ; more than one thing to do (if ... then ... else) (progn) needed
	(progn							  ; if true do these
		(command "circle" pause "300")
		(command "circle" pause "400")
	);end_progn
	(progn							  ; else do these
		(command "circle" pause "500")
		(command "circle" pause "600")
	);end_progn
);end_if

(if (test)
  (setq a "A" ;this is a multi line setq (one statement)so it doesn't need a progn
        b "B"
  );end_setq
);end_if

(if (test)
  (while (test) ;again this doesn't need a progn as it is one statement (a loop), even though the loop contains multiple statement
       ........
       ........
  );end_while
);end_if

(progn) 101, hope this helps.

Edited by dlanorh
Posted

You may be better using a list dcl there are a few basically you can choose an item from the list, same with my Multi radio buttons.lsp.

 

You will though like dlanorh need to use cond to work out which group goes next and join the resulting strings. It could be a case of using defuns even though they are only a couple of lines.

 

So if multi choices need a bolt this will work for all of them.

 

(cond 
( (= ttc:Mode "Bolt")((boltz)(setq strcat xxx ans))) ; can have more defuns as answer to cond
( (= ttc:Mode "UBolt")((boltz)(setq strcat xxx ans)))
)
(defun boltsz ( / )
(setq ans (ah:butts but "V"   '("Choose size " "1/4" "3/8" "1/2" "5/8" "3/4")))
)

 

 

Posted
13 hours ago, Sambuddy said:

i always forget that LISP is in fact list processing, yet I always try to force everything onto one statement. your code is teaching me a lot - thank you for that!

 

very basic functions in LISP = car, cdr, assoc

 

(cdr
  (assoc x
	 '(("Bolt" . "[1-2/5-8/3-4]")
	   ("U-bolt" . "[1-2/5-8]")
	   ("Pipe" . "[General/73/89/102/114]")
	   ("Angle" . "only on dynamic block with all sizes")
	   ("Plate" . "whatever")
	   ("Hss-square" . "[Square/Rectangle]")
	   )
	 )
  )

 

Posted

Thank you all for your input.

Special thanks to dlanorh for explaining the process statements: cond / if / progn.

I already have learnt a lot more with his input and examples. I constructed this lisp and am in the process of creating at least two more lisps with getword functions, so I bow to you dlanorh.

 

 

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...