Need help with Lisp

Need help with Lisp

annoisscary
Advocate Advocate
688 Views
8 Replies
Message 1 of 9

Need help with Lisp

annoisscary
Advocate
Advocate

I am trying to make a Lisp that Lists and lets me pick the DimStyle. Don't need it to do anything fancy (I think). The code I have so far does basically what I want it to do except it doesn't work at all. I started off with just trying to get 1 dimstyle to work and so far whenever I "pick" a style, it just says invalid input and asks for me to pick again. I'm sure this is probably something clearly wrong with my code, but to be honest I have very little to no idea what I'm doing so any help would be great, thanks!

 

Code: 

 

(Defun c:EDS (/ a)

(prompt "DIMSTYLE - ")
(setq a (getkword "Specify Style [ISJ/OSJ/OSB/TTT/DLO/GO/FACE/OA/NOTCH/COBRA/DECIMAL/1.5]: "))
(if (= a "ISJ")
(command "-dimstyle" "r" "ISJ - 1.5")) ;if
(Princ)
)

0 Likes
Accepted solutions (1)
689 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

You need to use INITGET! Then some list of associated real names. Also, add a test if the style actually is in the drawing.

 

(Defun c:EDS (/ a)
  
  (prompt "DIMSTYLE - ")
  (initget "ISJ OSJ OSB TTT DLO GO FACE OA NOTCH COBRA DECIMAL 1.5")
  (setq a (getkword "Specify Style [ISJ/OSJ/OSB/TTT/DLO/GO/FACE/OA/NOTCH/COBRA/DECIMAL/1.5]: "))
 
  (if (and (setq a (cdr (assoc a '(("ISJ" . "ISJ - 1.5")
				   ("OSJ" . "OSJ - 1.5")
				   ))))
	   (tblsearch "dimstyle" a)
	   )
    (command "-dimstyle" "r" a)) ;if
  (Princ)
  )

 

0 Likes
Message 3 of 9

annoisscary
Advocate
Advocate

Yes thank you, I just realized I needed to use initget but also gladly welcome your improvements!

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant

If you like [or want to have the choice] to type in options, you can make it a little easier on yourself by setting it up so that, for at least some of the options, you don't need to type in the entire word:

  (initget "Isj OSJ OSB Ttt DLo Go Face OA Notch Cobra DEcimal 1.5")
  (setq a (getkword "Specify Style [Isj/OSJ/OSB/Ttt/DLo/Go/Face/OA/Notch/Cobra/DEcimal/1.5]: "))

Then for the word options you can type only the capital-letter parts, such as just [for example] F to get the Face option.  [No need if you would always pick an option in the prompt, which would work either way.]

Kent Cooper, AIA
0 Likes
Message 5 of 9

annoisscary
Advocate
Advocate

Ah, I see. Thanks Kent, a good suggestion!

0 Likes
Message 6 of 9

Sea-Haven
Mentor
Mentor

Maybe this 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq ans (ah:butts 1  "V" '("Select Dim Style" "Isj" "OSJ" "OSB" "Ttt" "DLo" "Go" "Face" "OA" "Notch" "Cobra" "DEcimal" "1.5")))

SeaHaven_0-1664330131346.png

 

 

0 Likes
Message 7 of 9

annoisscary
Advocate
Advocate

Daang, now that is cool! Going through all these different versions has been a good learning experience, I like seeing everyone's take on doing stuff. I gotta say, I wasn't really looking for buttons as I'm a keybind/shorthand command kinda guy but I'm actually really liking how fast I can go from one to the other with that DCL. Got it all set up and think I'll be sticking with the buttons, thanks!

 

p.s. , I'm 100% going to recycle this DCL for other lisps, hah!

0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

That is the idea anywhere that you need to select an answer as an alternative to initget. If you want better descriptions in the dcl so they are not returned as "strings", you can also look at variable "but" it will be a number starts at 1.

 

There is Multi getvals and Multi toggles. All I ask is to leave my name in the multi code.

0 Likes
Message 9 of 9

annoisscary
Advocate
Advocate

But of course! I have no intention of trying to pass others code off as my own, credit given where credit is due my friend!

0 Likes