bgator220 Posted September 28, 2010 Posted September 28, 2010 Hello, I am new to the forums. I am trying to make a program that helps me write g-code from autocad files. I am learning lisp quite quickly by just piecing different snippets together and then customizing them to my specific needs. I am having trouble with one function that I was hoping someone would know the answer to. I have the code telling if the object is an arc or not, but find that it the user enters something other than an object (like just clicking a point), then the code messess up. Is there any way to prevent that? I was thinking about the initget but is that only for get commands? (defun g79fun ( ) (setq codeuse 1) (while(= codeuse 1) (setq ent (entsel "\nSelect the Arc: ")) (setq lstent (entget (car ent))) (initget + 1) (if (= "ARC" (cdr (assoc 0 lstent)))(progn (setq radius (cdr (assoc 10 lstent))) (setq codeuse nil) )(progn (princ "\nNot an Arc or Circle. ") (princ "idiot") ) ) ) ) Thanks, Brian Quote
JohnM Posted September 28, 2010 Posted September 28, 2010 look at the ssget function with single selection and filters Quote
BlackBox Posted September 28, 2010 Posted September 28, 2010 Try this: (defun c:FOO (/ eName eList) (if (and (setq eName (car (entsel "\n >> Select an Arc or Ciricle: "))) (wcmatch (cdr (assoc 0 (setq eList (entget eName)))) "ARC,CIRCLE")) (prompt (strcat "\n >> Radius = " (rtos (cdr (assoc 40 eList)) 2 2))) (prompt "\n <!> Invalid Object <!> ")) (princ)) Quote
alanjt Posted September 28, 2010 Posted September 28, 2010 Out of my toolbox... (defun c:Rad (/ ent cen) ;; Check radius of selected arc segment ;; Alan J. Thompson, 05.17.10 (if (setq ent (nentsel "\nSelect arc segment: ")) (if (setq cen (osnap (cadr ent) "_cen")) (alert (strcat "Radius: " (rtos (distance (osnap (cadr ent) "_near") cen)))) (alert "Segment not an arc!") ) ) (princ) ) Works on anything with a radius (LWPolyline segment, arc, ellipse, circle). Quote
David Bethel Posted September 28, 2010 Posted September 28, 2010 There are quite a few ways to skin that cat: [b][color=BLACK]([/color][/b]defun c:getarc [b][color=FUCHSIA]([/color][/b]/ ss en ed ce ra[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not ss[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]/= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nSelect 1 ARC"[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"ARC"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq en [b][color=NAVY]([/color][/b]ssname ss 0[b][color=NAVY])[/color][/b] ed [b][color=NAVY]([/color][/b]entget en[b][color=NAVY])[/color][/b] ce [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 10 ed[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] ra [b][color=NAVY]([/color][/b]cdr [b][color=MAROON]([/color][/b]assoc 40 ed[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote
BlackBox Posted September 28, 2010 Posted September 28, 2010 Out of my toolbox... Savvy usage of osnaps (5 points!), my friend. I never really considered the distance function, with the property being available. You know it's coming, too, don't you!? Yup.... Deservedly: Quote
alanjt Posted September 28, 2010 Posted September 28, 2010 Savvy usage of osnaps (5 points!), my friend. I never really considered the distance function, with the property being available. You know it's coming, too, don't you!? Yup.... Deservedly: LoL, thanks.The real advantage is OSnap for "cen" is the object filter and will work on anything with a radius. Quote
BlackBox Posted September 28, 2010 Posted September 28, 2010 LoL, thanks.The real advantage is OSnap for "cen" is the object filter and will work on anything with a radius. You're welcome. True, and true. Very cool, Alan. Quote
David Bethel Posted September 28, 2010 Posted September 28, 2010 Alan, I would think that would have a chance of return erroneous results if the user adds transparent osnaps during the selection: Select line red line using _end near the magenta line but not on the arc. It says it has a radius. -David test.dwg Quote
alanjt Posted September 28, 2010 Posted September 28, 2010 Alan, I would think that would have a chance of return erroneous results if the user adds transparent osnaps during the selection: Select line red line using _end near the magenta line but not on the arc. It says it has a radius. -David Yeah, it does have that limitation. Quote
bgator220 Posted September 29, 2010 Author Posted September 29, 2010 Thanks for the help. Got it working just how I wanted. Does anyone know how to still use the nentsel command but combine it with a getkwds? For something on the command line to say "Select the Arc, or (Feedrate/Gcode)". Where the keyword F or G would take them out of the nentsel command. Quote
Lee Mac Posted September 29, 2010 Posted September 29, 2010 This is how I might code it, I don't like using snaps, leaves too much room for error :wink: (defun c:test ( / input ) (while (progn (initget "Feedrate Gcode") (setq input (entsel "\nSelect Arc or [Feedrate/Gcode] <Exit> : ")) (cond ( (and (listp input) (eq 'ENAME (type (car input)))) (if (eq "ARC" (cdr (assoc 0 (entget (car input))))) (princ (strcat "\n:: Radius = " (rtos (cdr (assoc 40 (entget (car input))))) " ::")) (princ "\n** Object is not an Arc **") ) ) ( (eq "Feedrate" input) (princ "\nYou have Selected Feedrate") ) ( (eq "Gcode" input) (princ "\nYou have Selected Gcode") ) ) ) ) (princ) ) Quote
bgator220 Posted October 1, 2010 Author Posted October 1, 2010 Thanks! Got it working how I wanted. Quote
Recommended Posts
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.