.NET

Reply
Mentor
mgorecki
Posts: 413
Registered: ‎09-23-2004
Message 1 of 5 (172 Views)

How to Rotate Selected Objects

172 Views, 4 Replies
05-02-2014 03:21 PM

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 2 of 5 (153 Views)

Re: How to Rotate Selected Objects

05-03-2014 02:07 AM in reply to: mgorecki

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 5 (144 Views)

Re: How to Rotate Selected Objects

05-03-2014 09:13 AM in reply to: mgorecki

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
Member
HONGBINREN
Posts: 3
Registered: ‎09-11-2013
Message 4 of 5 (125 Views)

Re: How to Rotate Selected Objects

05-05-2014 04:28 AM in reply to: mgorecki

mgorecki Use and try:

 

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

 

I think this is where the problem happen.

Mentor
mgorecki
Posts: 413
Registered: ‎09-23-2004
Message 5 of 5 (112 Views)

Re: How to Rotate Selected Objects

05-05-2014 08:49 AM in reply to: HONGBINREN

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

 

Best regards,

Mark

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.