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

How to select XRef in drawing

3 REPLIES 3
Reply
Message 1 of 4
jason17439
2180 Views, 3 Replies

How to select XRef in drawing

I'm trying to have the user select an XRef in a drawing, I can do this in VBA but I'm having problems in .NET. I can't find any type of XRef object to store the selection as and I'm thinking maybe I don't understand how XRefs work in .NET.

In VBA I could use the following code:

Dim ExRef As AcadExternalReference
Dim sPick As Variant
'On Error Goto code here in case user selects something other than XRef
ThisDrawing.Utility.GetEntity ExRef, sPick, "Select Xref:"

Is there anything like this in .NET?
3 REPLIES 3
Message 2 of 4

External references are treated as blocks in autocad, and accessed as such in .NET.

I just looked in the object browser, and unfortunately there does not appear to be a property in the BlockReference class which indicates whether it is an Xref, but in the BlockTableRecord class there is an XrefStatus property which indicates NotAnXref for regular block definitions, and the load status of Xref's (FileNotFound, Resolved, Unloaded, Unreferenced, Unresolved). That of course makes it tough to restrict the selection function to only allow Xrefs, but you can restrict it to BlockReferences, then open the corresponding BTR and check the XrefStatus. Also, as I recall, the code I have which uses that property also has to check the name of the block because if you loop through the block table you will see definitions that are in the Xref, but the XrefStatus of those nested definitions returns NotAnXref.

Edited by: chiefbraincloud on May 6, 2009 3:10 PM

I just looked again, and there are also two other properties IsFromExternalReference and IsFromOverlayReference, which also return incorrectly for a block definition nested in an Xref. Based on the description of what it is you are trying to do, you probably wouldn't encounter that problem, because you aren't looping through the whole block table, you are getting a selection from the user.
Dave O.                                                                  Sig-Logos32.png
Message 3 of 4
t.willey
in reply to: jason17439

You could step through the XrefGraph, and get the names of the xrefs. This way you could further limit your selection to BlockReferences with the names you have gathered of all xrefs.
Message 4 of 4
jason17439
in reply to: jason17439

Thanks for your help guys, I got it working with the following code if anybody else is interested:

//Define selection options
PromptEntityOptions PEOptions = new PromptEntityOptions("Select XRef:");
PEOptions.SetRejectMessage("\nObject must be an XRef, select XRef:");
PEOptions.AddAllowedClass(typeof(BlockReference),true);

//User selects XRef
PromptEntityResult PR = ed.GetEntity(PEOptions);

try
{
//Get block reference entity from PR
BlockReference BR = (BlockReference)Trans.GetObject(PR.ObjectId, OpenMode.ForRead);
//Get the block table record of the block reference
BlockTableRecord BTR = (BlockTableRecord)Trans.GetObject(BR.BlockTableRecord, OpenMode.ForRead);
//Perform operation of XRef here. If BTR is not an XRef it will fall through to the catch block
{

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