Author Topic: Determine if Dynamic Block has an Alignment Paramter  (Read 344 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Determine if Dynamic Block has an Alignment Paramter
« on: February 26, 2024, 06:29:57 PM »
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#: [Select]
  1. private static bool HasAlignmentParameter(BlockReference blockRef)
  2.         {
  3.             if (blockRef.IsDynamicBlock)
  4.             {
  5.                 foreach (DynamicBlockReferenceProperty prop in blockRef.DynamicBlockReferencePropertyCollection)
  6.                 {
  7.                     if (prop.PropertyName.Equals("Alignment", StringComparison.OrdinalIgnoreCase))
  8.                     {
  9.                         return true;
  10.                     }
  11.                 }
  12.             }
  13.             return false;
  14.         }

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Determine if Dynamic Block has an Alignment Paramter
« Reply #1 on: February 27, 2024, 04:10:14 AM »
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#: [Select]
  1.         [CommandMethod("TEST")]
  2.         public static void Test()
  3.         {
  4.             var doc = Application.DocumentManager.MdiActiveDocument;
  5.             var db = doc.Database;
  6.             var ed = doc.Editor;
  7.  
  8.             var promptEntityOptions = new PromptEntityOptions("\nSelect Block: ");
  9.             promptEntityOptions.SetRejectMessage("\nSelected object is not a block reference.");
  10.             promptEntityOptions.AddAllowedClass(typeof(BlockReference), true);
  11.             var promptEntityResult = ed.GetEntity(promptEntityOptions);
  12.             if (promptEntityResult.Status != PromptStatus.OK)
  13.                 return;
  14.  
  15.             using (var tr = db.TransactionManager.StartOpenCloseTransaction())
  16.             {
  17.                 var br = (BlockReference)tr.GetObject(promptEntityResult.ObjectId, OpenMode.ForRead);
  18.                 var btr = (BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead);
  19.                 try
  20.                 {
  21.                     if (btr.GetDynamicPropertiesData(tr).Any(tvs => tvs.Any(tv => tv == new TypedValue(0, "BLOCKALIGNMENTPARAMETER"))))
  22.                         ed.WriteMessage("\nSelect block reference has an alignment parameter");
  23.                     else
  24.                         ed.WriteMessage("\nSelect block reference has none alignment parameter");
  25.                 }
  26.                 catch (System.Exception ex) { ed.WriteMessage($"\n{ex.Message}"); }
  27.                 tr.Commit();
  28.             }
  29.         }
« Last Edit: February 27, 2024, 05:35:23 AM by gile »
Speaking English as a French Frog

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Determine if Dynamic Block has an Alignment Paramter
« Reply #2 on: February 28, 2024, 12:32:39 PM »
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.