Rectangle Extend

Rectangle Extend

Anonymous
Not applicable
7,223 Views
43 Replies
Message 1 of 44

Rectangle Extend

Anonymous
Not applicable

Is there anyone with a command that can make a rectangle extend to a polyline/line?

0 Likes
7,224 Views
43 Replies
Replies (43)
Message 2 of 44

CodeDing
Advisor
Advisor

This is quite a cumbersome task actually. It is never so black & white. Consider the following example below.. While I believe I understand HOW you would want the final product to look, coding such a feat will take a very skilled individual. It's a bit above my level at the moment, but I'm interested to see what others come up with.

image.png

Best,

~DD

0 Likes
Message 3 of 44

devitg
Advisor
Advisor

Please upload your sample.dwg before and after 

0 Likes
Message 4 of 44

Anonymous
Not applicable

Here is the drawing. Let me know if you have any questions

0 Likes
Message 5 of 44

Anonymous
Not applicable

What I'm looking for is a command just like the extend command, but will be able to extend a rectangle just like it does lines and polylines.

0 Likes
Message 6 of 44

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

What I'm looking for is a command just like the extend command, but will be able to extend a rectangle just like it does lines and polylines.


So many questions arise....

 

Extend to any kind of boundary object?  At any angle?  If the boundary to be extended to is not parallel  to the end of the rectangle, what should it do?

ExtendRectangle.JPG

What if a boundary is curved?

Would the direction to be extended ever be ambiguous?

ExtendRectangle2.JPG

In such a case, would it work to require that you select the rectangle on the edge that should move  [in whatever way it should]?  That would cover the possibility in your sample drawing that you might want the rectangle Extended to the right and left sides rather than to the top and bottom.

 

In your sample drawing, the same rectangle is Extended twice, in opposite directions, to the same boundary.  Should that require two selections, as it would if the rectangle was a Line  that you wanted Extended in both directions, or would you want that done with one  selection of the rectangle?

 

[If none of those complications are to be encountered, and they're always like your sample, you could do a  w h o l e   l o t   of them with Stretch, with ENDpoint (or INTersection) and PERpendicular Object Snap modes running, in the time it would take someone to come up with a routine to automate it.]

 

It might be possible to come up with a concept if the rectangles you want extended are always and only  four-sided closed Polylines and actually rectangular [all corners 90 degrees].  If there might be other configurations, I imagine all bets are off.

 

Kent Cooper, AIA
Message 7 of 44

devitg
Advisor
Advisor

Please try it  Just as ask , Not any guess. 

 

0 Likes
Message 8 of 44

Anonymous
Not applicable

Yes it would need to extend to any type of boundary or angle. It would need to function like the second example from the right on your image so that the rectangle covers the entire area. I envisioned it functioning like the extend command, so you would select the perimeter boundary that you want to extend to and then you select the side of the rectangle that you want to extend to that boundary. 

0 Likes
Message 9 of 44

Anonymous
Not applicable

I tried using this, but when i did the appload i got an AutoCAD message that says: "/n Type REC-PL"

0 Likes
Message 10 of 44

Anonymous
Not applicable

I see, i typed that in and it did function correctly. Is it possible to select more than one rectangle

0 Likes
Message 11 of 44

Anonymous
Not applicable

Also, some rectangles will be oriented horizontally. Is it possible to make them extend to the boundary as well?

0 Likes
Message 12 of 44

hak_vz
Advisor
Advisor

Few questions.

a) Will you always have layers named RECTANGLE and LIMITS? Why not make this function applicable to others.

b) Extension of a rectangle must always be in both directions?

c) Extension is always in a direction of rectangle longer side?

d) Rectangles will only be horizontal and vertical?

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 13 of 44

devitg
Advisor
Advisor

Just so type: REC-PL at the command line . But this lisp do not meet your need . Please upload a sample dwg with such samples , as you need .  

0 Likes
Message 14 of 44

devitg
Advisor
Advisor

@Anonymous wrote:

Also, some rectangles will be oriented horizontally. Is it possible to make them extend to the boundary as well?


No it will not . I have to think other way .

 

0 Likes
Message 15 of 44

Anonymous
Not applicable

a) Will you always have layers named RECTANGLE and LIMITS? Why not make this function applicable to others. There will be several layers. I only had rectangle and limits in my drawing for illustration purposes

b) Extension of a rectangle must always be in both directions? yes, sometimes it will need to be extended vertically, sometime it will need to extend horizontally

c) Extension is always in a direction of rectangle longer side? correct

d) Rectangles will only be horizontal and vertical? correct

0 Likes
Message 16 of 44

devitg
Advisor
Advisor

Please be so gentle to upload your sample DWG ,. A true real life . 

 

Will it to be  extend to one or both sides of the LIMITS boundary ?

 

0 Likes
Message 17 of 44

