Valued Contributor
73 Posts
0 Kudos
Registered: ‎10-10-2011
Post 1 of 3

SelectionSet Error

198 Views, 2 Replies
11-18-2011 04:30 AM
I am using the below code to get all the selected objects in a selection, Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput _ Public Sub SelectObjectsOnscreen() '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Request for objects to be selected in the drawing area Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection() '' If the prompt status is OK, objects were selected If acSSPrompt.Status = PromptStatus.OK Then Dim acSSet As SelectionSet = acSSPrompt.Value '' Step through the objects in the selection set For Each acSSObj As SelectedObject In acSSet '' Check to make sure a valid SelectedObject object was returned If Not IsDBNull(acSSObj) Then '' Open the selected object for write Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, _ OpenMode.ForWrite) If Not IsDBNull(acEnt) Then '' Change the object's color to Green acEnt.ColorIndex = 3 End If End If Next '' Save the new object to the database acTrans.Commit() End If '' Dispose of the transaction End Using End Sub But i am getting an error that selection is an invalid method . I am using .net framework 3.5 and dll is used in autocad 2007
Valued Contributor
95 Posts
1 Kudo
Registered: ‎11-15-2011
Post 2 of 3

Re: SelectionSet Error

01-14-2012 07:05 PM in reply to: muthineni

first, i'm not really sure, but i'll give it a try:


1. dbnull() returns only info on an entity's value, default or not, nothing about the entity itself. i'm assuming the intention is to make sure the selection set is not an empty one, i.e. that something indeed has been returned by the set. an appropriate check from the outset may be the selectionset.count;


2. the code opens the selectionobjects as entity and presumes this entity to have a colour property which can be changed. even if it has, i reckon that in order to gain access to that color property the selectionobject needs to be opened as an object that has that colour property. in other words, 'entity' is too general and could be something that has no colour property, identify what the object is accuratly enough, e.g. a line, open it as a line if that's the case and then access line.colourindex. (a filter for selection might be considered in the first place, however, only to narrow the results set, selectedobjects would still need to be opened as, e.g. line.)  entity actually has a colourindex property, but then again e.g. circle has an explode method where a circle cannot be exploded.

Active Contributor
32 Posts
1 Kudo
Registered: ‎08-12-2011
Post 3 of 3

Re: SelectionSet Error

01-14-2012 08:07 PM in reply to: FFlix

i agree with felix and add if you are calling this method from a modeless dialog or a paletteset you must lock the document.

Instead of IsDBNull you should use ObjectID.IsNull.


good luck :smileywink:

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post