embed line to a med point of a polyline

embed line to a med point of a polyline

GeryKnee
Advocate Advocate
870 Views
4 Replies
Message 1 of 5

embed line to a med point of a polyline

GeryKnee
Advocate
Advocate

Helo to everyone.

If i want to embed a line to plyline, i have to use filet, that will embed it to an edge of the polyline, cutting the polyline if needed.

I need a code wich will embed it to a med point, like a nail sticking out the polyline.

 

Here is the description.

 

1. If selection not exists, asks for user selection.

2. From the selection gothers one pair (the first found) of  A::: a polyline B:: a line that has acommon point with the line.

3. After the code execution line does not exist and polyline has two more vertices added at the position of the common point (the first is the other and second the commot).

example :

 

polyline : 1,2,3,....  N,  N+1,n+2,...pEnd  Vertices Count = pNend

Line                         NPout

After code execution

Edited polyline : 1,2,3,....   N, Pout,  N,    n+1,n+2,...pEnd   Vertices Count = pNend + 2

 

Regards

Gery

 

0 Likes
Accepted solutions (1)
871 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

Post a image or dwg before after example no idea what you want.

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

I think I understand what you want.  If so, here's one way to do it, in simplest terms:

 

(vl-load-com)
(defun C:TEST ()
  (setq
    pl (car (entsel "\nPolyline: "))
    lin (car (entsel "\nLine that touches it at one end: "))
    ldata (entget lin)
    lin1 (cdr (assoc 10 ldata))
    lin2 (cdr (assoc 11 ldata))
    pt (if (equal lin1 (vlax-curve-getClosestPointTo pl lin1) 0.01) lin1 lin2)
  ); setq
  (command "_.break" pl "_non" pt "@")
  (setq pl2 (entlast))
  (command
    "_.pedit" pl "_join" lin "" ""
    "_.line" "_non" (vlax-curve-getEndPoint pl) "_non" pt ""
    "_.pedit" pl "_join" (entlast) pl2 "" ""
  ); command
  (princ)
); defun

 

It BREAKs the Polyline where the Line touches it, and PEDIT/Joins the Line to it.  Then it draws another LINE from the new endpoint of the joined Polyline back to that touching point, and PEDIT/Joins that Line and the remainder of the original Polyline to the Polyline that had the original Line joined to it.

 

For now, it relies on you selecting the right two things, not missing, and that the Line does touch the Polyline at one end.  If it gives the result you want, it can be enhanced to verify the selections, and that they touch in the right way, accept pre-selection if any, and add the usual things like *error* handling, Undo begin/end, etc.

Kent Cooper, AIA
Message 4 of 5

Kent1Cooper
Consultant
Consultant

By the way, the code works only if the Polyline is a lightweight one.  When Broken, their "upstream" part keeps the same entity name as the original whole.  The results of Breaking "heavy" ones [such as one that has been spline-fit] get new entity names, so the first PEDIT/Join command fails.  If that's a possibility, it can be accounted for.

Kent Cooper, AIA
0 Likes
Message 5 of 5

GeryKnee
Advocate
Advocate

The routine works fine. Does exactly the work that i want.

The only one i have to say, is that it's easier to use another selection senario.

a) User selects objects first and then calls the routine.

    OR

b) User calls the routine, routine prompts 'select a polyline and a line' and user selects objects.

    Code uses the existant selection.

    If selection includes at least one polyline and one line with the common point, the code understands

    that has to work with them , and is executing using those first collected objects, ignoring any other.

    If none pair of polyline and line can be gothered, code prompts 'select a polyline and a line'.

    The option to use existant selection or create a selection is very very important

 

That's a generaly good way to draw.

Routines written using this double face senario makes drawing comfotatable.

Anyway, the routine works and i'm happy for that and i thank you very mach.

If you have time to change the selection senario, that will be better.

Regards,

Gery.

0 Likes