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

Line between two lines

42 REPLIES 42
SOLVED
Reply
Message 1 of 43
smaher12
10166 Views, 42 Replies

Line between two lines

I am trying to draw a line between two lines and I put together the following. It works great if the start/end points are perpendicular to each other. How do I solve if line one start point is in a positive direction and line two is in a negative direction? 

 

(defun c:test ()

 (setq L1 (car (entsel "\nSelect the first line: "))
          L2 (car (entsel "\nSelect the second line: "))
 )

 (setq P1 (cdr (assoc 10 (entget L1)))
          P2 (cdr (assoc 11 (entget L1)))
          P3 (cdr (assoc 10 (entget L2)))
          P4 (cdr (assoc 11 (entget L2)))
 )

 (setq D1 (/ (distance P1 P3) 2)
          D2 (/ (distance P2 P4) 2)
 )

 (setq A1 (angle P1 P3)
          A2 (angle P2 P4)
 )

 (setq P5 (polar P1 A1 D1)
          P6 (polar P2 A2 D2)
 )
 (command "LINE" P5 P6 "")
)

42 REPLIES 42
Message 21 of 43
Kent1Cooper
in reply to: smaher12


@smaher12 wrote:
....

I was just thinking, what if you wanted to include polylines???


You could use the Bisector.lsp routine I posted a link to in Message 2, whose BI command will work with virtually anything that's straight.  It results in an Xline, which you can then Break or Trim as needed.

 

If you really want a Line, the routine would need to check for entity type, allowing Polylines as well as Lines.  If it's a Polyline, it would need to check that you picked it on a line segment rather than an arc segment, which can be done by checking whether Osnap Center returns anything.  And if you did, it would need to find the vertices on either side of the pick location.  That can certainly all be done, if the Bisector approach doesn't do it for you.

Kent Cooper, AIA
Message 22 of 43
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@smaher12 wrote:
....

I was just thinking, what if you wanted to include polylines???


...  That can certainly all be done....


For example, as in the attached upgraded version of LineBetween.lsp.

Kent Cooper, AIA
Message 23 of 43
smaher12
in reply to: Kent1Cooper


Kent1Cooper wrote:

For example, as in the attached upgraded version of LineBetween.lsp.



That is awesome! I can't believe it. Thank you very much. Let me ask you, do you typically have (vl-load-com) in your startup acaddoc.lsp?

Message 24 of 43
Kent1Cooper
in reply to: smaher12


@smaher12 wrote:
That is awesome! I can't believe it. Thank you very much. Let me ask you, do you typically have (vl-load-com) in your startup acaddoc.lsp?

You're welcome -- that was kind of fun to work out, though it didn't take much, because I already had lots of the pieces in other routines.

 

I don't have (vl-load-com) in acaddoc.lsp, but we use the Architectural Desktop overlay, which I think must include something that loads it.  That means I don't need to include it in routines in order for them to work when I test them, which therefore means I pretty regularly forget to include it in things I post.  Sorry about that -- I'll keep trying to remember....

Kent Cooper, AIA
Message 25 of 43
Anonymous
in reply to: Kent1Cooper

Hi

I need a lisp for draw a line(with z) between two feature line.

I look forward to hearing from you.

Thanjs

Message 26 of 43
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

I need a lisp for draw a line(with z) between two feature line.

....


If a "feature line" is a special kind of object in some overlay program such as for civil engineering, I won't be able to help you, at least I can't test any change to the routine.  I might be able to suggest something if you can post the entity data list for a typical one [type (entget (car (ensel))) and select one, and copy what is returned].

 

If a "feature line" is just a particular usage of a regular Line or Polyline, the routine attached to Message 22 should do what you want, assuming you want one Line as a result, and not, for instance, multiple Lines [or another Polyline] between all segments of two Polylines.

 

If you mean something other than those two possibilities, post a more detailed description of what you want to do, perhaps with an image or drawing if that helps explain it.

Kent Cooper, AIA
Message 27 of 43
David125
in reply to: smaher12

Here's a challenge, I'd like to automate drawings a line between multiple sets of lines, to essentially convert a double line floor plan to single line. I'm trying to mess with the lisp posted here but having some difficulty.

Message 28 of 43
Sea-Haven
in reply to: David125

Post a dwg with a before and after ?  To many options left right centre ?

Message 29 of 43
David125
in reply to: Sea-Haven

One of the solutions by

pbejse worked well but only allows selection of 2 lines at a time. 

Message 30 of 43
David125
in reply to: Sea-Haven

One of the solutions posted by pbejse ( l2.lsp )worked well but it still allows me to pick only 2 lines at a time. 

Message 31 of 43
Kent1Cooper
in reply to: David125

The difficulty comes in situation like the upper edge in your sample drawing.  In both the left and right portions (either side of the window), there's one outside line that encompasses the extent of two inside lines.  If those six lines are chosen in a collective selection, figuring out 1) that two mid-width Lines are to be the result, and 2) the proper extent for each of them, is going to be a real challenge for a routine to calculate.  Maybe not impossible, but difficult.  And that's a simple condition -- there's the potential for any various numbers of lines to make up one side of a wall, and some different number of lines the other, with potentially none of their endpoints being across from each other except maybe at the extreme ends, but all wanting to be represented in the result by a single mid-line along the whole wall.

