Author Topic: Creating Static Block of iinstance of dynamic block  (Read 313 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Creating Static Block of iinstance of dynamic block
« 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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Creating Static Block of iinstance of dynamic block
« Reply #1 on: March 12, 2024, 02:48:38 AM »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Creating Static Block of iinstance of dynamic block
« Reply #2 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.
Speaking English as a French Frog

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Creating Static Block of iinstance of dynamic block
« Reply #3 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.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Creating Static Block of iinstance of dynamic block
« Reply #4 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.