mlb6d9 Posted September 13, 2012 Posted September 13, 2012 Hi All - this is my first time on the site as a member. I have gleaned much useful information off this site in the past, and for that I thank you all. I have a need for a lisp routine I cannot find anywhere, and am not familiar enough with lisp to write one. So basically, I'm saying 'Help!' I'm drawing a bunch of flat patterns where I'm drawing a bunch of small arc segments & offsetting lines. The offset distance changes with the length of each successive arc length I choose. Right now, I have to choose 'List' to get the arc length, then copy and paste it into the command line when asked for the offset distance. Sounds simple enough, but when I'm dealing with a whole bunch it gets tedious. I'd like to simply be able to pick an arc when asked for the offset distance, and the offset distance is the same as the arc length picked. Make sense? Many thanks in advance for anyone's help! Quote
Lee Mac Posted September 13, 2012 Posted September 13, 2012 Here's a short & quick program to get you going: (defun c:arcoff ( / en ex ) (while (progn (setvar 'errno 0) (setq en (car (entsel "\nSelect Arc: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (= 'ename (type en)) (if (= "ARC" (cdr (assoc 0 (setq ex (entget en))))) (command "_.offset" (* (cdr (assoc 40 ex)) (rem (+ pi pi (- (cdr (assoc 51 ex)) (cdr (assoc 50 ex)))) (+ pi pi)) ) en "\\" "" ) (princ "\nObject is not an Arc.") ) t ) ) ) ) (princ) ) Quote
BlackBox Posted September 13, 2012 Posted September 13, 2012 Welcome to CADTutor! ** EDIT - Per usual, Lee beat me to it! LoL In any event, at least this shows an alternative. Give this a try: (vl-load-com) (defun c:OFAM () (c:OffsetArcMultiple)) (defun c:OffsetArcMultiple (/ *error* eName acDoc oArc) (princ "\rOFFSETARCMULTIPLE ") (defun *error* (msg) (if acDoc (vla-endundomark acDoc) ) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it ) (princ) ) (while (and (/= nil (setq eName (car (entsel "\nSelect arc to offset: ")))) (= "ARC" (cdr (assoc 0 (entget eName)))) ) (progn (or acDoc (not (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))) ) ) ) (vla-offset (setq oArc (vlax-ename->vla-object eName)) (vla-get-arclength oArc) ) (*error* nil) ) ) ) Quote
mlb6d9 Posted September 13, 2012 Author Posted September 13, 2012 Thanks guys! These work great for offsetting arc segments! I should have been more specific in my request - sorry I'm actually looking to offset a separate straight line, but when asked the offset distance I would like to pick an arc segment for the offset distance (see attached) Quote
Lee Mac Posted September 13, 2012 Posted September 13, 2012 I would suggest the following: OFFSET Through Multiple Pick your arc endpoints. Quote
mlb6d9 Posted September 13, 2012 Author Posted September 13, 2012 Thanks Lee - we're getting close. When I choose the two endpoints, it uses the straight line distance between them as opposed to the actual arc length (see attached). While the two distances are close, I need to be very accurate in these patterns, and ten lines of accumulative error can add up. Quote
Lee Mac Posted September 13, 2012 Posted September 13, 2012 When I choose the two endpoints, it uses the straight line distance between them as opposed to the actual arc length (see attached). Sorry, of course, I'm not sure how I overlooked that fact. Try this quick modification of my earlier code: (defun c:arcoff ( / _select en ex ) (defun _select ( msg obj / en ) (while (progn (setvar 'errno 0) (setq en (car (entsel msg))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (= 'ename (type en)) (if (not (wcmatch (cdr (assoc 0 (entget en))) obj)) (princ "\nInvalid object selected.") ) ) ) ) ) en ) (if (setq en (_select "\nSelect Object to Offset: " "*LINE")) (while (setq ex (_select "\nSelect Arc: " "ARC")) (setq ex (entget ex)) (command "_.offset" (* (cdr (assoc 40 ex)) (rem (+ pi pi (- (cdr (assoc 51 ex)) (cdr (assoc 50 ex)))) (+ pi pi)) ) en "\\" "" ) (setq en (entlast)) ) ) (princ) ) Quote
mlb6d9 Posted September 13, 2012 Author Posted September 13, 2012 OMG - That's IT!!!!! Thanks Lee - It works perfectly, I should have posted this a couple years ago. Thanks to you both for your help - I will be forever grateful!! In the meantime, is there a specific book you can recommend to start learning AutoLisp? 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.