Select all in model space

Select all in model space

gwhitcherQ98HZ
Enthusiast Enthusiast
834 Views
11 Replies
Message 1 of 12

Select all in model space

gwhitcherQ98HZ
Enthusiast
Enthusiast

How do I select all without a filter and iterate through all that has been selected in VB.Net?

 

Using this code generate an error at the ed.SelectAll() line

 

Try
Dim Res As PromptSelectionResult = ed.SelectAll()
If (Res.Status = PromptStatus.OK) Then
Dim selectedIds As ObjectId() = Res.Value.GetObjectIds()
Using lk As DocumentLock = doc.LockDocument()
Using tr As Transaction = db.TransactionManager.StartTransaction()
For j = 0 To selectedIds.Count - 1
Dim ent As Entity = DirectCast(GetObjectbyID(selectedIds(j)), Entity)
ent.UpgradeOpen()
ent.ColorIndex = 8
ent.DowngradeOpen()
Next
tr.Commit()
End Using

End Using

End If
Catch ex As Exception

End Try

 

0 Likes
835 Views
11 Replies
Replies (11)
Message 2 of 12

kerry_w_brown
Advisor
Advisor

What is the error message ?

 

Is it getting caught by in the catch block ?

 

// --

Please use the '</>' button to post /format code

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 3 of 12

gwhitcherQ98HZ
Enthusiast
Enthusiast

yes. the error says: eNotApplicable

0 Likes
Message 4 of 12

kerry_w_brown
Advisor
Advisor

Are you calling this code from a form. ?

Is the document in a side database ?

 

is CommandFlags.Session added to your  CommandMethod attribute ?

( Editor interactive methods (ed.Getxxx, ed.Selectxxx, etc) can only be called on the active document )

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 5 of 12

Ed__Jobe
Mentor
Mentor

@kerry_w_brown wrote:

Please use the '</>' button to post /format code

 


Hi @kerry_w_brown 

You can refer users to this sticky post.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 6 of 12

gwhitcherQ98HZ
Enthusiast
Enthusiast

I just found out that issue. I wasn't setting the editor to the newly opened drawing. I am trying to change every entity to a specific color. I am at another error now.

0 Likes
Message 7 of 12

kerry_w_brown
Advisor
Advisor

@Ed__Jobe ,

 

Thanks Ed, I'll bookmark that.
I actually have one saved for C# code , but was in a hurry.

 

It also helps if the code is preformatted properly, but that's another issue 😉

 

Regards,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 8 of 12

kerry_w_brown
Advisor
Advisor

@gwhitcherQ98HZ 

 

good,

I assumed it would be an active document issue.

 

Regards,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 9 of 12

gwhitcherQ98HZ
Enthusiast
Enthusiast

Once I have the objectIds, I get each one as a DBObject .  I have opened each one Forwrite but I get an einvalidopenstate error

 

0 Likes
Message 10 of 12

ActivistInvestor
Mentor
Mentor

What is the exception that is thrown by the call to SelectAll()?

 

If you are trying to select all objects in model space, there really isn't any point to calling SelectAll() when you can simply get the model space BlockTableRecord and enumerate its elements. There are hundreds of code examples posted here that demonstrate how to do that.

Message 11 of 12

gwhitcherQ98HZ
Enthusiast
Enthusiast

I found the problem. I was not resetting the database or the editor when I opened a new drawing

0 Likes
Message 12 of 12

kerry_w_brown
Advisor
Advisor

@gwhitcherQ98HZ ,

 

Aside from Tony's excellent point  . . . 

 

The main thing to learn from this thread is to provide a good description of the problem conditions and to provide sufficient (readable and pre-formatted) code to allow deciphering the problem.

Regards,

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper