.NET

Reply
Valued Contributor
architectOfIdeas
Posts: 75
Registered: ‎08-10-2007
Message 1 of 4 (361 Views)
Accepted Solution

Unload Xref in .NET

361 Views, 3 Replies
12-13-2012 08:48 AM

In searching some other threads, I see this was discussed, but I can't find any reference to a solution in VB.

 

I was attempting to change the .IsUnloaded boolean flag on a Block Table Record (as the Developer Help does show this as read/write), but I see that as it changes the flag, even a .Commit won't actually unload the Xref. 

 

Does anyone have some VB code as an example of how to unload an Xref programmatically? Or do I have to resort to feeding the command line some strings? 

 

Thanks in advance,
Drew

Have you had a look at Database.UnloadXrefs?

Valued Contributor
architectOfIdeas
Posts: 75
Registered: ‎08-10-2007
Message 2 of 4 (349 Views)

Re: Unload Xref in .NET

12-13-2012 11:24 AM in reply to: architectOfIdeas

With a little more digging into some reference material; perhaps I should be asking whether anyone has an example of how they use XrefReloadOperation?

Active Contributor
absStructural
Posts: 37
Registered: ‎07-15-2010
Message 3 of 4 (308 Views)

Re: Unload Xref in .NET

12-17-2012 05:31 AM in reply to: architectOfIdeas

Have you had a look at Database.UnloadXrefs?

Valued Contributor
architectOfIdeas
Posts: 75
Registered: ‎08-10-2007
Message 4 of 4 (301 Views)

Re: Unload Xref in .NET

12-17-2012 10:48 AM in reply to: absStructural

I have now!! Thanks for the help as I didn't know this method existed. 

 

A basic example of how I got it to work:

 

Public Sub unloadBaseXref(ByVal strName As String)

 

'get the active document, editor and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acDocEd As Editor = acDoc.Editor
Dim acCurDb As Database = acDoc.Database

 

'start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction

 

'create a collection to house the xref object id
Dim colObjId As ObjectIdCollection = New ObjectIdCollection

 

'open the block table for read
Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

 

'step through each record in the table
For Each acObjId As ObjectId In acBlkTbl

 

'open the block table record for read
Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acObjId, OpenMode.ForRead)

 

'if the current block matches the supplied string
If acBlkTblRec.Name Like strName Then

 

'and if the current block is loaded
If acBlkTblRec.IsUnloaded = False Then

 

'add the object id to the collection
colObjId.Add(acBlkTblRec.ObjectId)

 

'unload the xref in the collection
acCurDb.UnloadXrefs(colObjId)

 

'document the change
acDocEd.WriteMessage(vbLf & strName & " unloaded")

 

End If

 

End If

 

Next

 

'commit the changes and dispose of the transaction
acTrans.Commit()

 

End Using

 

End Sub

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.