Lt Dan's legs Posted July 13, 2010 Share Posted July 13, 2010 Just trying to figure out how to do this.. (defun C:test (/) (setq ss (ssget)) (command "_.erase" ss "") (setq p1 (getpoint "\n**First point**")) (setq p2 (getpoint p1 "\n**Second point**")) (command "_.line" p1 p2 nil) (setq opt (strcase (getstring "\NRepeat Last Command <Yes or No>: "))) (cond ((or(= opt "Y")(= opt "YES"))(prompt "\nrepeat last command")) [color=red];;instead of prompting repeat last command I want it to actually repeat it[/color] (T (prompt "\nExiting command")) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 13, 2010 Share Posted July 13, 2010 Is this what you are trying to accomplish? (defun c:Test (/ ss p1 p2) (if (setq ss (ssget "_:L")) (progn (command "_.erase" ss "") (while (and (setq p1 (getpoint "\nSpecify first point: ")) (setq p2 (getpoint p1 "\nSpecify second point: ")) ) (command "_.line" "_non" p1 "_non" p2 "") ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted July 13, 2010 Share Posted July 13, 2010 Not sure exactly which part you want to repeat, but here is one way.... (defun C:test (/) (setq ss (ssget)) (command "_.erase" ss "") (setq wait T) (while wait (setq p1 (getpoint "\n**First point**")) (setq p2 (getpoint p1 "\n**Second point**")) (command "_.line" p1 p2 nil) (initget 1 "Y N") (setq opt (getkword "\nRepeat Last Command [Yes or No]: ")) (if (eq "N" opt) (setq wait nil) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 13, 2010 Author Share Posted July 13, 2010 Not sure exactly which part you want to repeat, but here is one way.... (defun C:test (/) (setq ss (ssget)) (command "_.erase" ss "") (setq wait T) (while wait (setq p1 (getpoint "\n**First point**")) (setq p2 (getpoint p1 "\n**Second point**")) (command "_.line" p1 p2 nil) (initget 1 "Y N") (setq opt (getkword "\nRepeat Last Command [Yes or No]: ")) (if (eq "N" opt) (setq wait nil) ) ) (princ) ) Looks like you have it. I'll test after lunch. Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 13, 2010 Share Posted July 13, 2010 For initget use (initget 1 "Y N") (setq opt (getkword "\nRepeat Last Command [Yes[color=red]/[/color]No]: ")) Instead of (initget 1 "Y N") (setq opt (getkword "\nRepeat Last Command [Yes[color=red] or[/color] No]: ")) To show a menu (see attached) Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 13, 2010 Author Share Posted July 13, 2010 okay I give!! how would I retrieve a block rotation? (setq ss (ssget "_:s" '((0 . "insert")))) ;;not really knowledgeable on assoc or car functions ;;I did find that rotation = 50 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 13, 2010 Share Posted July 13, 2010 1) Check for a valid SelSet: (if (setq ss (ssget '((0 . "INSERT")))) ... 2) Iterate through the SelSet: Most intuitive is probably something like: (setq counter 0) (repeat (sslength ss) (setq ent (ssname ss counter)) ... (setq counter (1+ counter)) ) 3) Query the rotation of each entity: (cdr (assoc 50 (entget ent))) Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 14, 2010 Author Share Posted July 14, 2010 Most intuitive is probably something like: (setq counter 0) (repeat (sslength ss) (setq ent (ssname ss counter)) ... (setq counter (1+ counter)) ) 3) Query the rotation of each entity: (cdr (assoc 50 (entget ent))) Thank you sir Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 14, 2010 Author Share Posted July 14, 2010 Is rotation 50? I'm getting some weird angle... Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 14, 2010 Share Posted July 14, 2010 Is rotation 50? I'm getting some weird angle... It will be in radians. Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 14, 2010 Author Share Posted July 14, 2010 It will be in radians. putting the puzzle together (defun c:test (/ ss counter ent en) (setq ss (ssget "_:s" '((0 . "insert")))) (setq counter 0) (repeat (sslength ss) (setq ent (ssname ss counter)) (setq en (cdr (assoc 50 (entget ent)))) (setq counter (1+ counter)) ) (setq pt (getpoint "\nSpecify Insertion point: ")) (command "-insert" ent pt "" "" en) (princ) ) I see the problem. I just don't know how to get to the solution... What should I be looking for to get my result? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 14, 2010 Share Posted July 14, 2010 As you are dealing with a single block, there is no need to iterate through the selection set in this case - but, you should check for a valid selection as I pointed out. With a single selection you could use ssget with "_:S" as you have, or just use a simple 'entsel' call. Your angle will be in radians, hence you will need to convert it to degrees if you want to use it in a command call. This sub should help in that matter: (defun RtoD ( x ) (* 180. (/ x pi)) ) Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted July 14, 2010 Share Posted July 14, 2010 Your angle will be in radians, hence you will need to convert it to degrees if you want to use it in a command call. Or you can add an "r" suffix to specify radians in a command. (i.e.: 1.5r) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 14, 2010 Share Posted July 14, 2010 Or you can add an "r" suffix to specify radians in a command. (i.e.: 1.5r) Ooo I didn't know that! Thanks RK Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted July 14, 2010 Share Posted July 14, 2010 Ooo I didn't know that! Thanks RK Of course, if you were going to do that, you would have to convert the radians to a string anyway.... But it can be useful if you are testing something at the command line and you want to enter radians... Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 14, 2010 Author Share Posted July 14, 2010 Thank you very much btw I have a friend with the last name McSwain. Just thought I'd share Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 14, 2010 Share Posted July 14, 2010 Of course, if you were going to do that, you would have to convert the radians to a string anyway.... But it can be useful if you are testing something at the command line and you want to enter radians... Yeah, it's a neat trick, but for code, it seems like it's safer to just convert to degrees then to a string (remove any possibilities of rounding errors). Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted July 14, 2010 Share Posted July 14, 2010 Yeah, it's a neat trick, but for code, it seems like it's safer to just convert to degrees then to a string (remove any possibilities of rounding errors). It's not a trick, AutoCAD was designed to accept "r" for radians, "g" for grads, d for degrees, etc. As far as code goes, I try to avoid converting anything. If you do though, you can do it in one step using (angtos), but I don't see how this avoids rounding errors. Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 14, 2010 Share Posted July 14, 2010 It's not a trick, AutoCAD was designed to accept "r" for radians, "g" for grads, d for degrees, etc. As far as code goes, I try to avoid converting anything. If you do though, you can do it in one step using (angtos), but I don't see how this avoids rounding errors. Sorry, 'trick' was the wrong choice of words. I meant if one was the convert the radians to a string, then append "R" to it, you could/would open yourself up to rounding issues. I wouldn't convert either, but if one is so inclined to use command, they are forced to feed it degrees or append "R" as you shown. Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted July 14, 2010 Author Share Posted July 14, 2010 Sorry, 'trick' was the wrong choice of words. I meant if one was the convert the radians to a string, then append "R" to it, you could/would open yourself up to rounding issues. I wouldn't convert either, but if one is so inclined to use command, they are forced to feed it degrees or append "R" as you shown. How would you go about making this, Alan? I'm not wanting the full code. Just the function to insert the same block you select. Quote Link to comment Share on other sites More sharing options...
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.