Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

point opposite line i pick

26 REPLIES 26
Reply
Message 1 of 27
autobot00
301 Views, 26 Replies

point opposite line i pick

hello folks, i have a question that im not sure i know how to ask, but i'll do my best. i have attached an image to help explain what i want. Note that i show a horizontal and vertical condition. I have 2 lines (orange lines in example) and i select them, what i want is a point away from the lines so when i offset the white line in the example it will offset it like how i have the magenta line in the example. anyone have any ideas on how i can go about this? Thanks in advance.
26 REPLIES 26
Message 21 of 27
Anonymous
in reply to: autobot00

Say the endpoints of the white line are Aend1 and Aend2, and the endpoints
of the orange line that the user selects are Bend1 and Bend2. Simple
version something like this:

(if
(or
(= Aend1 Bend1)
(= Aend2 Bend1)
)
(setq Bnearend Bend1 Bfarend Bend2)
(setq Bnearend Bend2 Bfarend Bend1)
); end if
(command "copy" "l" "" Aend1
(polar
Aend1
(angle Bfarend Bnearend)
(distance Aend1 Aend2)
)
); end copy

In English, if either end of the white line is the same as Bend1 of the
orange line, then that's the nearer end, and Bend2 is the farther end. If
not, it's the other way around. Then you copy the Last item from anyplace
(could be Aend2 instead of Aend1, or Bnearend, or 0,0, or whatever, as long
as the designation on either side of the word "polar" is the same), in the
direction from the far end to the near end of the orange line, by a distance
equal to the length of the white line.

You probably want to turn off Osnaps. You can get more sophisticated with
checking whether they actually picked something, etc. Only works when, as
you say, the white line is the last item drawn.
--
Kent Cooper


wrote...
well, i know how to get the endpoints using (cdr (assoc 11)) & (cdr (assoc
10)) but i dont know how to do the angle thing. so if u wouldnt mind, i
would appreciate the guidance.
Message 22 of 27
autobot00
in reply to: autobot00

ya know what, i think i know how to get this to work the way i need it. if i just add a move command moving both lines, from endpoint of the last line, and move to the endpoint of the original line that will give me what i need. good show indeed. Thanks to all who helped me. much appreciated.
Message 23 of 27
Anonymous
in reply to: autobot00

Try this instead

