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

How can I bind xrefs?

2 REPLIES 2
Reply
Message 1 of 3
rubendm
277 Views, 2 Replies

How can I bind xrefs?

Hi all,
I am having some trouble with external references. I have a little library of drawings containing single blocks. My app attaches that blocks as external references to a document and creates block references with them. The problem is with layers: even though I assign those references to a layer, it does not work. I mean: when I hide the layer, the blocks are still visible.

Before reading some docs, I saw there is no way to assign other layer than the original to a Xref Block reference. As the doc says, I would need to bind the Xrefs to be able to assign a new layer to my block references.

I have been reading ObjectARX help to see how implement this: I saw the key was in cloning, but I was not able to understand how to clone an entity from another database to my database, and find the cloned one.

It would be fantastic if someone could send me an example, article, etc, on how to solve this.

Thanks in advance 🙂

Rubén
2 REPLIES 2
Message 2 of 3
rubendm
in reply to: rubendm

Hi again,
After taking another look at the ObjectARX docs, I saw I could resolve this using Database.Insert()

Doing this, I am able to insert in my documents all the objects contained in my external docs as block definitions (BlockTableRecord elements).

Anyway, I am still having problems. I am using this piece of code to create the new BlockTableRecord's:


///////////////////////////////////////////////////////////////////////////////////////////////////////////
Dim bt As BlockTable = Nothing
Dim blkOid As ObjectId = Nothing

Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()

Try
bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
blkOid = bt.Item(blockName)
Catch ex As Exception
Dim etiqDefDoc As Document = Application.DocumentManager.Open(defFilePath, True)
Dim etiqDefDB As Database = etiqDefDoc.Database

blkOid = db.Insert(blockName, etiqDefDB, True)

etiqDefDoc.CloseAndDiscard()

trans.Commit()
Finally
trans.Dispose()
End Try

///////////////////////////////////////////////////////////////////////////////////////////////////////////

But sometimes I am getting an [eNoDocument] error. I tried to use Database.ReadDwgFile() instead of calling DocumentManager.Open(), but I got an AccessViolationException error ("Attempted to read or write protected memory"). I saw some posts at the forum reflecting the same problem, but I still don't have an answer.

I also have been checking the value of DocumentManager.IsApplicationContex, but it is [False] before and after the error happens.

Any kind of help would be appreciated

Thanks in advance
Message 3 of 3
rubendm
in reply to: rubendm

Hi all,
I solved the problems with the exceptions. Finally, I preferred to use ReadDwgFile rather than Document.Open(). The reasons are the following:

- Document.Open() REALLY opens the document in a new MDA window.
- The eNoDocument error. Still don't know why I got this... Maybe I was working in the wrong execution context...

I finally was able to use ReadDwgFile without getting the AccessViolationException. The key was testing my app out of the VS 2005 debug environment.

I wish this post can help someone in the future.

This was a monologue, but anyway, thanks X-D

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