.NET

.NET

Reply
New Member
2 Posts
0 Kudos
Registered: ‎11-10-2008
Post 1 of 13

Definition of Dynamic Blocks with .NET API

1420 Views, 12 Replies
11-10-2008 06:56 AM
Hello, I'd like to know if it is possible, with the .NET API provided in AutoCAD 2009, to define dynamic blocks (dynamic properties and actions) completely from .NET code (VB.NET or C#).

If yes, can someone provide me a tutorial about this issue ?

Thank you.
*Tony Tanzillo
Post 2 of 13

Re: Definition of Dynamic Blocks with .NET API

11-10-2008 08:25 AM in reply to: uomopinza

Unfortunately no, the authoring elements were not publicly
exposed.


 

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

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello,
I'd like to know if it is possible, with the .NET API provided in AutoCAD
2009, to define dynamic blocks (dynamic properties and actions) completely
from .NET code (VB.NET or C#). If yes, can someone provide me a tutorial about
this issue ? Thank you.
Valued Contributor
57 Posts
0 Kudos
Registered: ‎07-10-2008
Post 3 of 13

Re: Definition of Dynamic Blocks with .NET API

01-13-2009 02:27 AM in reply to: uomopinza
Is it possible to show the dynamic properties?

I can retreive AttributeDefinitions, but no properties...
Contributor
15 Posts
1 Kudo
Registered: ‎01-12-2009
Post 4 of 13

Re: Definition of Dynamic Blocks with .NET API

01-13-2009 04:52 AM in reply to: uomopinza
sample code for iterating all dynamic blkrefs of MS and accessing their prop's:

using (BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead, false))
{
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
{
foreach(ObjectId objId in btr)
{
using (DBObject dbObj = trans.GetObject(objId, OpenMode.ForRead, false))
{
if (dbObj != null && dbObj.GetType() == typeof(BlockReference))
{
try
{
BlockReference br = dbObj as BlockReference;
if (br != null && br.IsDynamicBlock)
{
DynamicBlockReferencePropertyCollection dynBlkRefProps = br.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty dynProp in dynBlkRefProps)
{
// ... access dynprop methods
// dynProp... PropertyName, Value, GetAllowedValues()
}
}
}
catch (System.Exception ex)
{
// ...
}
}
}
}
}
}
Valued Contributor
57 Posts
0 Kudos
Registered: ‎07-10-2008
Post 5 of 13

Re: Definition of Dynamic Blocks with .NET API

01-14-2009 02:31 AM in reply to: uomopinza
Hi bobbydehero,

Thanks for your answer. However, this is not what I am looking for.

What you are describing, is how to get the PropertyREFERENCES from a BlockREFERENCE.

What I need to do is find the PropertyDEFINITIONS from a BlockDEFINITION.

I can extract the AttributeDefinitions from a blockDefinitions by iterating it's entities, but I still have not found how to extract the Properties...
Contributor
15 Posts
1 Kudo
Registered: ‎01-12-2009
Post 6 of 13

Re: Definition of Dynamic Blocks with .NET API

01-14-2009 04:53 AM in reply to: uomopinza
Ok, I'm not sure whether this suggestion works, before I've tried myself... but you might find something if you do this:

1) try querying the BlockTableRecord (that is dynamic) extension dictionary
2) get the "ACAD_ENHANCEDBLOCK" entry and examine the resbuf's - maybe you can find something there.
Valued Contributor
57 Posts
0 Kudos
Registered: ‎07-10-2008
Post 7 of 13

Re: Definition of Dynamic Blocks with .NET API

01-14-2009 05:56 AM in reply to: uomopinza
Hi, thanks, I'll try that.

For now, we'll create a BlockReference in memory and access the Properties that way...
Contributor
15 Posts
1 Kudo
Registered: ‎01-12-2009
Post 8 of 13

Re: Definition of Dynamic Blocks with .NET API

01-14-2009 06:10 AM in reply to: uomopinza
Yeah, that's probably wise... I ran a quick test and found out that the ACAD_ENHANCEDBLOCK dictionary entry is an EvalGraph object that is not exposed in the .Net framework (Autodesk.AutoCAD.DatabaseServices.EvalGraph).

I then tried C++ and the corresponding AcDbEvalGraph class is accessible for 3rd party dev's, but the implementation of the node classes are still not public - meaning you can only access them as AcDbObjects, here's a printout of the class descriptor names (for my sample dynamic block table record):
AcDbBlockStretchAction
AcDbBlockMoveAction
AcDbBlockVisibilityParameter
AcDbBlockVisibilityGrip
AcDbBlockGripExpr
AcDbBlockGripExpr
AcDbBlockLookupParameter
AcDbBlockLookupAction
AcDbBlockLinearParameter
AcDbBlockLinearGrip
Contributor
15 Posts
1 Kudo
Registered: ‎01-12-2009
Post 9 of 13

Re: Definition of Dynamic Blocks with .NET API

03-24-2009 11:04 AM in reply to: uomopinza
bertvan -

It's actually possible to read the dynamic properties from a BlockTableRecord if you for some reason still want to...
Here's some sample code, and you'll need to reference the unsupported acmgdinternal module for it (generally not recommended):

Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
if (bt.Has(sDynBlk) == true)
{
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[sDynBlk], OpenMode.ForRead);
if (btr.IsDynamicBlock)
{
try
{
DBDictionary extDictDynBT = (DBDictionary)trans.GetObject(btr.ExtensionDictionary, OpenMode.ForRead, false);
DBObject acadEnhancedBlk = (DBObject)trans.GetObject(extDictDynBT.GetAt("ACAD_ENHANCEDBLOCK"), OpenMode.ForRead, false);
EvalGraph graph = null;
ObjectId idGraph = acadEnhancedBlk.ObjectId;
if (!idGraph.IsNull)
graph = (EvalGraph)trans.GetObject(idGraph, OpenMode.ForRead);

if (graph != null)
{
int [] iNodes = graph.GetAllNodes();
foreach(int iNode in iNodes)
{
DBObject node = graph.GetNode((uint)iNode, OpenMode.ForRead, trans);
if (node != null)
{
EvalExpr eExpr = node as EvalExpr;
if (eExpr.GetType() == typeof(BlockLookupAction))
{
BlockLookupAction blua = eExpr as BlockLookupAction;
if (blua != null)
{
Array pDataTable;
LookupColumnDescriptorCollection descArray;
blua.GetLookupTable(out pDataTable, out descArray);
if (pDataTable != null)
{
....


if (eExpr.GetType() == typeof(BlockLookupParameter))
{
BlockLookupParameter blup = eExpr as BlockLookupParameter;
if (blup != null)
{
BlockParameterPropertyDescriptorCollection props = blup.PropertyDescription;
foreach (BlockParameterPropertyDescriptor prop in props)
{
....
Valued Contributor
100 Posts
2 Kudos
Registered: ‎07-11-2011
Post 10 of 13

Re: Definition of Dynamic Blocks with .NET API

02-25-2012 02:07 AM in reply to: uomopinza

just wondering if it can be done now?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!