TheSwamp

Code Red => .NET => Topic started by: cmwade77 on March 11, 2024, 07:57:49 PM

Title: Creating Static Block of iinstance of dynamic block
Post by: cmwade77 on March 11, 2024, 07:57:49 PM
I am trying to work around some issues in CAD, so I am trying to create a static block of an instance of dynamic blocks. I have code that mostly works with this jig until I click to finish the the rotateresize jig as attached, then it throws a system exception error because it tries to copy the block again. I am using the attached block as well. I am close, just not sure what I am missing.
Title: Re: Creating Static Block of iinstance of dynamic block
Post by: gile on March 12, 2024, 02:48:38 AM
Hi,
What about using BlockReference.ConvertToStaticBlock (https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-__OVERLOADED_ConvertToStaticBlock_Autodesk_AutoCAD_DatabaseServices_BlockReference)?
Title: Re: Creating Static Block of iinstance of dynamic block
Post by: gile on March 12, 2024, 03:58:51 AM
Your CreateBlock method could be something like this:
Code - C#: [Select]
  1.         private static void CreateStaticBlock(BlockReference originalBlockRef)
  2.         {
  3.             var db = originalBlockRef.Database;
  4.             using (var tr = db.TransactionManager.StartTransaction())
  5.             {
  6.                 var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  7.                 int i = 1;
  8.                 string newName;
  9.                 do
  10.                 {
  11.                     newName = $"Nested_{i++}";
  12.                 } while (blockTable.Has(newName));
  13.                 originalBlockRef.ConvertToStaticBlock(newName);
  14.                 tr.Commit();
  15.             }
  16.         }
And this method should not be called in the Update method of the RotateResizeBlockJig. It should be called in the InsertBlock method instead.
Title: Re: Creating Static Block of iinstance of dynamic block
Post by: cmwade77 on March 12, 2024, 11:24:04 AM
Ah, my bad for not more clearly explaining what I am trying to do, I am trying to work around some issues in how jigs work with dynamic blocks. Basically, I am dynamically updating the properties of the block, creating a new block that contains that block as an entity, then erasing it as the mouse moves. It works smoothly this way, until I finish the command. I know I have seen this approach before on a website (it's what gave me the idea for this approach), but I can't find it now and so I am trying to recreate it from scratch.
Title: Re: Creating Static Block of iinstance of dynamic block
Post by: cmwade77 on March 13, 2024, 07:11:24 PM
I actually have figured out a better way around the issues by making the original block not visible, setting the properties, then making it visible again seems to work.