Kent Cooper, AIA
Message 32 of 43
David125
in reply to: smaher12

It seemed like a simple concept at first, when I gave it a shot I just couldn't get anything to work. Thanks for the input.

Message 33 of 43
David125
in reply to: Kent1Cooper

Just a thought, my intent was to be selective about the lines to be picked, and not just one sweeping selection. I wanted to be able to select maybe 10-20 sets of lines, all the while staying away from any geometry that was meant to represent doors or windows. Is that doable?

Message 34 of 43
David125
in reply to: pbejse

This works really great, I was wondering, could this be modified to allow me to select more than one set of parallel lines? Another 7 or 8 sets would make this exactly what I need.

Message 35 of 43
john.uhden
in reply to: David125

I'm sure that @pbejse has this well in hand, but I'm just curious.  If a pair of parallel lines is of different length, then how would you want the start and end point of the new line created... an offset of the longer, an offset of the shorter, etc. etc.?

John F. Uhden

Message 36 of 43
ec-cad
in reply to: David125

Maybe add a 'loop' until done picking (2) at a time ?

(While lines

....

); while

Where lines is the selection set.

Message 37 of 43
john.uhden
in reply to: ec-cad

@ec-cad ,

Smart idea.  I would still use entsel because some dimwit would otherwise likely select more than 2 lines with a crossing.  Plus, immediately after the 2nd pick you can test for parallelity (Fewer than 0.01 occurrences per million words in modern written English).

John F. Uhden

Message 38 of 43
Sea-Haven
in reply to: smaher12

Years ago wrote get wall sizes uses a simple drag over lines to work out perp distances, the idea being to reset wall sizes to an existing drawn sizes. As the walls are part of a bigger program the wall layers are not the same having like wall-1, wall-2 etc this simplifies the automation request.

 

So can drag a line over say 8 lines sort into matched pairs and work out c/l. Repeating the line drag over for multiple walls. 

SeaHaven_0-1719140016749.png

The issue is walls are 2 lines or 4 ? Thats where layers come in handy.

SeaHaven_1-1719140113723.png

Added to do list. 

 

Put something together but need 2 solutions a single segment or a multi segment, the latter needs a drag over twice, near opposite ends.

 

Just a side note have the reverse convert single line to 2 line or 4 lines walls with option Left, Right, or Centre.

 

This is single segment, when dragging over do near one end this sorts out the line directions.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/line-between-two-lines/td-p/3781918/page/2

(defun c:lineinwall ( / oldsnap pt1 pt2 lent ss obj obj2 lst dist start end d1 d2 x)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(while (setq pt1 (getpoint "\nPick 1st point "))
  (setq pt2 (getpoint pt1 "\nPick 2nd point "))
  (setq pts (list pt1 pt2))
  (setq ss (ssget "F" pts '((0 . "LINE"))))
  (command "line" pt1 pt2 "")
  (setq lent (entlast))
  (setq obj2 (vlax-ename->vla-object lent))
  (setq lst '())
  (repeat (setq x (sslength ss))
    (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
    (setq intpt (vlax-invoke obj2 'intersectWith obj acExtendnone))
    (setq dist (distance pt1 intpt))
    (setq start (vlax-curve-getstartPoint obj))
    (setq end (vlax-curve-getEndPoint obj))
    (setq d1 (distance intpt start) d2 (distance intpt end))
    (if (< d1 d2)
    (progn
      (setq tmp start)
      (setq start end)
      (setq end tmp)
    )
    )
    (setq lst (cons (list dist start end) lst))
   )
  (setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
  (command "erase" lent "")
  (setq x 0)
  (repeat (/ (length lst) 2)
    (setq start1 (cadr (nth x lst)) start2 (cadr (nth (1+ x) lst)))
    (setq mp1 (mapcar '* (mapcar '+ start1 start2) '(0.5 0.5)))
    (setq end1 (caddr (nth x lst)) end2 (caddr (nth (1+ x) lst)))
    (setq mp2 (mapcar '* (mapcar '+ end1 end2) '(0.5 0.5)))
    (command "line" mp1 mp2 "")
    (setq x (+ X 2))
  )
)
(setvar 'osmode oldsnap)
(princ)
)
(c:lineinwall)

 

Message 39 of 43
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

Being in the northern hemisphere, I'm really not familiar with walls except that interior walls usually have vertical studs with sheetrock applied to each side.  Exterior walls also have vertical studs with sheetrock applied to the inside and sheathing and siding applied to the outside.  Those blasted architectural plans also include the foundation lines and sometimes even the roof gutters.  Even if I have a DWG or PDF I have to redraw the exterior following the dimensions labeled thereon because I don't know which endpoints to pick.

John F. Uhden

Message 40 of 43
Sea-Haven
in reply to: john.uhden

Here in Aus the most common exterior walls shown as 4 lines is, internal plaster sheet to studs, sarking and /or insulation, external wall is brick veneer, or a wall material, even corrugated iron. Internal walls would be 2 lines with typically plaster both sides. 

 

Re picking points the house in the image is drawn with strict layer control you draw objects on a preset layer. So isolate say external wall layer.

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report