How can I get Direct xref of a Particular Drawing using C# Code?

How can I get Direct xref of a Particular Drawing using C# Code?

Anonymous
Not applicable
2,820 Views
6 Replies
Message 1 of 7

How can I get Direct xref of a Particular Drawing using C# Code?

Anonymous
Not applicable

Hi All,

 

Suppose I have a Drawing Structure like:
MasterRoot
    Root1
        MasterChild1
            Child
        MasterChild2
            Child
    Root2
        MasterChild1
            Child
        MasterChild2
            Child

When I use XrefGraph xg = mainDb.GetHostDwgXrefGraph(true); in Code then I get all the Files as a node including MasterRoot (say count=6).
If I want to get Only direct Children (here, Root1 and Root2)(means count=2 only), then wha i have to do?
Is it Possible?
Any help will be appreciated.

Thanks in Advance..

Thanks & Regards,
Vasant Padhiyar

0 Likes
Accepted solutions (1)
2,821 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Have you tried the XrefGraphNode.IsNested property?

 

From the ObjectARX docs for this property:

"Returns True if this node represents a nested xref that is not directly referenced in the host drawing."

 

So in code you could check for this property to be false, i.e.:

 

XrefGraph graph = db.GetHostDwgXrefGraph(true);
for (int i = 0; i < graph.NumNodes; i++)
{
	XrefGraphNode node = graph.GetXrefNode(i);
	if (!node.IsNested)
	{
		// < Insert your code for non-nested xref here >
	}
}

 

Haven't tried this myself but hopefully this will help you out.

 

Art

Message 3 of 7

Anonymous
Not applicable

Thanks a lot...

It is really helpful for me...

0 Likes
Message 4 of 7

Anonymous
Not applicable

Hi All,

 

Now Actually I wants the xRef Structure in a Tree Structure as it is in AutoCAD Drawing.

 

How to traverse recursively to generate a Tree Structure same as xRef Structure.

 

Thanks & Regards,

Vasant Padhiyar

0 Likes
Message 5 of 7

Anonymous
Not applicable

Hi,

 

The ObjectARX docs say something like this...

 

Each reference (between databases) is represented by an edge in the graph, and can be queried by calling GraphNode.In(int index) for what is referencing this node...

 

I haven't tried to do this, but looking at the ObjectARX documentation I would try the following:

 

1. Get the root node (which is effectively the host drawing), i.e.:

 

    XrefGraph graph = db.GetHostDwgXrefGraph(true);
    XrefGraphNode rootNode = graph.RootNode;

 

2. Then use the XrefGraphNode.NumIn property and XrefGraphNode.In(int i) method to iterate child nodes recursively.
    

You might need to experiment and step through in debug mode to see what's happening under the hood. I've never looked closely at it.

 

Good luck, Art

Message 6 of 7

Anonymous
Not applicable
Accepted solution

Thanks Art,

 

I have done it using the same Concept and it works fine.

 

1. Get the root node (which is effectively the host drawing), i.e.:

 

    XrefGraph graph = db.GetHostDwgXrefGraph(true);
    XrefGraphNode rootNode = graph.RootNode;

 

2. Then use the XrefGraphNode.NumIn property and XrefGraphNode.In(int i) method to iterate child nodes recursively.

 

Thanks,

 

0 Likes
Message 7 of 7

Anonymous
Not applicable
A few days later... Finding all XREFs in the current database using C#.NET: http://adndevblog.typepad.com/autocad/2012/06/finding-all-xrefs-in-the-current-database-using-cnet.h...
0 Likes