Valued Mentor
Posts: 380
Registered: ‎01-27-2010
Message 1 of 4 (291 Views)
Accepted Solution

How to check BlockReference

291 Views, 3 Replies
01-03-2013 03:54 AM

HI all.

So i have 3 file DWG :

3.dwg : is a plan 'archi'
2.dwg is a plan with only décoration.
1. dwg is a plan with only the water.

i have this structure in my file (1.dwg) :

---> 2..dwg
---------> 3.dwg   (this file is a Xref of 2.dwg)


--> is the blockRefecence (XRef).

my code :

        Dim CollXref As New ObjectIdCollection

        Dim mydb As Database = Application.DocumentManager.MdiActiveDocument.Database 
        Dim myTrans As Transaction = mydb.TransactionManager.StartTransaction
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim DocLock As DocumentLock = doc.LockDocument

            Dim BlocTable As BlockTable = CType(myTrans.GetObject(mydb.BlockTableId, OpenMode.ForRead), BlockTable)
            For Each btid As ObjectId In BlocTable
                Dim DefBloc As BlockTableRecord = CType(myTrans.GetObject(btid, OpenMode.ForWrite), BlockTableRecord)
                If DefBloc.IsFromExternalReference = True Then
                    If DefBloc.IsResolved = False Then
                    End If
                End If
        Catch ex As Exception
            MsgBox(ex.Message, vbOKOnly & vbCritical, "ee")
        End Try
        DocLock = Nothing


So i don't want to add Id of a Xref From a Xref. (In my example i want only ObjectId of the 2.dwg not 3.dwg if i launch this code on 1.dwg.


How i can do that ?

Posts: 5
Registered: ‎02-20-2009
Message 2 of 4 (254 Views)

Re: How to check BlockReference

01-04-2013 02:14 PM in reply to: AubelecBE

You can use the XRef Graph to determine if an XRef is nested. Here is a blog post that shows how to use the XRefGraph type:






Valued Mentor
Posts: 380
Registered: ‎01-27-2010
Message 3 of 4 (235 Views)

Re: How to check BlockReference

01-05-2013 02:56 AM in reply to: gopinatht

Thx i have to see that

Valued Mentor
Posts: 380
Registered: ‎01-27-2010
Message 4 of 4 (210 Views)

Re: How to check BlockReference

01-06-2013 02:43 AM in reply to: AubelecBE

Here my code final :


                Dim LockDoc As DocumentLock = doc.LockDocument
                Dim OkErr as boolean = false
                Dim CollXRef As New ObjectIdCollection
                    Dim xg As XrefGraph = db.GetHostDwgXrefGraph(True)
                    Dim root As GraphNode = xg.RootNode

                    Using tr As Transaction = db.TransactionManager.StartTransaction

                        For o = 0 To root.NumOut - 1 Step 1
                            Dim child As XrefGraphNode = CType(root.Out(o), XrefGraphNode)

                            If child.XrefStatus = XrefStatus.Resolved Then
                                Dim bl As BlockTableRecord = tr.GetObject(child.BlockTableRecordId, OpenMode.ForRead)

                                'ed.WriteMessage(vbCrLf & i_indent + child.Database.Filename)

                                ' Name of the Xref (found name)

                                ' You can find the original path too:
                                If bl.IsFromExternalReference = True Then
                                    ed.WriteMessage(vbCrLf & "Xref path name: " + bl.PathName)
                                    Exit For
                                End If
                            End If

                        'trouvé un xref --> Adding

                        If CollXRef.Count > 0 Then
                                doc.Database.BindXrefs(CollXRef, False)

                            Catch ex As Exception
                                okErr = True
                                MsgBox("Erreur lors de la liaison d'un Xref" & vbCrLf & "--> Essayer de lier le premier niveau", _
                                              vbOKOnly & vbCritical, _
                                              "Erreur Système")
                            End Try
                        End If
                    End Using
                    ed.WriteMessage(vbCrLf & "-> " & CollXRef.Count.ToString)
                Loop Until (CollXRef.Count = 0) Or (okErr = True)

                LockDoc = Nothing

 If check only one XRef. it is for the binf of only one XREF.

I have big file to bing and if i bing all in one troke, autocad crack for a 'Out of mémory'


I can't check it now (i am not on my work). So i don't know if i have resolve this case of out of memory.





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 or visit the Installation and Licensing Forum to get help installing your software.