.NET

Reply
Contributor
Giri_kani
Posts: 15
Registered: ‎11-26-2013
Message 1 of 4 (176 Views)
Accepted Solution

Scaling Multiple Objects in .Net

176 Views, 3 Replies
03-28-2014 10:29 PM

I have a objectid collection, I need to scale all tha objects as the scale factor 20.

The object id collection have line,text,block and so on.

How to scale those objects using .net?

 

Please guide me.

Try this example borrowed from Jeff_H

 ''borrowed from Jeff_H
<CommandMethod("Sc20", CommandFlags.UsePickSet And CommandFlags.Redraw)> _
Public Shared Sub ScaleObjects()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim ppo As New PromptPointOptions("")
ppo.Message = vbLf & "Pick a center of scaling : "
ppo.AllowNone = False
Dim ppr As PromptPointResult
ppr = ed.GetPoint(ppo)
If ppr.Status <> PromptStatus.OK Then
Return
End If
Dim pc As Point3d = ppr.Value
Try
Using doclock As DocumentLock = doc.LockDocument()
Using tr As Transaction = doc.TransactionManager.StartTransaction()
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead), BlockTableRecord)
Dim pso As New PromptSelectionOptions
pso.MessageForRemoval = vbLf & "Nothing sdelected, try again."
pso.MessageForAdding = vbLf & "Select Objects to scale: "
pso.RejectObjectsOnLockedLayers = True
pso.RejectObjectsFromNonCurrentSpace = True
Dim res As PromptSelectionResult = ed.GetSelection(pso)
If res.Status <> PromptStatus.OK Then Return
Dim idArr() As ObjectId = res.Value.GetObjectIds()
btr.UpgradeOpen()
Dim ids As ObjectIdCollection = New ObjectIdCollection
For Each id As ObjectId In idArr
ids.Add(id)
Next
For Each id In ids
Dim ent As Entity = TryCast(tr.GetObject(id, OpenMode.ForRead, False), Entity)
If ent Is Nothing Then Return
If Not ent.IsWriteEnabled Then ent.UpgradeOpen()
ent.TransformBy(Matrix3d.Scaling(20.0, pc))
Next
tr.Commit()
End Using
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbLf & ex.StackTrace)
Finally
End Try
End Sub

 

Valued Contributor
cdinten
Posts: 61
Registered: ‎11-19-2010
Message 2 of 4 (152 Views)

Re: Scaling Multiple Objects in .Net

03-29-2014 12:25 AM in reply to: Giri_kani
using Entity.TransformBy() method, all you have to do is constructing a transform matrix that dealing with scaling
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (154 Views)

Re: Scaling Multiple Objects in .Net

03-29-2014 12:33 AM in reply to: Giri_kani

Try this example borrowed from Jeff_H

        ''borrowed from Jeff_H
        <CommandMethod("Sc20", CommandFlags.UsePickSet And CommandFlags.Redraw)> _
        Public Shared Sub ScaleObjects()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim ppo As New PromptPointOptions("")
            ppo.Message = vbLf & "Pick a center of scaling : "
            ppo.AllowNone = False
            Dim ppr As PromptPointResult
            ppr = ed.GetPoint(ppo)
            If ppr.Status <> PromptStatus.OK Then
                Return
            End If

            Dim pc As Point3d = ppr.Value
            Try
                Using doclock As DocumentLock = doc.LockDocument()
                    Using tr As Transaction = doc.TransactionManager.StartTransaction()

                        Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead), BlockTableRecord)

                        Dim pso As New PromptSelectionOptions

                        pso.MessageForRemoval = vbLf & "Nothing sdelected, try again."
                        pso.MessageForAdding = vbLf & "Select Objects to scale: "
                        pso.RejectObjectsOnLockedLayers = True
                        pso.RejectObjectsFromNonCurrentSpace = True
                        Dim res As PromptSelectionResult = ed.GetSelection(pso)
                        If res.Status <> PromptStatus.OK Then Return
                        Dim idArr() As ObjectId = res.Value.GetObjectIds()

                        btr.UpgradeOpen()
                        Dim ids As ObjectIdCollection = New ObjectIdCollection
                        For Each id As ObjectId In idArr
                            ids.Add(id)
                        Next

                        For Each id In ids
                            Dim ent As Entity = TryCast(tr.GetObject(id, OpenMode.ForRead, False), Entity)
                            If ent Is Nothing Then Return
                            If Not ent.IsWriteEnabled Then ent.UpgradeOpen()
                            ent.TransformBy(Matrix3d.Scaling(20.0, pc))
                        Next

                        tr.Commit()
                    End Using
                End Using
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbLf & ex.StackTrace)
            Finally
            End Try
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
Giri_kani
Posts: 15
Registered: ‎11-26-2013
Message 4 of 4 (104 Views)

Re: Scaling Multiple Objects in .Net

04-02-2014 12:48 AM in reply to: Hallex

This is working fine.. 

 

Thank you so much..

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.