.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SelectionSet Error

2 REPLIES 2
Reply
Message 1 of 3
muthineni
423 Views, 2 Replies

SelectionSet Error

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
2 REPLIES 2
Message 2 of 3
adadnet
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.

Message 3 of 3
cincir
in reply to: adadnet

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 😉

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost