How to use vla-rotate with a selection set?

How to use vla-rotate with a selection set?

JBerns
Advisor Advisor
2,544 Views
5 Replies
Message 1 of 6

How to use vla-rotate with a selection set?

JBerns
Advisor
Advisor

Greetings, Community.

 

The VLA-Rotate method requires an object, base point, and an angle.

How would you use the VLA-Rotate method with a selection set?

Is there an easy way to convert a selection set to an object?

 

The selection set was created using code by Wold and Puckett:

https://www.cadtutor.net/forum/topic/56008-select-copy-of-an-object-after-copy-command/

 

Thank you for your time and attention. I look forward to your replies.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Accepted solutions (1)
2,545 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

@JBerns wrote:

.... The VLA-Rotate method requires an object, base point, and an angle.  How would you use the VLA-Rotate method with a selection set?  Is there an easy way to convert a selection set to an object? ....

 

 

Don't be afraid of the (command) function -- far easier in this case.  I expect with (vla-rotate) you would need to step through the selection set and do each one separately.  [Or, a crazy concept -- you could define the selection set into a Block, and then (vla-rotate) that....]

Kent Cooper, AIA
0 Likes
Message 3 of 6

JBerns
Advisor
Advisor

@Kent1Cooper,

 

Thanks for the quick reply.

 

I had resorted to using the (command) function for the rotate step, but I was hoping to avoid it if I could. I had considered a block too, but more steps then to explode and purge the block. I wondered about creating a group, but that too would require extra steps to clean-up after its use.

 

It must be a tedious process then to perform basic edits (move, rotate, etc.) on several objects using only VLA methods.

 

Thanks again.

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 4 of 6

ronjonp
Mentor
Mentor
Accepted solution

What is keeping you from iterating the selection and using vla-rotate? Here's a simple helper function to do it:

(defun _rotate (ss bp ang / o)
  (cond	((and (= 'pickset (type ss)) bp ang)
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	   (vlax-invoke (setq o (vlax-ename->vla-object x)) 'rotate bp ang)
	   (vla-update o)
	 )
	)
  )
)
(_rotate (ssget ":L") (getpoint) (getangle))

 Or if you want to return a list of vla-objects from the pickset:

(defun _rotate (ss bp ang / o)
  (cond	((and (= 'pickset (type ss)) bp ang)
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	   (mapcar '(lambda (x)
		      (vlax-invoke (setq o (vlax-ename->vla-object x)) 'rotate bp ang)
		      ;; Faster without vla-update btw
		      (vla-update o)
		      o
		    )
		   (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
	   )
	 )
	)
  )
)
(_rotate (ssget ":L") (getpoint) (getangle))
0 Likes
Message 5 of 6

JBerns
Advisor
Advisor

@ronjonp,

 

Thank you for the solution!

 

I am slowly transitioning to using more VL and VLA functions in my code.

 

Based on my familiarity with the AutoCAD ROTATE command, I thought there might be a way to process a selection set with a VL or VLA method. So nothing was stopping me from using iteration, other than lack of knowledge.

 

It makes sense now that when you rotate multiple objects (a selection set) with AutoCAD ROTATE, behind the scenes, each object must be rotated one at a time (iterated).

 

I think this solution will prove valuable to help me expand my VL/VLA knowledge. Thank you again.

 

 

Kind regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 6 of 6

ronjonp
Mentor
Mentor

Glad to help out ! 🙂

0 Likes