Community
public bool IsBlockInDrawing(string BlockName, out ObjectId BlockId){
bool BlockIsInDrawing = false;ObjectId tmpID = new ObjectId();BlockId = tmpID;
using (Transaction tr = db.TransactionManager.StartTransaction())using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false)){
foreach (ObjectId tmpBlockId in bt){
using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(tmpBlockId, OpenMode.ForRead, false)){
if (String.Compare(btr.Name, BlockName, true) == 0){
BlockIsInDrawing =
true;BlockId = tmpBlockId;
break;}
}
}
tr.Commit();
return BlockIsInDrawing;}
}
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<RolandF> wrote in message
href="news:5182890@discussion.autodesk.com">news:5182890@discussion.autodesk.com...
I do it with the following code, but i don't know
if it is the best way:
public bool IsBlockInDrawing(string BlockName, out ObjectId BlockId){
bool BlockIsInDrawing = false;ObjectId tmpID = new ObjectId();BlockId = tmpID;
using (Transaction tr = db.TransactionManager.StartTransaction())using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false)){
foreach (ObjectId tmpBlockId in bt){
using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(tmpBlockId, OpenMode.ForRead, false)){
if (String.Compare(btr.Name, BlockName, true) == 0){
BlockIsInDrawing =
true;BlockId = tmpBlockId;
break;}
}
}
tr.Commit();
return BlockIsInDrawing;}
}
hp workstation xw4200, 3GB
quadro
fx1400
AutoCAD 2007, 3DSMax 8.0 SP 2
"Matt" <Finally trying to
href="mailto:nospam@nowhere.com">
size=2>nospam@nowhere.com> schrieb im
Newsbeitrag
face=Arial size=2>news:5182844@discussion.autodesk.com
face=Arial size=2>...
get my hands dirty on .NET. It's not that easy really
How do i find
a BlockTabelRecord from a name?
In objectArx i got the objectId using
AcDbBlockTable::getAt(const ACHAR*
entryName,AcDbObjectId&
recordId);
Then I created a new AcDbBlockReference using the id, added it
to the
database and i was done.
In .NET I can not find any GetAt
method. Do I have to iterate the enumerator
and find it by
myself?
I'm to old for this new stuff. Guess i should stay with Arx
and ADS 😉
/Matt
if (!BlockId.IsErased)BlockIsInDrawing =
true;
public bool IsBlockInDrawing(string BlockName, out ObjectId BlockId){
bool BlockIsInDrawing = false;BlockId =
new ObjectId(); using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false)){
try{
BlockId = bt[BlockName];
using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(BlockId, OpenMode.ForRead, false)){
if (!btr.IsLayout && !btr.IsAnonymous)BlockIsInDrawing =
true;}
}
catch{
}
tr.Commit();
return BlockIsInDrawing;}
}
Can't find what you're looking for? Ask the community or share your knowledge.