Message 1 of 5
How to Rotate Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a window that selects some objects (rectangle and two lines, sometimes just a rectangle).
I have seen code that shows how to rotate a single object, but not really much for multiple objects.
Some things I've seen use a "For Each" to get all of the ObjectIds in the selection set and rotate each one. Can someone show me how to create an ObjectIdCollection from a selection set?
I did this, but it just errors out on the rotation:
' If the component doesn't rotate or does a complete 180, do not rotate it
If dblCompRot <> 0 Or dblCompRot <> 180 Then
Dim myDB As DatabaseServices.Database
Dim myEd As EditorInput.Editor
Dim compPSR As EditorInput.PromptSelectionResult
Dim compSelSet As SelectionSet
Dim compObjIDs As ObjectIdCollection
Dim comp As Object
Dim ssWinX1 As Double, ssWinX2 As Double, ssWinY1 As Double, ssWinY2 As Double, ssWinPt1 As Point3d, ssWinPt2 As Point3d
myDB = myDWG.Database
myEd = myDWG.Editor
' Select the SMD component using a window
compCenter = New Geometry.Point3d(compCenterX, compCenterY, 0)
ssWinX1 = compCenterX - ((dblCompLen / 2) + 0.02)
ssWinX2 = compCenterX + ((dblCompLen / 2) + 0.02)
ssWinY1 = compCenterY - ((dblCompWid / 2) + 0.02)
ssWinY2 = compCenterY + ((dblCompWid / 2) + 0.02)
ssWinPt1 = New Geometry.Point3d(ssWinX1, ssWinY1, 0)
ssWinPt2 = New Geometry.Point3d(ssWinX2, ssWinY2, 0)
compPSR = myEd.SelectWindow(ssWinPt1, ssWinPt2)
'compSelSet = compPSR.Value
Try
'Dim compPSR As PromptSelectionResult = ed.SelectAll
compSelSet = compPSR.Value
If compSelSet.Count > 0 Then
compObjIDs = New ObjectIdCollection(compSelSet.GetObjectIds)
For Each compObjId In compObjIDs
comp = compObjId.GetObject(OpenMode.ForWrite)
Dim m3d As Matrix3d = Matrix3d.Rotation((dblCompRot * (Math.PI / 180)), Geometry.Vector3d.ZAxis, compCenter)
'Dim ent2 As Entity = tr.GetObject(oid, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
comp.TransformBy(m3d)
Next
End If
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End If
End Sub
Thanks,
Mark