.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

find if ExternalReferences Is Nested Reference

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Danny.isr
1492 Views, 3 Replies

find if ExternalReferences Is Nested Reference

 
3 REPLIES 3
Message 2 of 4
StephenPreston
in reply to: Danny.isr

You could try looking at the XrefGraph for the drawing - see Database.GetHostDwgXrefGraph(). Here's a blog post that shows how to use that function, although not for the same reason you want it - http://through-the-interface.typepad.com/through_the_interface/2009/05/importing-autocad-layers-from...

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 3 of 4
lukasz.taraszka
in reply to: Danny.isr

First You have to realize how does the xrefs works. The external references are placed in block table as a block table records. They are in a flat structure (opposite to tree structure) it means if we have attached drawing which have another external references, those references will be in top level in block table or they will be entity in model space.

 

Here is explaination:

 

MainDrawing.dwg

|

|---AttachedDrawing.dwg

||---AnotherAttachedDrawing.dwg

||---AttachedJpg.jpg

||---Picture.bmp

|

|---AnotherDrawing.dwg

 

BlockTable in MainDrawing will look like this:

 

MainDrawing-BlockTable

-AttachedDrawing.dwg

-AnotherAttachedDrawing.dwg

-AnotherDrawing.dwg

-ModelSpace

-Picture.bmp

- Attached.jpg

-AttachedDrawing.dwg

-AnotherAttachedDrawing.dwg

-AnotherDrawing.dwg

- ... another block talbe records

 

We can check if attached drawing is external reference by property IsXref.


Dim AcadDocument As AcadDocument = Application.DocumentManager.MdiActiveDocument.AcadDocument

For Each block As AcadBlock In AcadDocument.Blocks
    If block.IsXRef OrElse block.ObjectID = AcadDrawing.ModelSpace.ObjectID Then
        
        ' Your code here
        
    End If
Next

If drawing is xref we can get its path, and open that document in background.

 

Dim drawing As Database = New Database(False, True)
drawing.ReadDwgFile(pathToReference, FileOpenMode.OpenForReadAndAllShare, True, Nothing)

 

You can search for each references in opened drawing and check if there are external references by Property IsFromExternalReference. If drawing contain external reference it means that it's nested reference.

 

Unfortunatelly the best way for doing this is recursion because nested references can appear on different level. The worst information is in some case You can have the same reference on different lvl or duplicated references... . It's long and hard way...

 

Dim blockTable As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
For Each blockTableRecId As ObjectId In blockTable
Dim blockTableRec = tr.GetObject(blockTableRecId, OpenMode.ForRead)
If blockTableRec.IsFromExternalReference
' Is nested reference

 


Message 4 of 4
Danny.isr
in reply to: StephenPreston

Thank you

Dim bt As Autodesk.AutoCAD.DatabaseServices.BlockTable

 Dim btr As BlockTableRecord

Dim blockId As ObjectId

 Dim iter As IEnumerator

Dim xg As XrefGraph = db.GetHostDwgXrefGraph(False)

 bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead)

 iter = bt.GetEnumerator() Do While iter.MoveNext()

 blockId = iter.Current btr = trans.GetObject(blockId, OpenMode.ForWrite)

If btr.IsFromExternalReference Then

        If Not xg.GetXrefNode(btr.Name).IsNested Then

                btr.IsUnloaded = True

                If btr.IsUnloaded = True Then

                      Dim aa As New SiWeb.BaseFileVersion(btr.PathName)

                End If

         End If

End If

Tags (1)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost