• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    New Member
    Posts: 2
    Registered: ‎11-10-2008

    Definition of Dynamic Blocks with .NET API

    986 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.
    Please use plain text.
    *Tony Tanzillo

    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.
    Please use plain text.
    Valued Contributor
    Posts: 57
    Registered: ‎07-10-2008

    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...
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎01-12-2009

    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)
    {
    // ...
    }
    }
    }
    }
    }
    }
    Please use plain text.
    Valued Contributor
    Posts: 57
    Registered: ‎07-10-2008

    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...
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎01-12-2009

    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.
    Please use plain text.
    Valued Contributor
    Posts: 57
    Registered: ‎07-10-2008

    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...
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎01-12-2009

    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
    Please use plain text.
    Contributor
    Posts: 15
    Registered: ‎01-12-2009

    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)
    {
    ....
    Please use plain text.
    Valued Contributor
    cean_au
    Posts: 99
    Registered: ‎07-11-2011

    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?

    Please use plain text.