LENGTH MATCH( POLYLINES)

LENGTH MATCH( POLYLINES)

Anonymous
Not applicable
2,239 Views
14 Replies
Message 1 of 15

LENGTH MATCH( POLYLINES)

Anonymous
Not applicable

if polylines are different length.....how to match polyline at equal lengths..

i need idea or lisp

0 Likes
2,240 Views
14 Replies
Replies (14)
Message 2 of 15

ВeekeeCZ
Consultant
Consultant

Try this... for applying the change is used the regular LENGTHEN command with the TOTAL option. So - you can use either single selection or "F" as Fence multiple selection.

 

(vl-load-com)

(defun c:MatchLength ( / en len)

  (if (and (setq en (car (entsel "\nSelect source object: ")))
           (or (wcmatch (cdr (assoc 0 (entget en))) "LINE,LWPOLYLINE,ARC")
               (prompt "\nWrong selection. Required LINE,LWPOLYLINE or ARC."))
           )
    (progn
      (setq len (cond ((= (cdr (assoc 0 (entget en))) "LWPOLYLINE")
                       (command "_.AREA" "_e" en)
                       (getvar 'PERIMETER))
                      ((vlax-curve-getDistAtPoint en (vlax-curve-getEndPoint en)))))
      (command "_.LENGTHEN" "_T" len)
      (while (> (getvar 'CMDACTIVE) 0)
        (command PAUSE))))
  (princ)
)
0 Likes
Message 3 of 15

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

.... 

... (cond ((= (cdr (assoc 0 (entget en))) "LWPOLYLINE")
                       (command "_.AREA" "_e" en)
                       (getvar 'PERIMETER))
                      ((vlax-curve-getDistAtPoint en (vlax-curve-getEndPoint en)))))
....

That AREA/PERIMETER part is there because the distance along an object at its endpoint returns 0 if it's closed, which can only happen, among the object types allowed in the routine, with a Polyline.  There's a simpler way to get around that problem, without involving the Area command and the Perimeter System Variable -- get the distance at the end Parameter instead of at the endpoint.  That returns the correct distance even if it's closed, and avoids the problem of using VLA Properties that 'Length will get it for some object types, but not for all types.  And it works for any finite-length kind of (vlax-curve)-class object [however unlikely it may be that you would ever want to match the length of some of them].  Something like this [lightly tested], which also lets you try again if you either miss or pick the wrong kind of thing:

 

(vl-load-com)
(defun c:MatchLength (/ en)
  (while
    (not
      (and
        (setq en (car (entsel "\nSelect source object: ")))
        (wcmatch (cdr (assoc 0 (entget en))) "LINE,*POLYLINE,ARC,SPLINE,ELLIPSE,CIRCLE")
      ); and
    );not
    (prompt "\nNothing selected, or not a finite-length object with linearity.")
  ); while
  (command "_.LENGTHEN" "_T"
    (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en))
  ); command
  (princ)
); defun

EDIT:  I took out the wait-for-User-input-until-the-command-is-finished part at the end.  That's appropriate if a routine changes something earlier [the current Layer, or some System Variable setting(s)] that you want to have set back, but not until after the command is done.  In this case, there's nothing to reset, and it can just leave you in the command at the end.

Kent Cooper, AIA
Message 4 of 15

ВeekeeCZ
Consultant
Consultant

You're right, of course. I am aware of a parameter, but lately, when I made some my own routines about polylines, I've lost my confidence about that. See the dwg what made me insecure. I don't think that the second rectangle was drawn by wrong technique - just different. Now, I played with that a little and I think I understand it now. (in the second sample, the end parameter is 5, not 4, but length between 4-5 is 0).

Also... I can see that an end param of LINE is its length. But - you know what is the actual value of end param of ARC?

 

BTW. The difference of kind of closing those two rectangles is significant in THIS thread. The Alan's routine I've offered returns correctly a single point at beginning/end of PL, your suggested routine creates 2 points on this spot.

0 Likes
Message 5 of 15

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

....

Also... I can see that an end param of LINE is its length. But - you know what is the actual value of end param of ARC?

 

BTW. The difference of kind of closing those two rectangles is significant....


The Parameter value along an Arc is the angle in radians from the center to the location along it, the start and end points being defined as proceeding in a CCW direction, regardless of the direction in which the Arc was drawn.

 

Yes, many routines are affected by whether a Polyline is closed as AutoCAD defines that, or merely looks closed by having its end vertex at the same place as its start vertex.

Kent Cooper, AIA
0 Likes
Message 6 of 15

ВeekeeCZ
Consultant
Consultant

Kent1Cooper wrote: 

Yes, many routines are affected by whether a Polyline is closed as AutoCAD defines that, or merely looks closed by having its end vertex at the same place as its start vertex.


No no, in this case it is properly closed, code 70 is 1. I think it's achievable only by manual drawing when you outline all the way to first segment, and then you close that, or change this parameter in Properties Palette. I would not be so keen about it if I haven't a lot of those myself.

Although, joining lines by the JOIN or PEDIT command makes the PL it with 4 vertices.

 

And thanks for explanation of arc's param.

0 Likes
Message 7 of 15

john.uhden
Mentor
Mentor

Whether it's param or perimeter, I am stupidly missing three things...

 

1.  How can you lengthen a closed polyline or a circle?  Yeah, you could use stretch, but I don't see that mentioned.

2.  Where is the target entity?  Or maybe that's 'where is the source entity'?  It appears that one entity is being lengthened to its original length.

3.  Which end is to be lengthened?  The Lengthen command needs a pick point to determine that, not just an entity name.

 

John F. Uhden

0 Likes
Message 8 of 15

ВeekeeCZ
Consultant
Consultant

John, you are the man with skills. I'm pretty sure that you can find the answers by yourself!

 

I think the only issue is that you're not familiar with the LENGTHEN command enough.

 


@john.uhden wrote:

Whether it's param or perimeter, I am stupidly missing three things...

 

1.  How can you lengthen a closed polyline or a circle?  Yeah, you could use stretch, but I don't see that mentioned.

Can't. Those objects are used only to determinate a source length.

 

2.  Where is the target entity?  ...

Selected by the user in LENGTHEN command. 

 

3.  Which end is to be lengthened?  The Lengthen command needs a pick point to determine that, not just an entity name.

See the LENGTHEN command - The end closer to users selection point. The routine leaves the user inside of LENGTHEN.

 


See the LENGTHEN's prompts...


Select an object to measure or [DElta/Percent/Total/DYnamic] <Total>: t
Specify total length or [Angle] <1.00>: 20    <end of routine, leaves the command running>

Select an object to change or [Undo]:
Select an object to change or [Undo]:

 

The red one's are filled by the routine.

The blue one's are up to user.

0 Likes
Message 9 of 15

john.uhden
Mentor
Mentor

Good explanation.  Thank you!

John F. Uhden

0 Likes
Message 10 of 15

ВeekeeCZ
Consultant
Consultant

Kent, let's be a minimalist!

 

(defun c:MatchLength ()
  (command "_.LENGTHEN")
  (princ "\nSelect source object: ")
  (command PAUSE "_T" (getvar 'PERIMETER))
  (princ)
)

John, it seems that I have a serious lack in knowledge of the LENGTHEN command too.

0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

.... 

...
  (command "_.LENGTHEN")
  (princ "\nSelect source object: ")
  (command PAUSE "_T" (getvar 'PERIMETER))
...

I wouldn't have guessed the length of the selected object in that circumstance would go into the PERIMETER System Variable, but sure enough it does -- provided you actually pick something with length at the pause.  It fails if you miss, or pick on an inappropriate object [well, it keeps working, but it uses whatever is the latest value on whatever you then pick (and any further things), rather than taking the length from that to apply to other things].

Kent Cooper, AIA
0 Likes
Message 12 of 15

john.uhden
Mentor
Mentor

The only thing minimal is your lack of knowledge.

My step-by-step brain would gather the pick using (entsel) and then feed it to the lengthen command, IF the pick and the entity selected were qualified.  Otherwise report the situation to the user.  I guess that approach comes from my years as CAD Manager/developer, where I wanted to save my own time by making things clear to the user.  Stephan Koster was the biggest help in teaching me the running (and ...) approach with plenty of ors to either continue or prompt the user what was wrong.  You can see that a lot in my work.

 

Your accolades mean a lot to me.  I am very childish in that regard.

John F. Uhden

0 Likes
Message 13 of 15

Anonymous
Not applicable

i try this lisp...it is work well...this lisp is  working for length match at starting are ending point....but my drawing the both are not  matching,because both end are (one end is bga  and anchor end is connector).so both end are matching...i need the lisp for length match in-between. 

0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....but my drawing the both are not  matching,because both end are (one end is bga  and anchor end is connector).so both end are matching...i need the lisp for length match in-between. 


I'm not sure I understand correctly -- can you post a sample drawing or image with before and after conditions?

 

If you mean that you want to apply Lengthen to both ends of the same object by the same amount, without needing to select at both ends, try this.

Kent Cooper, AIA
0 Likes
Message 15 of 15

john.uhden
Mentor
Mentor
I am not the author but have been following this thread closely. It uses
the AutoCAD LENGTHEN command on your second pick. Where you pick the
object to be lengthened makes a huge difference. Picking the object nearer
(along it's length) to one end will apply all the length adjustment to that
end and leave the other end alone. If picking the desired end is not
possible for you, then additional programming would be required to adjust
both ends (say equally, i.e. half the adjustment at each end). Or it could
be done proportionally from where the pick is made along the object's
length.

I am interpreting what you have written that you want the source and target
objects to begin and end at the same points, yet I gather that they take
different routes to get there. That would require reshaping the target to
achieve both lengths and endpoints matching. Not a clear task at all,
unless they were both arcs, in which case they would both end up with the
same radius, an easy solution.

Please let us know if my interpretation is close or way off.

John F. Uhden

0 Likes