.NET

Reply
Valued Mentor
AubelecBE
Posts: 363
Registered: ‎01-27-2010
Message 1 of 4 (273 Views)
Accepted Solution

How to check BlockReference

273 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) :

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

        Try
            
            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
                       ....
                    Else
                        CollIdXref.Add(btid)
                    End If
                End If
            Next
            myTrans.Commit()
        Catch ex As Exception
            MsgBox(ex.Message, vbOKOnly & vbCritical, "ee")
        Finally
            myTrans.Dispose()
        End Try
        DocLock.Dispose()
        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 ?

Member
gopinatht
Posts: 5
Registered: ‎02-20-2009
Message 2 of 4 (236 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:

 

http://adndevblog.typepad.com/autocad/2012/06/finding-all-xrefs-in-the-current-database-using-cnet.h...

 

Cheers

Gopinath

Valued Mentor
AubelecBE
Posts: 363
Registered: ‎01-27-2010
Message 3 of 4 (217 Views)

Re: How to check BlockReference

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

Thx i have to see that

Valued Mentor
AubelecBE
Posts: 363
Registered: ‎01-27-2010
Message 4 of 4 (192 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
                Do
                    CollXRef.Clear()
                    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)
                                    CollXRef.Add(bl.ObjectId)
                                    Exit For
                                End If
                            End If
                        Next

                        'trouvé un xref --> Adding

                        If CollXRef.Count > 0 Then
                            Try
                                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")
                            Finally
                                tr.Commit()
                            End Try
                        End If
                    End Using
                    ed.WriteMessage(vbCrLf & "-> " & CollXRef.Count.ToString)
                Loop Until (CollXRef.Count = 0) Or (okErr = True)

                LockDoc.Dispose()
                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.

 

 

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
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 to get help installing your software.

Ask the Community