.NET

Reply
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 1 of 3 (179 Views)

SelectionSet Error

179 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
FFlix
Posts: 95
Registered: ‎11-15-2011
Message 2 of 3 (141 Views)

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
cincir
Posts: 32
Registered: ‎08-12-2011
Message 3 of 3 (138 Views)

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:

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community