hak_vz
Advisor
Advisor

Here is starting code, modification possible if after you check how it works for you.

To run use command EXTEND_RECTS.

How it works.

For each rectangle object - lwpolyline it extracts 4 points, finds two sides, and in direction of longer side through midpoints of two perpendicular sides it finds midpoints and a direction of extension. It looks for a intersection points with boundary object, recalculates new point positions and modifies starting rectangle  so that it retain all his properties (layer, color .....).

 

(defun c:extend_rects ( / acadObj doc modelSpace ss i boundary_element pts ma mb mc md dis_1 dis_2 direction lineObj intPoints pa pb p1 p2 p3 p4 ang1 ang2 ent *error*)
; hak_vz 19.01.2020 
;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
;
(vl-load-com)
(defun *error* () (princ))
(defun getpoints (e / i  ent pts)
    (setq 
        ent 
            (entget e)
         i 0 
    )
    (repeat
        (length ent)     
            (if (eq (car (nth i ent)) 10)
                (setq 
                    pts 
                        (append pts (list (cdr (nth i ent))))
                )
            )
            (setq 
                i
                    (+ i 1)
            )
    )
pts
)

(defun midpoint (pt1 pt2)(list (/ (+ (car pt1) (car pt2)) 2.0)(/ (+ (cadr pt1)(cadr pt2)) 2.0)))


(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq modelSpace (vla-get-ModelSpace doc))  


(princ "\nSelect rectangles >")
(setq ss (ssget) i 0)
(setq boundary_element (car(entsel "\nSelect extension boundary >")))
(cond 
((and ss)
 (while (< i (sslength ss))
    (setq 
        pts (getpoints (ssname ss i))
        ma (midpoint (nth 0 pts) (nth 1 pts))
        mb (midpoint (nth 1 pts)(nth 2 pts))
        mc (midpoint (nth 2 pts) (nth 3 pts))
        md (midpoint (nth 3 pts) (nth 0 pts))
        dis_1 (distance ma mc) 
        dis_2 (distance mb md)
    )
    (if (> dis_1 dis_2)
        (setq direction (list ma mc) rectwidth (distance mb md))
        (setq direction (list mb md) rectwidth (distance ma mc))
    )
(setq pts nil lineObj (vla-Addline modelSpace (vlax-3d-point (car direction)) (vlax-3d-point  (cadr direction))))
(setq intPoints (vla-IntersectWith lineObj (vlax-ename->vla-object boundary_element) 1))
(entdel (entlast))
(setq intPoints (vlax-variant-value intPoints))
(setq intPoints (vlax-safearray->list intPoints))
(setq pa (list (nth 0 intPoints)(nth 1 intPoints) (nth 2 intPoints)) pb (list (nth 3 intPoints)(nth 4 intPoints)(nth 5 intPoints)))
(setq ang1 (+ (angle (car direction)(cadr direction))(/ pi 2)))
(setq ang2 (- (angle (car direction)(cadr direction))(/ pi 2)))
(setq p1 (polar pa ang1 (/ rectwidth 2.0)))
(setq p4 (polar pa ang2 (/ rectwidth 2.0)))
(setq p2 (polar pb ang1 (/ rectwidth 2.0)))
(setq p3 (polar pb ang2 (/ rectwidth 2.0)))
(setq ent (entget(ssname ss i)))
(setq ent (vl-remove-if '(lambda (x) (= (car x) 10)) ent))
(setq ent (apply 'append  (cons ent (mapcar 'list (mapcar '(lambda (a) (cons 10 a)) (list p1 p2 p3 p4))))))
(setq ent (entmod ent))
(setq i (+ i 1))
 )   
))
(princ)
)

If it works select this as a final solution.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 18 of 44

Anonymous
Not applicable

REC EXTEND.JPG

Everything works great, but is it possible to make it extend to where it covers the entire area?

0 Likes
Message 19 of 44

devitg
Advisor
Advisor

It seem to be you want to calculate the area surrounded by a some like  mathematical function.

If you would start asking for it , no such work about extending rectangle would be need .

Lisp has the capability to do such calc.

That is the problem when some Poster ask what to  do , when it is better to ask HOW to do. 

 

Like : do any forum user know how to calc the area given  by a given function?

For more illustration here is my sample.dwg 

 

 

 

 

0 Likes
Message 20 of 44

hak_vz
Advisor
Advisor

@devitg wrote:

It seem to be you want to calculate the area surrounded by a some like  mathematical function.

If you would start asking for it , no such work about extending rectangle would be need .

Lisp has the capability to do such calc.


I don't think @Anonymous  wants that. What he has shown is a result he receives when extend rectangles to a curve with the code I provided. I also supposed that he wants to retain rectangle shape, but what he wants is a rectangle that deforms into a such a way that rectangle side stick to boundary curve i.e. sloped line.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes