by Fenton Webb
For a change, I thought I’d post some VB.NET code which utilizes acedCmd(). You know, I grew up on acedCommand() back when the original C ADS API was released back in R11 and I have to say, I still love its power and simplicity…
' zoom to selected entities using acedCmd
' by Fenton Webb, DevTech, Autodesk 09/May/2012
' (using full namespaces in VB.NET)
Public Sub ZoomToEnts()
' get the autocad editor instance
Dim ed As Autodesk.AutoCAD.EditorInput.Editor = _
Autodesk.AutoCAD.ApplicationServices. _
Application.DocumentManager.MdiActiveDocument.Editor
' get a select set of entities in the dwg window
Dim selection As PromptSelectionResult = ed.GetSelection()
' if the selection was successful
If selection.Status = PromptStatus.OK Then
' create a new .NET resbuf struct
Dim rbCommand As New Autodesk.AutoCAD.DatabaseServices.ResultBuffer
' create the buildlist
rbCommand.Add( _
New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "_ZOOM")) ' RTSTR
rbCommand.Add( _
New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "_o")) ' RTSTR
' in old ADS you could send an RTPICKS 5007 which was an ename selection
' set but I found iterating the objectIds much easier than trying to work
' out an old style ename ss from a .NET SelectionSet
Dim id As ObjectId
For Each id In selection.Value.GetObjectIds()
rbCommand.Add( _
New Autodesk.AutoCAD.DatabaseServices.TypedValue(5006, id)) ' RTENAME
Next
' exit out of entity selection
rbCommand.Add( _
New Autodesk.AutoCAD.DatabaseServices.TypedValue(5005, "")) ' RTSTR
' now call the zoom to objects command
acedCmd(rbCommand.UnmanagedObject)
End If
End Sub
Updated May 10th 2012 to add additional line breaks (to prevent code being truncated on blog).

Leave a Reply to SummerNightCancel reply