jimpcfd Posted April 21, 2011 Posted April 21, 2011 i need to reduce a line evenly at both ends, tried the Lengthen command but that only changes one end. can a lisp routine do this if so has someone already done one, is not if someone could give me some help on where to start. cheers jimpcfd Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 Hi jimpcfd, Here is how I might approach it: * Select your line using the entsel function (car (entsel)) * Retrieve its DXF data using the entget function * Retrieve its start and endpoints at DXF Group codes 10 and 11 (cdr (assoc )) * Find the length of the line (distance ) * If not a zero length line, Find the unit vector of the line (mapcar '/ (mapcar '- ) (list )) * Add or substract multiples of this unit vector from the start/end points (mapcar '+ (mapcar '* (list ))) * Update the DXF data with the new points * Update the line (entmod) Lee Quote
jimpcfd Posted April 21, 2011 Author Posted April 21, 2011 Thanks Lee i will have a play with that at the weekend it looks very logical, finger crossed . cheers Quote
BlackBox Posted April 21, 2011 Posted April 21, 2011 i need to reduce a line evenly at both ends, tried the Lengthen command but that only changes one end. If writing LISP isn't that easy for you, try exploring the DYnamic functionality of the LENGTHEN command. (command "._lengthen" "_dynamic") Quote
jimpcfd Posted April 21, 2011 Author Posted April 21, 2011 hi Renderman just tried that and it seems to do one end. image a line 200mm long and the mid point is at 0,0 then reduce the line too 150mm long but the mid point still needs to be on 0,0. hope that makes scene . cheers Quote
eldon Posted April 21, 2011 Posted April 21, 2011 Lengthen always works on the end point of the line nearest to where it was picked. With one more click at the other end, you could shorten each end of the line Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 Ok, so I couldn't resist the urge to LISP [color=RED]([/color][color=BLUE]defun[/color] c:short [color=RED]([/color] [color=BLUE]/[/color] d di l p1 p2 r uv [color=RED])[/color] [color=#990099];; © Lee Mac 2011[/color] [color=RED]([/color][color=BLUE]while[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]setvar[/color] [color=DARKRED]'[/color]ERRNO [color=#009900]0[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]setq[/color] l [color=RED]([/color][color=BLUE]car[/color] [color=RED]([/color][color=BLUE]entsel[/color] [color=#a52a2a]"\nSelect Line to Shorten: "[/color][color=RED])))[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED]([/color] [color=RED]([/color][color=BLUE]=[/color] [color=#009900]7[/color] [color=RED]([/color][color=BLUE]getvar[/color] [color=DARKRED]'[/color]ERRNO[color=RED]))[/color] [color=RED]([/color][color=BLUE]princ[/color] [color=#a52a2a]"\n--> Missed, Try Again."[/color][color=RED])[/color] [color=RED])[/color] [color=RED]([/color] [color=RED]([/color][color=BLUE]eq[/color] [color=DARKRED]'[/color]ENAME [color=RED]([/color][color=BLUE]type[/color] l[color=RED]))[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]and[/color] [color=RED]([/color][color=BLUE]eq[/color] [color=#a52a2a]"LINE"[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]0[/color] [color=RED]([/color][color=BLUE]setq[/color] l [color=RED]([/color][color=BLUE]entget[/color] l[color=RED])))))[/color] [color=RED]([/color][color=BLUE]setq[/color] p1 [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]10[/color] l[color=RED]))[/color] p2 [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]11[/color] l[color=RED]))[/color] di [color=RED]([/color][color=BLUE]distance[/color] p1 p2[color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]not[/color] [color=RED]([/color][color=BLUE]equal[/color] di [color=#009999]0.0[/color] [color=#009999]1e-8[/color][color=RED]))[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]setq[/color] d [color=RED]([/color][color=BLUE]getdist[/color] [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=RED]([/color][color=BLUE]lambda[/color] [color=RED]([/color] a b [color=RED])[/color] [color=RED]([/color][color=BLUE]/[/color] [color=RED]([/color][color=BLUE]+[/color] a b[color=RED])[/color] [color=#009999]2.[/color][color=RED]))[/color] p1 p2[color=RED])[/color] [color=#a52a2a]"\nSpecify New EndPoint: "[/color][color=RED]))[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]setq[/color] r [color=RED]([/color][color=BLUE]/[/color] [color=RED]([/color][color=BLUE]-[/color] [color=RED]([/color][color=BLUE]/[/color] di [color=#009999]2.[/color][color=RED])[/color] d[color=RED])[/color] di[color=RED])[/color] uv [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=BLUE]*[/color] [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=BLUE]-[/color] p2 p1[color=RED])[/color] [color=RED]([/color][color=BLUE]list[/color] r r r[color=RED]))[/color] p1 [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=BLUE]+[/color] p1 uv[color=RED])[/color] p2 [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=BLUE]-[/color] p2 uv[color=RED])[/color] l [color=RED]([/color][color=BLUE]subst[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]10[/color] p1[color=RED])[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]10[/color] l[color=RED])[/color] l[color=RED])[/color] l [color=RED]([/color][color=BLUE]subst[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]11[/color] p2[color=RED])[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]11[/color] l[color=RED])[/color] l[color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]entmod[/color] l[color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]princ[/color] [color=#a52a2a]"\n--> Invalid Object Selected."[/color][color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color] [color=RED])[/color] Quote
BlackBox Posted April 21, 2011 Posted April 21, 2011 hi Renderman just tried that and it seems to do one end. image a line 200mm long and the mid point is at 0,0 then reduce the line too 150mm long but the mid point still needs to be on 0,0. hope that makes scene . cheers Lengthen always works on the end point of the line nearest to where it was picked. With one more click at the other end, you could shorten each end of the line Ugh... I tried to post a short .AVI I recorded showing you that the DYnamic option does work on the same object, for both sides, but CADTutor will not accept .AVI files. @ Lee - How do I get my own Lily Pond folder over at 'that other place' we frequent? Maybe I can use the URL instead. Ok, so I couldn't resist the urge to LISP I knew it! I was going to poke fun at your earlier step-by-step instructions, but one should never punish good behavior. LoL Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 @ Lee - How do I get my own Lily Pond folder over at 'that other place' we frequent? Ask Mr Thomas very, very nicely EDIT: I would note however, that it would likely be deemed bad 'netiquette' to use the webspace of another forum to post an item in this forum. I'm ashamed to say that I've done so in the past, but refrain from doing so now. I was going to poke fun at your earlier step-by-step instructions, but one should never punish good behavior. LoL The more I wrote the instructions, the more I wanted to write the code myself Quote
alanjt Posted April 21, 2011 Posted April 21, 2011 For fun, you can draw it. (defun c:DLL (/ p1 p2) (if (and (setq p1 (getpoint "\nSpecify first point: ")) (setq p2 (getpoint p1 "\nSpecify next point: ")) ) (entmakex (list '(0 . "LINE") (cons 10 (polar (setq p1 (trans p1 1 0)) (angle (setq p2 (trans p2 1 0)) p1) (distance p1 p2) ) ) (cons 11 p2) ) ) ) (princ) ) Quote
BlackBox Posted April 21, 2011 Posted April 21, 2011 Ask Mr Thomas very, very nicely ....Emailing him momentarily; thanks! The more I wrote the instructions, the more I wanted to write the code myself The funny part, and I could be wrong, is that I bet when you were writing the instructions... you were visualizing the LISP code in your mind, and 'translating' LISP -> English! Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 The funny part, and I could be wrong, is that I bet when you were writing the instructions... you were visualizing the LISP code in your mind, and 'translating' LISP -> English! Indeed I was! Most of the time its easier to express an idea in code Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 For fun, you can draw it. Nice idea Alan I would be more inclined to take the following route however, since polar/angle project onto the current construction plane: (defun c:dll ( / p1 p2 ) (if (and (setq p1 (getpoint "\nSpecify First Point: ")) (setq p2 (getpoint "\nSpecify Next Point: " p1)) (setq p1 (trans p1 1 0) p2 (trans p2 1 0)) ) (entmakex (list (cons 0 "LINE") (cons 10 (mapcar '- (mapcar '+ p1 p1) p2)) (cons 11 p2))) ) (princ) ) Quote
alanjt Posted April 21, 2011 Posted April 21, 2011 Nice idea Alan I would be more inclined to take the following route however, since polar/angle project onto the current construction plane: (defun c:dll ( / p1 p2 ) (if (and (setq p1 (getpoint "\nSpecify First Point: ")) (setq p2 (getpoint "\nSpecify Next Point: " p1)) (setq p1 (trans p1 1 0) p2 (trans p2 1 0)) ) (entmakex (list (cons 0 "LINE") (cons 10 (mapcar '- (mapcar '+ p1 p1) p2)) (cons 11 p2))) ) (princ) ) True. Thankfully, I don't have to worry with that in my field.I do need to spend some time on the math for it, but it's just not high priority since it's not required for our stuff. Remember, most of us code for necessity, not fun.:wink: Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 Remember, most of us code for necessity, not fun.:wink: Oh indeed, I understand. Quote
designerstuart Posted April 21, 2011 Posted April 21, 2011 Most of the time its easier to express an idea in code lee you have no idea how "beautiful mind" that makes you sound lol - respect! Quote
Lee Mac Posted April 21, 2011 Posted April 21, 2011 lee you have no idea how "beautiful mind" that makes you sound lol - respect! lol I must sound like a right nutter Quote
alanjt Posted April 21, 2011 Posted April 21, 2011 Oh indeed, I understand. Looking at the code, I understand the subtraction, but I'm not sure I grasp what adding the point one together does. Could you shed some light on that part? Quote
alanjt Posted April 21, 2011 Posted April 21, 2011 lol I must sound like a right nutter Not really, when you ones life is consumed by doing something one way, they begin to approach all aspects of their life with that approach. My first summer job of cad drafting, we were working 12 hour days (Monday thru Friday) and 4-6 hours on Saturday. I started approaching everything from an AutoCAD point of view. I would try to hit the undo button if I screwed something up in the real world. I do the same thing if I've been coding a lot. Or maybe I'm just a nutter with you. 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.