AutoCAD Map 3D Developer

AutoCAD Map 3D Developer

Reply
Valued Mentor
gluckett
Posts: 414
Registered: ‎10-10-2003
Message 1 of 4 (780 Views)

vb.net: erase all queried objects

780 Views, 3 Replies
11-18-2009 05:56 PM
Hi All, can you help me figure out why I cant' get the enties for WRITE mode with this code. It crashes if I try to open the entity for write?

Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim psr As PromptSelectionResult = ed.SelectAll()

Dim tr As Transaction = db.TransactionManager.StartTransaction()

Using tr
For Each id As ObjectId In psr.Value.GetObjectIds()

Dim ent As Entity = DirectCast(tr.GetObject(id, OpenMode.ForWrite), Entity)

ent.UpgradeOpen()
ent.Erase()
ent.Dispose()
Next

tr.Commit()

End Using
Valued Mentor
gluckett
Posts: 414
Registered: ‎10-10-2003
Message 2 of 4 (778 Views)

Re: vb.net: erase all queried objects

12-14-2009 07:02 PM in reply to: gluckett
so the issue was the prompt ("Save Back to Source Drawing")... just turn it off.


dim mapApi as MapApplication = HostMapApplicationServices.Application
dim proj as ProjectModel = mapApi.ActiveProject
proj.Options.MarkObjectsForEditingWithoutPrompting = true
Valued Mentor
fieldguy
Posts: 379
Registered: ‎03-31-2005
Message 3 of 4 (590 Views)

Re: vb.net: erase all queried objects

04-23-2012 10:06 AM in reply to: gluckett

This works - thank you.  But, it is far slower than close without saving changes, especially if there are thousands of objects.

 

In 64 bit MAP 3D 2011

 

I am trying to figure out how to code "closeandiscard" but cannot get past the "drawing busy" error.  I have already cloned the queried objects to the dwg file I want to save and detached the drawing set.  Now I want the user to be left with a blank "drawing1".

 

From my reading it looks as if I need to give the active document a name before I can discard it?  It's confusing.

Valued Mentor
fieldguy
Posts: 379
Registered: ‎03-31-2005
Message 4 of 4 (587 Views)

Re: vb.net: erase all queried objects

04-23-2012 12:25 PM in reply to: fieldguy

Commandflags.session was the answer.  This leaves the user with a blank Drawing2 (or higher). 

 

<CommandMethod("q4", CommandFlags.Session)> _
    Sub q_4()
        Dim templatepath As String = "map2diso.dwt"
        Dim acdocmgr As acapp.DocumentCollection = acapp.Application.DocumentManager
        Dim acdoc As acapp.Document = acdocmgr.MdiActiveDocument
        'query 
        'save
        'detach
        acdoc.CloseAndDiscard()
        acdoc = acdocmgr.Add(templatepath)
        acdocmgr.MdiActiveDocument = acdoc
    End Sub

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!