.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
704 Views, 13 Replies
12-24-2007 01:51 PM
Hi to all. I have'nt seen a lot on xrefs bind. So I've done an effort on my side and wanted to share this code with you. It's a basic Bind Command. You can send me your comments if you wish!
Don't forget to put the < before the commandmethod!!!
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
CommandMethod("BindAllXrefs")> _
Public Sub BES()
Dim bTransMan As DatabaseServices.TransactionManager
Dim bTrans As DatabaseServices.Transaction
Dim bDwg As Document
Dim bBT As BlockTable
Dim bBTR As SymbolTableRecord
Dim bBTE As SymbolTableEnumerator
bDwg = Application.DocumentManager.MdiActiveDocument
bTransMan = bDwg.TransactionManager
bTrans = bTransMan.StartTransaction
Try
'Open the database for Read
bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForR ead)
bBTE = bBT.GetEnumerator
Dim XrefIds As New ObjectIdCollection
While bBTE.MoveNext = True
bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
'Check if block is xref and add if so, add it's ID to the ObjectIdCollection
If bBTR.IsResolved And Not bBTR.Name.Contains("|") Then
XrefIds.Add(bBTR.Id)
End If
End While
'Bind xref of collection
bDwg.Database.BindXrefs(XrefIds, True)
'Important to commit
bTrans.Commit()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
bTrans.Dispose()
bTransMan.Dispose()
End Try
End Sub
Don't forget to put the < before the commandmethod!!!
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
CommandMethod("BindAllXrefs")> _
Public Sub BES()
Dim bTransMan As DatabaseServices.TransactionManager
Dim bTrans As DatabaseServices.Transaction
Dim bDwg As Document
Dim bBT As BlockTable
Dim bBTR As SymbolTableRecord
Dim bBTE As SymbolTableEnumerator
bDwg = Application.DocumentManager.MdiActiveDocument
bTransMan = bDwg.TransactionManager
bTrans = bTransMan.StartTransaction
Try
'Open the database for Read
bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForR
bBTE = bBT.GetEnumerator
Dim XrefIds As New ObjectIdCollection
While bBTE.MoveNext = True
bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
'Check if block is xref and add if so, add it's ID to the ObjectIdCollection
If bBTR.IsResolved And Not bBTR.Name.Contains("|") Then
XrefIds.Add(bBTR.Id)
End If
End While
'Bind xref of collection
bDwg.Database.BindXrefs(XrefIds, True)
'Important to commit
bTrans.Commit()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
bTrans.Dispose()
bTransMan.Dispose()
End Try
End Sub
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-24-2007 09:30 PM in reply to:
bertyboy
Hi Again! I just wanted to specifie that this code is for Autocad 2008.
And also Merry Christmas to all !!!
And also Merry Christmas to all !!!
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-28-2008 10:17 PM in reply to:
bertyboy
Hi,
Thanks for the code. But I have a question. What if the xrefs are unresolved? How do I handle the unresolved xrefs, like 'Not Found', 'Unloaded', 'Unreferenced'?
Thanks
Thanks for the code. But I have a question. What if the xrefs are unresolved? How do I handle the unresolved xrefs, like 'Not Found', 'Unloaded', 'Unreferenced'?
Thanks
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-29-2008 03:41 PM in reply to:
bertyboy
I love good questions!
I'm not an expert on this. But I find out that you could convert the
"SymbolTableRecord" to a "BlockTableRecord" with:
dim BlcTabRec as BlockTableRecord = _ Ctype(YourSymTableRecVariable,BlockTableRecord)
the BlcTabRec have a couple of property you could use.
Like:
IsUnloaded
IsFormExternalReference
IsResolved
But for the:
'Not Found', 'Unreferenced'
I think you could use the "IsResolved" property.
If Not IsResolved(BlcTabRec ) then Msgbox "Problem here!!"
Just for information, there's an automatic Bind command part of the etransmit command in Autocad 2008. That's very cool!
Cad Programmer
Bert
I'm not an expert on this. But I find out that you could convert the
"SymbolTableRecord" to a "BlockTableRecord" with:
dim BlcTabRec as BlockTableRecord = _ Ctype(YourSymTableRecVariable,BlockTableRecord)
the BlcTabRec have a couple of property you could use.
Like:
IsUnloaded
IsFormExternalReference
IsResolved
But for the:
'Not Found', 'Unreferenced'
I think you could use the "IsResolved" property.
If Not IsResolved(BlcTabRec ) then Msgbox "Problem here!!"
Just for information, there's an automatic Bind command part of the etransmit command in Autocad 2008. That's very cool!
Cad Programmer
Bert
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-17-2008 10:39 PM in reply to:
bertyboy
You're great, man!
dim BlcTabRec as BlockTableRecord = _ Ctype(YourSymTableRecVariable,BlockTableRecord)
What is YourSymTableRecVariable? Could you please help on how that would go into code.
Thanks
dim BlcTabRec as BlockTableRecord = _ Ctype(YourSymTableRecVariable,BlockTableRecord)
What is YourSymTableRecVariable? Could you please help on how that would go into code.
Thanks
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-17-2008 10:39 PM in reply to:
bertyboy
And why the _?
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-17-2008 11:19 PM in reply to:
bertyboy
Ok...I got it!
Dim BlkTabRec As BlockTableRecord = CType(bBTR, BlockTableRecord)
But unfortunatly it's not working.
Dim BlkTabRec As BlockTableRecord = CType(bBTR, BlockTableRecord)
But unfortunatly it's not working.
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-18-2008 05:55 PM in reply to:
bertyboy
Me it's working very fine. So I send you the code updated.
Oh ya! You guessed right for what you wrote!
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Microsoft.Office.Interop
Imports Microsoft.VisualBasic.ApplicationServices
Imports System.IO
< CommandMethod("BindAllXrefs") > _
Public Sub BES()
Dim bTransMan As DatabaseServices.TransactionManager
Dim bTrans As DatabaseServices.Transaction
Dim bDwg As Document
Dim bBT As BlockTable
Dim bBTR As SymbolTableRecord
Dim bBTE As SymbolTableEnumerator
Dim bBTRr As BlockTableRecord
' Current Document
bDwg = Application.DocumentManager.MdiActiveDocument
bTransMan = bDwg.TransactionManager
bTrans = bTransMan.StartTransaction
Try
' Open the database for Read
bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForR ead)
bBTE = bBT.GetEnumerator
Dim XrefIds As New ObjectIdCollection
While bBTE.MoveNext = True
bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
bBTRr = CType(bBTR, BlockTableRecord)
' Check if block is xref and also resolved and thenadd its ID to the ObjectIdCollection
If bBTRr.IsFromExternalReference And bBTRr.IsResolved Then
XrefIds.Add(bBTR.Id)
End If
End While
' Bind xref of collection
Try
'We bind all xrefs of drawing
bDwg.Database.BindXrefs(XrefIds, True)
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
' Important to commit
bTrans.Commit()
bSave(bDwg)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
bTrans.Dispose()
bTransMan.Dispose()
End Try
End Sub
Maybe if it doesn't work, a error message could help you up!
Cad Programmer
Bert
Oh ya! You guessed right for what you wrote!
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Microsoft.Office.Interop
Imports Microsoft.VisualBasic.ApplicationServices
Imports System.IO
< CommandMethod("BindAllXrefs") > _
Public Sub BES()
Dim bTransMan As DatabaseServices.TransactionManager
Dim bTrans As DatabaseServices.Transaction
Dim bDwg As Document
Dim bBT As BlockTable
Dim bBTR As SymbolTableRecord
Dim bBTE As SymbolTableEnumerator
Dim bBTRr As BlockTableRecord
' Current Document
bDwg = Application.DocumentManager.MdiActiveDocument
bTransMan = bDwg.TransactionManager
bTrans = bTransMan.StartTransaction
Try
' Open the database for Read
bBT = bDwg.Database.BlockTableId.GetObject(OpenMode.ForR
bBTE = bBT.GetEnumerator
Dim XrefIds As New ObjectIdCollection
While bBTE.MoveNext = True
bBTR = bBTE.Current.GetObject(OpenMode.ForRead)
bBTRr = CType(bBTR, BlockTableRecord)
' Check if block is xref and also resolved and thenadd its ID to the ObjectIdCollection
If bBTRr.IsFromExternalReference And bBTRr.IsResolved Then
XrefIds.Add(bBTR.Id)
End If
End While
' Bind xref of collection
Try
'We bind all xrefs of drawing
bDwg.Database.BindXrefs(XrefIds, True)
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
' Important to commit
bTrans.Commit()
bSave(bDwg)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
bTrans.Dispose()
bTransMan.Dispose()
End Try
End Sub
Maybe if it doesn't work, a error message could help you up!
Cad Programmer
Bert
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-06-2008 05:21 AM in reply to:
bertyboy
After a long gap!
Thanks for the code. I did some modifications in the code to suit my requirements, and it did work fine. But after I run a certain AutoCAD command, I get an error that says 'eWasOpenForWrite'. Seems like the command is opening the database and forgets to close! Is there any workaround that can be done in our code?
Thanks
Thanks for the code. I did some modifications in the code to suit my requirements, and it did work fine. But after I run a certain AutoCAD command, I get an error that says 'eWasOpenForWrite'. Seems like the command is opening the database and forgets to close! Is there any workaround that can be done in our code?
Thanks
Re: Bind Xrefs
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-07-2008 03:09 PM in reply to:
bertyboy
You should be an expert of vb.net by the time! 
I don't know, I haven't gone more far on this issue. And it seems that we are two caring about that! Everything seems to be ok but maybe there a problem with the Autodesk BindXrefs function. Maybe they'll enhance it for Autocad 2009. Have you seen it! The interface is pretty cool, I should say awesome!
Bert
Cad programmer
I don't know, I haven't gone more far on this issue. And it seems that we are two caring about that! Everything seems to be ok but maybe there a problem with the Autodesk BindXrefs function. Maybe they'll enhance it for Autocad 2009. Have you seen it! The interface is pretty cool, I should say awesome!
Bert
Cad programmer


