<?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 Re: Insert Dymanic Block from file and changeVisibility States in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3268965#M57946</link>
    <description>&lt;P&gt;You have to change order of your work with block&lt;/P&gt;&lt;P&gt;See if this working for you :&lt;/P&gt;&lt;PRE&gt;            using (btr)
                     {

                         BlockReference bref = new BlockReference(InsertionPoint, blkid);
                
                             Matrix3d mat = Matrix3d.Identity;

                             bref.TransformBy(mat);

                             bref.Layer = "0";

                             bref.Rotation = Rotation;

                             btr.AppendEntity(bref);
       
                             tr.AddNewlyCreatedDBObject(bref, true);

                             if (bref.IsDynamicBlock)
                             {
                                 
                                 DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;

                                 foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
                                 {
                                     if (dynBrefProps.PropertyName.ToUpper() == "VISIBILITY1")
                                     {

                                         dynBrefProps.Value = "M36";
                                     }
                                 }
                             }
 
                     }
                     tr.Commit();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2011 08:51:54 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2011-12-20T08:51:54Z</dc:date>
    <item>
      <title>Insert Dymanic Block from file and changeVisibility States</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3268808#M57945</link>
      <description>&lt;P&gt;I am trying to insert a Dynamic Block and change it's Visibility State. I can insert the block, and the visibility state changes, however, if I manually try to change it after, it does not change, even though the value has changed. My code executes and returns no errors, so I am assuming that I have done something wrong, or missed something out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; public class MyCommands
        {
        [CommandMethod("MyGroup", "Bolts", "MyCommandLocal", CommandFlags.Modal)]
        public void MyCommand() // This method can have any name
            {
            InsertBlock(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database, "C:/88NutPlan.dwg", new Point3d(0, 0, 0));
            }

        public static void InsertBlock(Database db, string FileName, Point3d InsertionPoint, double Rotation = 0)
            {
            ObjectId blkid = ObjectId.Null;
            using (Database bdb = new Database(false, true))
                {
                bdb.ReadDwgFile(FileName, System.IO.FileShare.Read, true, "");
                blkid = db.Insert(System.IO.Path.GetFileNameWithoutExtension(FileName), bdb, true);

                using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                    BlockTableRecord btr = default(BlockTableRecord);
                    btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);


                    using (btr)
                        {
                        BlockReference bref = new BlockReference(InsertionPoint, blkid);
                        using (bref)
                            {

                            
                            if (bref.IsDynamicBlock)
                                {
                                DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;
                                foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
                                    {
                                    if (dynBrefProps.PropertyName == "Visibility1")
                                        {
                                        dynBrefProps.Value = "M36";
                                        }
                                    }
                                }


                            Matrix3d mat = Matrix3d.Identity;
                            bref.TransformBy(mat);
                            bref.Layer = "0";
                            bref.Rotation = Rotation;
                            btr.AppendEntity(bref);
                            tr.AddNewlyCreatedDBObject(bref, true);
                            }
                        }
                    tr.Commit();
                    }
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I insert my block manually, I can change the states and it works fine, but the code seems to break the block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone shed some light on this?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2011 02:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3268808#M57945</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2011-12-20T02:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Dymanic Block from file and changeVisibility States</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3268965#M57946</link>
      <description>&lt;P&gt;You have to change order of your work with block&lt;/P&gt;&lt;P&gt;See if this working for you :&lt;/P&gt;&lt;PRE&gt;            using (btr)
                     {

                         BlockReference bref = new BlockReference(InsertionPoint, blkid);
                
                             Matrix3d mat = Matrix3d.Identity;

                             bref.TransformBy(mat);

                             bref.Layer = "0";

                             bref.Rotation = Rotation;

                             btr.AppendEntity(bref);
       
                             tr.AddNewlyCreatedDBObject(bref, true);

                             if (bref.IsDynamicBlock)
                             {
                                 
                                 DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;

                                 foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
                                 {
                                     if (dynBrefProps.PropertyName.ToUpper() == "VISIBILITY1")
                                     {

                                         dynBrefProps.Value = "M36";
                                     }
                                 }
                             }
 
                     }
                     tr.Commit();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2011 08:51:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3268965#M57946</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-12-20T08:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Dymanic Block from file and changeVisibility States</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3270321#M57947</link>
      <description>&lt;P&gt;Thanks Hallex - That worked perfeclty!!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2011 00:00:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3270321#M57947</guid>
      <dc:creator>BrentBurgess1980</dc:creator>
      <dc:date>2011-12-21T00:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Dymanic Block from file and changeVisibility States</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3270483#M57948</link>
      <description>&lt;P&gt;You're welcome&lt;/P&gt;&lt;P&gt;Cheers &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;~'J'~&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2011 06:46:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-dymanic-block-from-file-and-changevisibility-states/m-p/3270483#M57948</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-12-21T06:46:26Z</dc:date>
    </item>
  </channel>
</rss>

