Rotate to desired space

Rotate to desired space

rpajounia
Advocate Advocate
797 Views
6 Replies
Message 1 of 7

Rotate to desired space

rpajounia
Advocate
Advocate

If i have an ent lets say X, X is 24 inches wide and 72 inches long. lets say i want X to be inbetween points (0,10) and (34,72) or i want it to be in between (0,10) and (84,24).  can someone help me write a function that will take the end points that i want it to be inside and place it there while rotating it if necessary?

 

(defun PlaceUnit( ent pt1 pt2 / )

 

)

0 Likes
798 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

@rpajounia wrote:

... X is 24 inches wide and 72 inches long. lets say i want X to be inbetween points (0,10) and (34,72) or i want it to be in between (0,10) and (84,24).  ....

....


[If I understand correctly, I think your numbers are wrong.  Shouldn't they be (0,10) to (24,82) or (0,10) to (72,34)?  If I have misunderstood, post an image or small sample drawing.]

 

You could probably do it with a simple ALIGN command.

Kent Cooper, AIA
Message 3 of 7

rpajounia
Advocate
Advocate

i will provide the corner points circled for each option and i need it to place it on the bottom left corner position

 

PlaceUnit (ent pt1 pt2 / )

0 Likes
Message 4 of 7

TomBeauford
Advisor
Advisor

Use the MOCORO (Express Tool) command that moves, copies, rotates, and scales selected objects with a single command. https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-385D1161-6A07-432E-B69B-71C7D19409F5

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

ALIGN will certainly do that nicely, without any custom code.  And it could be done using points at opposite ends of a single edge just as well as with opposite corners.  But it will require selection of the object, picking four locations, and answering a question.  If you're looking for fewer steps [it can't be a lot fewer], is the idea that you select the object and the two destination points only?  If not, describe exactly the steps you imagine for the User.

 

Should there be any test made that the destination points are actually in the right kind of relationship to each other, i.e. that their X & Y coordinate differences match the XY size of the object?  What should be done if they don't match size and shape, such as if the object is rectangular as in your image but the points you give it are opposite corners of a square?

 

Would the object always be rectangular?  Also, would the object and the intended position always be at orthogonal orientations, or could there be other angles involved?  If the object is a Block that is orthogonal in its defined orientation, maybe that could be handled easily enough, but if it's a Polyline, or a Block at some different base orientation, it could be much more of a challenge.

 

Kent Cooper, AIA
Message 6 of 7

7598165
Advocate
Advocate

Free Copy :

During the dynamic copy process, you can freely transform the base point, rotate 90 degrees, align, scale, etc. to meet your various needs.

For details, see:  https://www.theswamp.org/index.php?topic=58897.0 

 

Free Move :

During the dynamic Move process, you can freely transform the base point, rotate 90 degrees, align, scale, etc. to meet your various needs.

For details, see:  https://www.theswamp.org/index.php?topic=58912.0 

 

Video_2024-04-22_104247.gif

 

=======================

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message

 

0 Likes
Message 7 of 7

rpajounia
Advocate
Advocate

im doing it this way

(defun PlaceUnit (ent pt1 pt2 / entObj p1 p2 width height angleR moveX moveY)
  ;; Ensure the entity handle is valid and convert to VLA-object
  (if (setq entObj (vlax-ename->vla-object ent))
    (progn
      ;; Get current bounding box corners
      (vla-getboundingbox entObj 'p1 'p2)
      (setq p1 (vlax-safearray->list p1))
      (setq p2 (vlax-safearray->list p2))

      (setq width (abs (- (cadr p2) (cadr p1))))
      (setq height (abs (- (car p2) (car p1))))
      
      ;; Move entity so its bottom-left corner aligns with pt1  
      (setq moveX (- (car pt1) (car p1)))
      (setq moveY (- (cadr pt1) (cadr p1)))
      (vla-move entObj (vlax-3d-point 0 0 0) (vlax-3d-point moveX moveY 0))
      
      ;; Calculate angle for rotation based on diagonal alignment
      (setq angleR (+ (angle pt1 pt2) (angle p1 p2)))
      
      ;; Rotate the entity to align from bottom-left to top-right as defined by pt1 to pt2
      (if (/= (equal (angle pt1 pt2) (angle p1 p2) 0.000001) t)
	  (progn
	      (vla-rotate entObj (vlax-3d-point (car pt1) (cadr pt1) 0) angleR)
	      (vla-move entObj (vlax-3d-point 0 0 0) (vlax-3d-point width 0 0))
	  )
	)
    )
  )
)
0 Likes