How to Rotate Selected Objects

How to Rotate Selected Objects

mgorecki
Collaborator Collaborator
1,646 Views
4 Replies
Message 1 of 5

How to Rotate Selected Objects

mgorecki
Collaborator
Collaborator

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

0 Likes
1,647 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> how to create an ObjectIdCollection from a selection set?

if tSSet is declared like that:

    Dim tSSet As Autodesk.AutoCAD.EditorInput.SelectionSet

then you can create an objectidcollection in that way:
    Dim tObjIdColl As ObjectIdCollection = New ObjectIdCollection(tSSet.GetObjectIds)


HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 5

Hallex
Advisor
Advisor

You can try this example as too, cnange entity name to your suit

        <CommandMethod("SelCL")> _
        Public Sub GetObjectIdsFromSelection()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Dim res As PromptSelectionResult
            res = ed.GetSelection
            If res.Status <> PromptStatus.OK Then
                Return
            End If
            Dim sset As SelectionSet = res.Value
            Dim ids As ObjectIdCollection = New ObjectIdCollection()
            For Each id As ObjectId In sset.GetObjectIds()
                ' extract just lines and circles without filter:
                If id.ObjectClass.DxfName = "LINE" Or id.ObjectClass.DxfName = "CIRCLE" Then
                    ids.Add(id)
                End If
            Next
            MsgBox(String.Format("Selected {0} lines and circles", ids.Count))
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 4 of 5

Anonymous
Not applicable

mgorecki Use and try:

 

Dim compObjIDs as  ObjectId()=compSelSet.GetObjectIds()

 

I think this is where the problem happen.

0 Likes
Message 5 of 5

mgorecki
Collaborator
Collaborator

Thank you all for your help.  I will give these a try and see what happens.

 

Best regards,

Mark

0 Likes