[code]
(defun C:LOF (/ adoc ang axss fepnt fspnt inpnt intpnt
len1 len2 len3 len4 line1 line2 line3 line4
mpnt ofdis sepnt ss sspnt tepnt tspnt)

(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object))
)
(alert (strcat "Select all three lines in the following order:\n"
"to the first select both parallel line\n"
"and than select perpendicular line"))
(setq ss (ssget '((0 . "LINE"))))
(setq axss (vla-get-activeselectionset adoc))
(setq line1 (vla-item axss 0)
line2 (vla-item axss 1)
line3 (vla-item axss 2))

(setq fspnt (vlax-get line1 'StartPoint)
fepnt (vlax-get line1 'EndPoint)
sspnt (vlax-get line2 'StartPoint)
sepnt (vlax-get line2 'EndPoint)
ang1 (vlax-get line1 'Angle)
ang2 (vlax-get line2 'Angle)
len1 (distance fspnt (vlax-curve-getClosestPointTo line2 fspnt))
len2 (distance fepnt (vlax-curve-getClosestPointTo line2 fepnt))
len3 (distance sspnt (vlax-curve-getClosestPointTo line1 sspnt))
len4 (distance sepnt (vlax-curve-getClosestPointTo line1 sepnt)))

(setq ofdis (min len1 len2 len3 len4))
(setq tspnt (vlax-get line3 'StartPoint)
tepnt (vlax-get line3 'EndPoint))
(setq inpnt (vlax-invoke line1 'Intersectwith line3 acextendnone))
(if (or (and (equal inpnt fepnt 0.00001)
(equal ang1 ang2 0.00001))
(and (equal inpnt fepnt 0.00001)
(not (equal ang1 ang2 0.00001))))
(setq mpnt (polar inpnt ang1 ofdis))
(setq mpnt (polar inpnt (- ang1 pi) ofdis)))
(setq line4 (vlax-invoke line3 'Copy))

(vlax-invoke line4 'Move inpnt mpnt)
(vlax-invoke line4 'Update)

(vl-catch-all-apply (function (lambda()
(mapcar (function (lambda(x)
(vlax-release-object x)))
(list line4 line3 line2 line1 axss)))))
(princ)
)
(prompt "\n\t***\tProgram is loaded \n")
(prompt "\n\t***\tType LOF to execute.. ")
(prin1)
[/code]

Fatty

~'J'~
Message 24 of 27
autobot00
in reply to: autobot00

HMMMM, seems to work. I like it, and i'll use it. Thank you.
Message 25 of 27
Anonymous
in reply to: autobot00

I have to say Fatty's routine looks overly complicated. (For example, I
don't see why it needs both originally-orange lines, or sets the offset
distance by a comparison of all four distances between their endpoints, if
that's simply the length of its line3.) But one thing that was wrong in my
previous excerpt that's right in Fatty's is the use of (equal) instead of
(=). This only requires one pick, again assuming your stipulation that the
white line is the last thing drawn (tested in 2004, and also attached):

(defun C:CopyOut (/ lastline Aend1 Aend2 perpline Bend1 Bend2 osstart
Bnearend Bfarend)
(setq lastline (entget (entlast))
Aend1 (cdr (assoc 10 lastline))
Aend2 (cdr (assoc 11 lastline))
perpline (entget (car (entsel "Pick a line to copy last line away from:
")))
Bend1 (cdr (assoc 10 perpline))
Bend2 (cdr (assoc 11 perpline))
osstart (getvar "osmode")
); end setq
(setvar "osmode" 0)
(if
(or
(equal Aend1 Bend1 0.001)
(equal Aend2 Bend1 0.001)
)
(setq Bnearend Bend1 Bfarend Bend2)
(setq Bnearend Bend2 Bfarend Bend1)
); end if
(command "copy" "l" "" Aend1
(polar
Aend1
(angle Bfarend Bnearend)
(distance Aend1 Aend2)
); end polar
); end copy
(setvar "osmode" osstart)
); end defun

You can shorten the name as you like, and/or add other controls, or adjust
the fuzz factor in the (equal) functions, etc., etc.
--
Kent Cooper


"Kent Cooper" wrote...
Say the endpoints of the white line are Aend1 and Aend2, and the endpoints
of the orange line that the user selects are Bend1 and Bend2. Simple
version something like this:

(if
(or
(= Aend1 Bend1)
(= Aend2 Bend1)
)
(setq Bnearend Bend1 Bfarend Bend2)
(setq Bnearend Bend2 Bfarend Bend1)
); end if
(command "copy" "l" "" Aend1
(polar
Aend1
(angle Bfarend Bnearend)
(distance Aend1 Aend2)
)
); end copy

In English, if either end of the white line is the same as Bend1 of the
orange line, then that's the nearer end, and Bend2 is the farther end. If
not, it's the other way around. Then you copy the Last item from anyplace
(could be Aend2 instead of Aend1, or Bnearend, or 0,0, or whatever, as long
as the designation on either side of the word "polar" is the same), in the
direction from the far end to the near end of the orange line, by a distance
equal to the length of the white line.

You probably want to turn off Osnaps. You can get more sophisticated with
checking whether they actually picked something, etc. Only works when, as
you say, the white line is the last item drawn.
--
Kent Cooper

wrote...
well, i know how to get the endpoints using (cdr (assoc 11)) & (cdr (assoc
10)) but i dont know how to do the angle thing. so if u wouldnt mind, i
would appreciate the guidance.
Message 26 of 27
Anonymous
in reply to: autobot00

>I have to say Fatty's routine looks overly complicated. (For example, I
>don't see why it needs both originally-orange lines, or sets the offset
>distance by a comparison of all four distances between their endpoints, if
>that's simply the length of its line3.) But one thing that was wrong in my
>previous excerpt that's right in Fatty's is the use of (equal) instead of
>(=). This only requires one pick, again assuming your stipulation that the
>white line is the last thing drawn (tested in 2004, and also attached)

Thanks for criticizm, Kent Coper, I agree with you
Unfortunately, this is my bad manner to write
routine, there is because of my low level of knowledge

Regards,

Fatty

~'J'~
Message 27 of 27
Anonymous
in reply to: autobot00

Not that yours is "bad" or anything -- it could probably be used under
broader circumstances, such as when the line they want to offset isn't the
last thing drawn, or the two lines they want to offset away from are not
parallel, or something. But it seemed in the more limited circumstances
that were described, there was a simpler way to do it.
--
Kent Cooper


wrote...
....
Thanks for criticizm, Kent Coper, I agree with you
Unfortunately, this is my bad manner to write
routine, there is because of my low level of knowledge

Regards,

Fatty

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost