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

Anonymous Blocks with .NET

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
2756 Views, 3 Replies

Anonymous Blocks with .NET

Anyone know of a straightf orward way to create anonymous blocks using managed classes (VB or C# .NET)? I am converting an old AutoLisp program in which I used number of anonymous blocks to store small tables within a drawing. There are a number of simpler ways to store these tables using .NET, but I need compatibility with existing drawings (a large number of them). Easy to do with 'entmake' but I can't seem to find any usable info in the Autodesk documentation. (What else is new??)
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Set the BlockTableRecord's Name property to "*U" (before you add it to the
block table).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


wrote in message news:6192560@discussion.autodesk.com...
Anyone know of a straightf orward way to create anonymous blocks using
managed classes (VB or C# .NET)? I am converting an old AutoLisp program in
which I used number of anonymous blocks to store small tables within a
drawing. There are a number of simpler ways to store these tables using
.NET, but I need compatibility with existing drawings (a large number of
them). Easy to do with 'entmake' but I can't seem to find any usable info in
the Autodesk documentation. (What else is new??)
Message 3 of 4
Anonymous
in reply to: Anonymous

Thanks for taking the time to answer a daft question Tony. Realized that after I sent it. Converting old ALisp pgms can be tiring......
Rgds

Charles Eglington
Message 4 of 4
Anonymous
in reply to: Anonymous

Here a code to create a anonymous block : 

 

 

static public ObjectId InsertBlockInstance(String blockName, Point3d point = new Point3d(), String layerName = "")
{
ObjectId returnID = new ObjectId();

Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

using (Transaction myT = db.TransactionManager.StartTransaction())
{
//Get the block definition "Check".
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;

BlockTableRecord blockDef = bt[blockName].GetObject(OpenMode.ForRead) as BlockTableRecord;

//Also open modelspace - we'll be adding our BlockReference to it
BlockTableRecord ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;

//Create new BlockReference, and link it to our block definition
using (BlockReference blockRef = new BlockReference(point, blockDef.ObjectId))
{
//SET THE LAYER
if (layerName == "") //SET TO THE CURRENT LAYER
blockRef.LayerId = db.Clayer;
else
blockRef.Layer = layerName;

BlockTableRecord blkTblRcd = myT.GetObject(blockRef.BlockTableRecord, OpenMode.ForWrite) as BlockTableRecord;
blkTblRcd.Name = "*U";

//Add the block reference to modelspace
returnID = ms.AppendEntity(blockRef);
myT.AddNewlyCreatedDBObject(blockRef, true);

//Iterate block definition to find all non-constant
// AttributeDefinitions
foreach (ObjectId id in blockDef)
{
DBObject obj = id.GetObject(OpenMode.ForRead);
AttributeDefinition attDef = obj as AttributeDefinition;

if ((attDef != null) && (!attDef.Constant))
{
//This is a non-constant AttributeDefinition
//Create a new AttributeReference
using (AttributeReference attRef = new AttributeReference())
{
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
//attRef.TextString = "";
attRef.TextString = attDef.TextString;

//Add the AttributeReference to the BlockReference
blockRef.AttributeCollection.AppendAttribute(attRef);

myT.AddNewlyCreatedDBObject(attRef, true);
}
}
}
}

//Our work here is done
myT.Commit();
}

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report