Code Red > .NET

Determine if Dynamic Block has an Alignment Paramter

(1/1)

cmwade77:
I would like to know if there is a way to determine if a dynamic block contains an Alignment parameter? I tried searching for a parameter with the name Alignment, but unfortunately Alignment parameters can't be named and don't get the hardcoded name Alignment listed. This is what I tried:


--- Code - C#: ---private static bool HasAlignmentParameter(BlockReference blockRef)        {            if (blockRef.IsDynamicBlock)            {                foreach (DynamicBlockReferenceProperty prop in blockRef.DynamicBlockReferencePropertyCollection)                {                    if (prop.PropertyName.Equals("Alignment", StringComparison.OrdinalIgnoreCase))                    {                        return true;                    }                }            }            return false;        }

gile:
Hi,

As far as I know, the .NET API does not expose this.
You can get it by inspecting the BlockTableRecord DXF data (see the attached (work in progress) extension methods).
Here's a testing command:

--- Code - C#: ---        [CommandMethod("TEST")]        public static void Test()        {            var doc = Application.DocumentManager.MdiActiveDocument;            var db = doc.Database;            var ed = doc.Editor;             var promptEntityOptions = new PromptEntityOptions("\nSelect Block: ");            promptEntityOptions.SetRejectMessage("\nSelected object is not a block reference.");            promptEntityOptions.AddAllowedClass(typeof(BlockReference), true);            var promptEntityResult = ed.GetEntity(promptEntityOptions);            if (promptEntityResult.Status != PromptStatus.OK)                return;             using (var tr = db.TransactionManager.StartOpenCloseTransaction())            {                var br = (BlockReference)tr.GetObject(promptEntityResult.ObjectId, OpenMode.ForRead);                var btr = (BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead);                try                {                    if (btr.GetDynamicPropertiesData(tr).Any(tvs => tvs.Any(tv => tv == new TypedValue(0, "BLOCKALIGNMENTPARAMETER"))))                        ed.WriteMessage("\nSelect block reference has an alignment parameter");                    else                        ed.WriteMessage("\nSelect block reference has none alignment parameter");                }                catch (System.Exception ex) { ed.WriteMessage($"\n{ex.Message}"); }                tr.Commit();            }        }

cmwade77:
Wow, thank you, no wonder why I couldn't find it in a google search. This seems like such a basic thing, you would expect it to be there.

Navigation

[0] Message Index

Go to full version