.NET

.NET

Reply
*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 11 of 13

Re: Definition of Dynamic Blocks with .NET API

02-25-2012 08:11 AM in reply to: cean_au

I hope bobbydehero will not make a sense on me..

Try this slightly eedited code

{code}

        [CommandMethod("DynamicPropertiesTest","dyntest", CommandFlags.Modal )]
        public static void TestDynProps()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;
           
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockReference bref = trans.GetObject(ed.GetEntity("\nSelect dynamic block").ObjectId, OpenMode.ForRead) as BlockReference;
                if (bref == null)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Nothing or wrong object selected");
                    return;
                }
               
                if (!bref.IsDynamicBlock)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("selected is not dynamick block");
                    return;
                }
                BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));

                BlockTableRecord btrec = trans.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForRead,false) as BlockTableRecord;
                string sDynBlk = btrec.Name;
                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)
                                                {
                                                    foreach (object obj in pDataTable)
                                                    {
                                                        ed.WriteMessage("\n\t{0}", obj.ToString());
                                                    }
                                                }
                                            }
                                        }

                                        if (eExpr.GetType() == typeof(BlockLookupParameter))
                                        {
                                            BlockLookupParameter blup = eExpr as BlockLookupParameter;
                                            if (blup != null)
                                            {
                                                BlockParameterPropertyDescriptorCollection props = blup.PropertyDescription;
                                                Array pDataTable;
                                                foreach (BlockParameterPropertyDescriptor prop in props)
                                                {
                                                    ed.WriteMessage("\n\t{0}", prop.PropertyName);
                                                    pDataTable = prop.ValueSetValues;
                                                    if (pDataTable != null)
                                                    {
                                                        foreach (object obj in pDataTable)
                                                        {
                                                            ed.WriteMessage("\n\t{0}", obj.ToString());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (eExpr.GetType() == typeof(BlockFlipParameter))
                                        {
                                            BlockFlipParameter blup = eExpr as BlockFlipParameter;
                                            if (blup != null)
                                            {
                                                BlockParameterPropertyDescriptorCollection props = blup.PropertyDescription;
                                                Array pDataTable;
                                                foreach (BlockParameterPropertyDescriptor prop in props)
                                                {
                                                    ed.WriteMessage("\n\t{0}", prop.PropertyName);
                                                    pDataTable = prop.ValueSetValues;
                                                    if (pDataTable != null)
                                                    {
                                                        foreach (object obj in pDataTable)
                                                        {
                                                            ed.WriteMessage("\n\t{0}", obj.ToString());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        //---------  add other actions / parameters same way here   -------------------//
                                    }
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.ToString());
                        }
                    }
                }
            }
        }

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
100 Posts
2 Kudos
Registered: ‎07-11-2011
Post 12 of 13

Re: Definition of Dynamic Blocks with .NET API

02-28-2012 01:08 AM in reply to: Hallex

ed.GetEntity("\nSelect dynamic block"

 

this still needs a dyna block first, not create one from scrath by program.

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 13 of 13

Re: Definition of Dynamic Blocks with .NET API

02-28-2012 03:16 AM in reply to: cean_au

Do it yourself

I go out from there

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
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!