.NET

.NET

Reply
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 11 of 13 (318 Views)

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
cean_au
Posts: 100
Registered: ‎07-11-2011
Message 12 of 13 (290 Views)

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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 13 of 13 (284 Views)

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
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.