<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic mirroring dynamic blocks in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6610895#M34253</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;the workflow of a certain very frequently used design involves using the measure-command and mirroring a set of dynamic blocks. After the design is finished some dynamic block attribute values are extracted (dataextraction) and delivered to the customer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;The first problem&lt;/STRONG&gt;&lt;/U&gt; is that the dynamic block [MYBLOCK] we are using has a custom rotation attribute [R1]. The block has many more custom attributes/properties as well as normal attributes. When the block is inserted with measure (with alignment to the measure path enabled) the block is rotated [R2]. When this is done the block appears correctly inserted, but the R1 value is still 0 when it should be R2&amp;nbsp; and R2 should be 0. This leads to incorrect values in the dataextraction table even though everything looks ok.&lt;/P&gt;&lt;P&gt;Correcting the block rotation to 0 was fairly easy but how do I use c# to edit a specific dynamic block attribute?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;The second problem&lt;/STRONG&gt;&lt;/U&gt; is that when the blocks are mirrored their scales change. What is the command to set a blocks scale? Should I use transform methods (scale with the inverse value of the block scale)? &lt;A title="link1" href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-D4348E23-7ECB-48F6-90B7-FB7EF42DFA8D-htm.html" target="_blank"&gt;autodesk transform&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've come so far that I have a ObjectIdCollection with all the block ID's that need to be checked for and here is what should be done (somewhat simplified)&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;R2 != 0?&lt;OL&gt;&lt;LI&gt;True: set rotation to 0, set R1=R1+R2&lt;/LI&gt;&lt;LI&gt;False: do nothing&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;scale x !=1?&lt;OL&gt;&lt;LI&gt;True: set scale to 1, adjust R1&lt;/LI&gt;&lt;LI&gt;False: do nothing&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;scale y !=1?&lt;OL&gt;&lt;LI&gt;True: set scale to 1, adjust R1&lt;/LI&gt;&lt;LI&gt;False: do nothing&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am aware that we could use more sophisticated and not so error prone methods to achieve what I described, but solving this with coding is also educational for me. All pointers are greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- F&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS. First timer here, so please be very detailed in your answers &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Oct 2016 15:49:53 GMT</pubDate>
    <dc:creator>Buzz0m</dc:creator>
    <dc:date>2016-10-09T15:49:53Z</dc:date>
    <item>
      <title>mirroring dynamic blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6610895#M34253</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;the workflow of a certain very frequently used design involves using the measure-command and mirroring a set of dynamic blocks. After the design is finished some dynamic block attribute values are extracted (dataextraction) and delivered to the customer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;The first problem&lt;/STRONG&gt;&lt;/U&gt; is that the dynamic block [MYBLOCK] we are using has a custom rotation attribute [R1]. The block has many more custom attributes/properties as well as normal attributes. When the block is inserted with measure (with alignment to the measure path enabled) the block is rotated [R2]. When this is done the block appears correctly inserted, but the R1 value is still 0 when it should be R2&amp;nbsp; and R2 should be 0. This leads to incorrect values in the dataextraction table even though everything looks ok.&lt;/P&gt;&lt;P&gt;Correcting the block rotation to 0 was fairly easy but how do I use c# to edit a specific dynamic block attribute?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;The second problem&lt;/STRONG&gt;&lt;/U&gt; is that when the blocks are mirrored their scales change. What is the command to set a blocks scale? Should I use transform methods (scale with the inverse value of the block scale)? &lt;A title="link1" href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-D4348E23-7ECB-48F6-90B7-FB7EF42DFA8D-htm.html" target="_blank"&gt;autodesk transform&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've come so far that I have a ObjectIdCollection with all the block ID's that need to be checked for and here is what should be done (somewhat simplified)&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;R2 != 0?&lt;OL&gt;&lt;LI&gt;True: set rotation to 0, set R1=R1+R2&lt;/LI&gt;&lt;LI&gt;False: do nothing&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;scale x !=1?&lt;OL&gt;&lt;LI&gt;True: set scale to 1, adjust R1&lt;/LI&gt;&lt;LI&gt;False: do nothing&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;scale y !=1?&lt;OL&gt;&lt;LI&gt;True: set scale to 1, adjust R1&lt;/LI&gt;&lt;LI&gt;False: do nothing&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am aware that we could use more sophisticated and not so error prone methods to achieve what I described, but solving this with coding is also educational for me. All pointers are greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- F&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS. First timer here, so please be very detailed in your answers &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Oct 2016 15:49:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6610895#M34253</guid>
      <dc:creator>Buzz0m</dc:creator>
      <dc:date>2016-10-09T15:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: mirroring dynamic blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6648177#M34254</link>
      <description>&lt;P&gt;I feel that posting your code would help yield a solution otherwise things are a guessing game to troubleshoot:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nevertheless this post should answer your first question at the very least:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2009/03/accessing-the-properties-of-a-dynamic-autocad-block-using-net.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2009/03/accessing-the-properties-of-a-dynamic-autocad-block-using-net.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps post more details?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 22:20:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6648177#M34254</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2016-10-26T22:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: mirroring dynamic blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6648254#M34255</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show the relevant code in order people here can help you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some tips:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ATTSYNC Command&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/attsync-in-vb-net/m-p/4645057/highlight/true#M37817" target="_self"&gt;Some similar problem solved&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gaston Nunez&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 23:04:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6648254#M34255</guid>
      <dc:creator>hgasty1001</dc:creator>
      <dc:date>2016-10-26T23:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: mirroring dynamic blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6651396#M34256</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for showing interest! The code I've managed to get together is below. There is one method, which is not given/explained. GetDynamicBlocksByName simply returns the objectids as an objectCollection. This code was written by somebody else: &lt;A title="source" href="https://www.theswamp.org/index.php?topic=31859.0" target="_self"&gt;https://www.theswamp.org/index.php?topic=31859.0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By now I've found the classes etc I need to edit the things I think I need to edit, but I've run into an unexpected problem. The dynamic block is set to scale uniformly. This means that when a block with scalefactors 1,1,1 is mirrored over a "vertical" line the scale is shown as -1,(1),(1). The parenthesis mean that they are not editable via properties. This same behavior can be tested by mirroring a block over a "horizontal" line. This also leads to scalefactors -1,(1),(1) even though they ought to be something like 1,(-1),(1) imho...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because of the uniform scale setting some of the block's functionality still seems to be affected by the negative x-scale even after setting the x-scale to 1. I believe this is due to the uniform scale setting regardless of that the y-scale is supposedly 1 after mirroring.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another strange thing is that the code is supposed to leave all the "inj"-blocks selected after the code is run. The code is also supposed to check if a blocks x-scale doesn't equal 1 and change it the block scalefactors to 1,1,1. Some blocks (when the original block is first mirrored over a vertical and then a horizontal line) still has a x-scalefactor of -1. When I run the command again nothing changes...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Am I trying to edit the wrong properties? Should I used 2d-scalefactors? Am I missing something fundamental?&lt;/STRONG&gt; All tips and comments are appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The math in the code is not entirely correct and does not result in what I'm trying to do so please don't mind the errors nor the unnecessary namespaces &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;&lt;BR /&gt;using Autodesk.AutoCAD.Runtime;&lt;BR /&gt;using Autodesk.AutoCAD.ApplicationServices;&lt;BR /&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using Autodesk.AutoCAD.Geometry;&lt;BR /&gt;using Autodesk.AutoCAD.EditorInput;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using Autodesk.AutoCAD.Internal;&lt;BR /&gt;&lt;BR /&gt;namespace resetinjek
{
    public class MyCommands
    {
        [CommandMethod("resetinj", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
        public void resetinjek()
        {
            
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            string blkName = "inj";
            ObjectIdCollection blockSet = GetDynamicBlocksByName(blkName);
            ObjectId[] blockSetArray =new ObjectId[blockSet.Count];
            blockSet.CopyTo(blockSetArray, 0);
            double xscale, yscale, brot;
            Scale3d scale1 = new Scale3d(1, 1, 1);            
            
foreach (ObjectId blockId in blockSet)
            {
                Database db = blockId.Database;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    BlockReference blockRef = trans.GetObject(blockId, OpenMode.ForWrite) as BlockReference;
                    brot = blockRef.Rotation;
                    xscale = blockRef.ScaleFactors.X;
                    yscale = blockRef.ScaleFactors.Y;
                    
                    if (brot != 0)
                    {
                        blockRef.Rotation = 0;
                                               
                        DynamicBlockReferencePropertyCollection properties = blockRef.DynamicBlockReferencePropertyCollection;
                       
foreach (DynamicBlockReferenceProperty property in properties)
                        {
                            if (xscale != 1)
                            {
                                blockRef.ScaleFactors = scale1;
                            } 

                            if (property.PropertyName == "Direction")
                            {                               
                                if (xscale &amp;lt; 0)
                                {
                                    brot += Math.PI; //adds 180 degrees to "Direction"
                                 }

                                property.Value = (double)property.Value + brot;

                            }
                        }
                    }
                    trans.Commit();
                }            
            }
            Utils.SelectObjects(blockSetArray);
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 19:57:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6651396#M34256</guid>
      <dc:creator>Buzz0m</dc:creator>
      <dc:date>2016-10-27T19:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: mirroring dynamic blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6652007#M34257</link>
      <description>&lt;P&gt;I think you've muddled&amp;nbsp;the nesting of the if statements?? -- try this code below - i made some changes so i hope it ports back to what you're trying to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in any case, it's scaling and rotating when I tried it -- no problem whatsoever.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please excuse me if i'm incorrect - but perhaps also make sure if you've defined a "direction" property in the dynamic block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in short looks like the nesting of the if statements is causing the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[CommandMethod("resetinj", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]&lt;BR /&gt;public void resetinjek()&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Editor ed = doc.Editor;&lt;BR /&gt;string blkName = "&lt;SPAN&gt;resetinj&lt;/SPAN&gt;";&lt;BR /&gt;ObjectIdCollection blockSet = GetDynamicBlocksByName(blkName);&lt;BR /&gt;ObjectId[] blockSetArray =new ObjectId[blockSet.Count];&lt;BR /&gt;blockSet.CopyTo(blockSetArray, 0);&lt;BR /&gt;double xscale, yscale, brot;&lt;BR /&gt;Scale3d scale1 = new Scale3d(1, 1, 1);&lt;BR /&gt;&lt;BR /&gt;foreach (ObjectId blockId in blockSet)&lt;BR /&gt;{&lt;BR /&gt;Database db = blockId.Database;&lt;BR /&gt;using (Transaction trans = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;BlockReference blockRef = trans.GetObject(blockId, OpenMode.ForWrite) as BlockReference;&lt;BR /&gt;brot = blockRef.Rotation;&lt;BR /&gt;xscale = blockRef.ScaleFactors.X;&lt;BR /&gt;yscale = blockRef.ScaleFactors.Y;&lt;/P&gt;&lt;P&gt;if (brot != 0)&lt;BR /&gt;{&lt;BR /&gt;blockRef.Rotation = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (xscale != 1)&lt;BR /&gt;{&lt;BR /&gt;blockRef.ScaleFactors = scale1;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DynamicBlockReferencePropertyCollection properties = blockRef.DynamicBlockReferencePropertyCollection;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;foreach (DynamicBlockReferenceProperty property in properties)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;// have you created the direction property in the dynamic block???&lt;BR /&gt;if (property.PropertyName == "Direction")&lt;BR /&gt;{&lt;BR /&gt;if (xscale &amp;lt; 0)&lt;BR /&gt;{&lt;BR /&gt;brot += Math.PI; //adds 180 degrees to "Direction"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;property.Value = (double)property.Value + brot;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;trans.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;Autodesk.AutoCAD.Internal.Utils.SelectObjects(blockSetArray);&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 23:25:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6652007#M34257</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2016-10-27T23:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: mirroring dynamic blocks</title>
      <link>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6669747#M34258</link>
      <description>thanks for finding the error!</description>
      <pubDate>Sat, 05 Nov 2016 22:42:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mirroring-dynamic-blocks/m-p/6669747#M34258</guid>
      <dc:creator>Buzz0m</dc:creator>
      <dc:date>2016-11-05T22:42:03Z</dc:date>
    </item>
  </channel>
</rss>

