INITGET and GETKWORD - Lisp Help

INITGET and GETKWORD - Lisp Help

Anonymous
Not applicable
2,194 Views
5 Replies
Message 1 of 6

INITGET and GETKWORD - Lisp Help

Anonymous
Not applicable

Hello helpful Lisp Writers,

I've made a quick lisp for creating basic Hex Nuts - as looking up dimensions and modeling them became pretty annoying after a while. I could create a library of blocks, but I rather enjoy the lisp approach.

My issue is that the initget/ getkword functions are auto-completing strings which is choosing 1-4" rather than 1", or 3-4" rather than 3" (even when clicking them in the dynamic user prompt - it doesn't recognize the quotation mark). I could get around this by writing out 'one half inch' rather than '1-2"' and so-on, but I'd rather not have to. I've also tried reversing the order of options given from largest to smallest, hoping the integer numbers would be recognized first but this didn't seem to have any affect.

I also had to use a dash rather than a forward slash for fractions as it messes up the prompt - Haven't been able to find a way around that.

 

(defun C:HN ( / ANS CEN UNITS WAF BOR HEI P C POL CIR)
	(setvar "CMDECHO" 0)
	(initget "1-4\" 1-2\" 3-4\" 1\" 2\" 3\"")
	(setq ANS 
		(getkword "\nChoose nominal hex nut size: [1-4\"/1-2\"/3-4\"/1\"/2\"/3\"] <1\">: ")
	)
	(if (not ANS) 
		(setq ANS "1\"")
	)
	(setq CEN
		(getpoint "\nSelect center point of hex nut: ")
	)
	(setq UNITS
		(getvar "LUNITS")
	)
	(setvar "LUNITS" 2)
	(cond
		((= ANS "1-4\"")	(setq WAF 11.1125)	(setq BOR 6.35) 	(setq HEI 5.55625))
		((= ANS "1-2\"")	(setq WAF 19.05)	(setq BOR 12.7) 	(setq HEI 11.1125))
		((= ANS "3-4\"")	(setq WAF 28.575)	(setq BOR 19.05) 	(setq HEI 16.271875))
		((= ANS "1\"")		(setq WAF 38.10)	(setq BOR 25.4) 	(setq HEI 21.828125))
		((= ANS "2\"")		(setq WAF 76.20)	(setq BOR 50.8) 	(setq HEI 43.65625))
		((= ANS "3\"")		(setq WAF 114.3)	(setq BOR 76.2) 	(setq HEI 65.88125))
	)
	(command "POLYGON" "6" "_NONE" CEN "C" (/ WAF 2))
	(setq P
		(ssget "L")
	)
	(command "CIRCLE" "_NONE" CEN (/ BOR 2))
	(setq C
		(ssget "L")
	)
	(command "EXTRUDE" P "" HEI)
	(setq POL
		(ssget "L")
	)
	(command "EXTRUDE" C "" HEI)
	(setq CIR
		(ssget "L")
	)
	(command "SUBTRACT" POL "" CIR "")
	(setvar "LUNITS" UNITS)
	(setvar "CMDECHO" 1)
)

Any help would be appreciated!

 

 

0 Likes
Accepted solutions (1)
2,195 Views
5 Replies
Replies (5)
Message 2 of 6

john.uhden
Mentor
Mentor
Accepted solution

That's never going to work with the quotes.  I suggest you create a dialog box where the user can just pick the size.

Other than that, you would have to let them type in the size and if it in your list then proceed, otherwise warn them and repeat.

John F. Uhden

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for the response John, that's a pretty simple solution and should work just fine for the lisp.

However, these quotes do show up in the command prompt just fine when you run the lisp, and I don't see why they'd be affecting the string auto-completing. Seems like a different problem... I suppose I'll just avoid it all together with a dialogue box though.

 

Thanks!

 

0 Likes
Message 4 of 6

scot-65
Advisor
Advisor
When AutoCAD introduced the DYNPROMPT, all hell
broke loose regarding forward slashes and quotes.
Those of us that work in Architectural units have shaken
our fists... with "you're #1".

As John suggested, turn to a DCL dialog box.
The values you need seem to be static. If not, turn
to an edit box (or edit box popup list combo) and I
can help you check if entered text is indeed a real
number. If you have trouble, ask in the customization
section and provide code that is giving you trouble...

I have a template floating somewhere in this forum that you can use.
It sets up the basic structure for declaring and displaying
the dialog, but not the dialog coding itself.

???

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

0 Likes
Message 5 of 6

john.uhden
Mentor
Mentor
Maybe you meant "you're #2". 🙂

John F. Uhden

0 Likes
Message 6 of 6

Anonymous
Not applicable

I'd be really interested in checking out that template for future lisping endeavors. I'll see what i can dig up from your post history. The values for this will be static, so I'll give the dialogue box a go 🙂

 

Thanks for the help fellas! Very much appreciated.

 

 

0 Likes