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.
Best,
~DD
Here is the drawing. Let me know if you have any questions
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.
@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?
What if a boundary is curved?
Would the direction to be extended ever be ambiguous?
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.
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.
I tried using this, but when i did the appload i got an AutoCAD message that says: "/n Type REC-PL"
I see, i typed that in and it did function correctly. Is it possible to select more than one rectangle
Also, some rectangles will be oriented horizontally. Is it possible to make them extend to the boundary as well?
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
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 .
@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 .
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
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 ?
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
Everything works great, but is it possible to make it extend to where it covers the entire area?
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
@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