<?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 Creating a block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3894122#M49807</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to .net for autocad, but very familiar with c#. I studied some samples about creating a block from c#, but need some help figuring it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Waht I'm trying to do:&lt;/P&gt;&lt;P&gt;I have a form for some basic input. When the user presses OK the code checks if the blockname is aleady in use. When no it creates the block using following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private void make_block()
        {
            double nextpoint = 0.0;
            double linedis = 7.3634;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = new BlockTableRecord();
                btr.Name = "hoeveelheden";

                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);

                btr.Origin = Point3d.Origin;
                btr.Units = UnitsValue.Meters;

                ObjectId btrId = bt.Add(btr);
                bt.DowngradeOpen();

                DBObjectCollection ents = new DBObjectCollection();

                //controleren op (de)markeren
                double tmp = conlengte + lengte0505 + lengte11 + lengte13 + lengte31 + lengte39 + lengte30270 + lengte93 + haailengte5050 + haailengte5070 + demconlengte +
                    demlengte0505 + demlengte11 + demlengte13 + demlengte31 + demlengte39 + demlengte30270 + demlengte93;
                if (tmp != 0.0 || pijlen != 0)
                {
                    //(de)markeren toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 100.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 90.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 90.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 92.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "markering";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

					//some more text entities are created

                    nextpoint = nextpoint + 100.0;
                }

                //controleren op barrier
                tmp = barrier + barrier_beton + barrier_Bever + barrier_HaiSafe + barrier_Haitsma_Step + barrier_kunststof +
                    barrier_Miniguard + barrier_Romein + barrier_RWS + barrier_Safe_guard + barrier_staal + barrier_Vario_guard;
                if (tmp != 0.0 || pstuk != 0 || rimobP110s != 0 || rimobV270 != 0 || antizichtscherm != 0.0)
                {
                    //(de)markeren toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 115.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 115.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 115.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 105.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 105.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 107.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "geleidebarrier";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

                    if (barrier_staal != 0.0)
                    {
                        p1 = new Point3d(52.0, nextpoint + (93.5 - 1 * linedis), 0.0);
                        acText = new DBText();
                        acText.SetDatabaseDefaults();
                        acText.Position = p1;
                        acText.Height = 3.5;
                        acText.TextString = Math.Round(barrier_staal, 0).ToString() + " m";
                        acText.Layer = "wx-zwart-002";
                        ents.Add(acText);
                    }

					//some more text entities are created

                    nextpoint = nextpoint + 115.0;
                }

                //controleren op geleidebakens / kegels
                if (baken != 0 || kegel != 0)
                {
                    //(geleidebakens/kegels toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 40.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 40.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 30.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 30.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 32.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "geleidebakens / kegels";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

					//some more text entities are created

                    nextpoint = nextpoint + 40.0;
                }

                //controleren op verlichting
                if (lichtmast != 0 || mobilight != 0)
                {
                    //(verlichting toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 40.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 40.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 30.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 30.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 32.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "tijdelijke verlichting";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

		    //some more text entities are created

                }

                foreach (Entity ent in ents)
                {
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);
                }

                tr.AddNewlyCreatedDBObject(btr, true);                

                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code runs succesfully (meaning i don't get any errors), but when I want to insert the block it isn't in the list of blocks. I must be forgetting something, but am unable to figure out what.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Apr 2013 10:58:52 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-04-26T10:58:52Z</dc:date>
    <item>
      <title>Creating a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3894122#M49807</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to .net for autocad, but very familiar with c#. I studied some samples about creating a block from c#, but need some help figuring it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Waht I'm trying to do:&lt;/P&gt;&lt;P&gt;I have a form for some basic input. When the user presses OK the code checks if the blockname is aleady in use. When no it creates the block using following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private void make_block()
        {
            double nextpoint = 0.0;
            double linedis = 7.3634;
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = new BlockTableRecord();
                btr.Name = "hoeveelheden";

                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);

                btr.Origin = Point3d.Origin;
                btr.Units = UnitsValue.Meters;

                ObjectId btrId = bt.Add(btr);
                bt.DowngradeOpen();

                DBObjectCollection ents = new DBObjectCollection();

                //controleren op (de)markeren
                double tmp = conlengte + lengte0505 + lengte11 + lengte13 + lengte31 + lengte39 + lengte30270 + lengte93 + haailengte5050 + haailengte5070 + demconlengte +
                    demlengte0505 + demlengte11 + demlengte13 + demlengte31 + demlengte39 + demlengte30270 + demlengte93;
                if (tmp != 0.0 || pijlen != 0)
                {
                    //(de)markeren toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 100.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 90.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 90.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 92.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "markering";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

					//some more text entities are created

                    nextpoint = nextpoint + 100.0;
                }

                //controleren op barrier
                tmp = barrier + barrier_beton + barrier_Bever + barrier_HaiSafe + barrier_Haitsma_Step + barrier_kunststof +
                    barrier_Miniguard + barrier_Romein + barrier_RWS + barrier_Safe_guard + barrier_staal + barrier_Vario_guard;
                if (tmp != 0.0 || pstuk != 0 || rimobP110s != 0 || rimobV270 != 0 || antizichtscherm != 0.0)
                {
                    //(de)markeren toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 115.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 115.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 115.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 105.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 105.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 107.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "geleidebarrier";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

                    if (barrier_staal != 0.0)
                    {
                        p1 = new Point3d(52.0, nextpoint + (93.5 - 1 * linedis), 0.0);
                        acText = new DBText();
                        acText.SetDatabaseDefaults();
                        acText.Position = p1;
                        acText.Height = 3.5;
                        acText.TextString = Math.Round(barrier_staal, 0).ToString() + " m";
                        acText.Layer = "wx-zwart-002";
                        ents.Add(acText);
                    }

					//some more text entities are created

                    nextpoint = nextpoint + 115.0;
                }

                //controleren op geleidebakens / kegels
                if (baken != 0 || kegel != 0)
                {
                    //(geleidebakens/kegels toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 40.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 40.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 30.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 30.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 32.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "geleidebakens / kegels";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

					//some more text entities are created

                    nextpoint = nextpoint + 40.0;
                }

                //controleren op verlichting
                if (lichtmast != 0 || mobilight != 0)
                {
                    //(verlichting toevoegen aan block
                    Point3d p1 = new Point3d(0.0, nextpoint, 0.0);
                    Point3d p2 = new Point3d(0.0, nextpoint + 100.0, 0.0);
                    Line ln = new Line(p1, p2);
                    ln.Layer = "wx-zwart-004";
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 40.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 40.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);
                    p1 = new Point3d(0.0, nextpoint + 30.0, 0.0);
                    p2 = new Point3d(150.0, nextpoint + 30.0, 0.0);
                    ln = new Line(p1, p2);
                    ents.Add(ln);

                    p1 = new Point3d(7.0, nextpoint + 32.5, 0.0);
                    DBText acText = new DBText();
                    acText.SetDatabaseDefaults();
                    acText.Position = p1;
                    acText.Height = 5.0;
                    acText.TextString = "tijdelijke verlichting";
                    acText.Layer = "wx-zwart-004";
                    ents.Add(acText);

		    //some more text entities are created

                }

                foreach (Entity ent in ents)
                {
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);
                }

                tr.AddNewlyCreatedDBObject(btr, true);                

                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code runs succesfully (meaning i don't get any errors), but when I want to insert the block it isn't in the list of blocks. I must be forgetting something, but am unable to figure out what.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2013 10:58:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3894122#M49807</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-26T10:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3894848#M49808</link>
      <description>&lt;P&gt;Only skimming your code, I see nothing suspicious.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are other transactions being started that you don't show in your code, make sure all of them are comitted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your code is being called in one or more try{} blocks, make sure the catch{} blocks are not hiding an error that might also cause a transaction to abort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2013 20:28:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3894848#M49808</guid>
      <dc:creator>DiningPhilosopher</dc:creator>
      <dc:date>2013-04-26T20:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a block</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3895449#M49809</link>
      <description>&lt;P&gt;I went trough my code again, indeed found a transaction which I didn't dispose. Now it works just perfect. Thanks for the tip!&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2013 19:49:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-a-block/m-p/3895449#M49809</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-04-27T19:49:21Z</dc:date>
    </item>
  </channel>
</rss>

