
Originally Posted by
dgorsman
Not sure thats possible for "all" objects, since they don't all have a qualified insertion point. Take a line, for example - do you use the end point (which one?), or the middle? What about heavy/light polylines, 3D polylines? "Rectangle" isn't an object, it may be a single polyline or multiple lines. Dimensions are another story altogether.
Its quite possible, if one will consider the center of the bounding box as base point for rotation of objects without Rotation property or Insertion point. About dimension objects, I don't think there's a need for them to be rotated. But if needed, together with the objects not included, you can add their object names in the Select Case clauses.
Here's the code. Modify as needed.
Code:
Sub RotateObjects(RotAngle)
Dim xEnt As AcadEntity
Dim cMin As Variant
Dim cMax As Variant
Dim BoundingBoxCenter(0 To 2) As Double
On Error Resume Next
For Each xEnt In ThisDrawing.ActiveSelectionSet
Select Case xEnt.ObjectName
Case "AcDbPolyline", "AcDbLine", "AcDb3dSolid", "AcDbEllipse", "AcDb2dPolyline"
xEnt.GetBoundingBox cMin, cMax
BoundingBoxCenter(0) = cMin(0) + (cMax(0) - cMin(0)) / 2
BoundingBoxCenter(1) = cMin(1) + (cMax(1) - cMin(1)) / 2
BoundingBoxCenter(2) = 0
RotBasePt = BoundingBoxCenter
Select Case RotAngle
Case "POLARANG"
xEnt.Rotate RotBasePt, ThisDrawing.GetVariable("POLARANG")
Case "-POLARANG"
xEnt.Rotate RotBasePt, ThisDrawing.GetVariable("POLARANG") * -1
Case Else
xEnt.Rotate RotBasePt, ThisDrawing.Utility.AngleToReal(RotAngle, acDegrees)
End Select
Case Else 'Objects with Rotation property (blocks,text,mtext etc)
Select Case RotAngle
Case "POLARANG"
xEnt.Rotation = xEnt.Rotation + ThisDrawing.GetVariable("POLARANG")
Case "-POLARANG"
xEnt.Rotation = xEnt.Rotation - ThisDrawing.GetVariable("POLARANG")
Case Else
xEnt.Rotation = xEnt.Rotation + ThisDrawing.Utility.AngleToReal(RotAngle, acDegrees)
End Select
End Select
Next xEnt
ThisDrawing.SelectionSets.Item("CURRENT").Delete
End Sub
Now you can use the routine in a toolbar button/keyboard shortcut macro. You can even use the POLARANG variable for the rotation angle or any desired angle in degrees. For me, I have buttons for clockwise and counter-clockwise rotation. By the way, this routine uses the currently selected objects (ActiveSelection), so make sure you select first before issuing the command.
examples.
_vbastmt;RotateObjects("POLARANG");
_vbastmt;RotateObjects("-POLARANG"); 'opposite direction
_vbastmt;RotateObjects("-45");