<?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: Problem creating layer in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919123#M37933</link>
    <description>&lt;P&gt;I finally found the solution for my problem guys, thanks for you all that tried helping me. really, thank you very much.&lt;/P&gt;</description>
    <pubDate>Sat, 21 Nov 2015 17:09:02 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-11-21T17:09:02Z</dc:date>
    <item>
      <title>Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5908952#M37926</link>
      <description>&lt;P&gt;Hello guys I&amp;nbsp;really need some help, I'm trying to create a new layer seting its name through&amp;nbsp;a windows form, but my code always break, for example, this code works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; LayerTable lT = tr.GetObject(bd.LayerTableId, OpenMode.ForRead) as LayerTable;
                    string sLayerName = "StringTest";

                    if (lT.Has(sLayerName) == false) 
                    {
                        LayerTableRecord lTR = new LayerTableRecord();
                        lTR.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 10);
                        lTR.Name = sLayerName;
                        
                        lT.UpgradeOpen();

                        lT.Add(lTR);
                        tr.AddNewlyCreatedDBObject(lTR, true);

                    }&lt;/PRE&gt;&lt;P&gt;but when I do some thing like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; &lt;BR /&gt;string name = textBox.Text;&lt;BR /&gt;&lt;BR /&gt;LayerTable lT = tr.GetObject(bd.LayerTableId, OpenMode.ForRead) as LayerTable;
                    string sLayerName = name;

                    if (lT.Has(sLayerName) == false) // Verify if this layer is already created
                    {
                        LayerTableRecord lTR = new LayerTableRecord();
                        lTR.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 10);
                        lTR.Name = sLayerName;
                        
                        lT.UpgradeOpen();

                        lT.Add(lTR);
                        tr.AddNewlyCreatedDBObject(lTR, true);

                    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Making the user set the name for the future layer, my code breaks, help me guys I have no idea how to solve this.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2015 20:15:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5908952#M37926</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-11-15T20:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909005#M37927</link>
      <description>And to be a little bit more expecific I'm getting an exception when I'm trying work with that name variable.</description>
      <pubDate>Sun, 15 Nov 2015 22:03:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909005#M37927</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-11-15T22:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909079#M37928</link>
      <description>&lt;P&gt;You'll need to be more explicit about the location and message of the exception.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the layer code works stand alone why do you think it is the cause of the error ??&lt;/P&gt;
&lt;P&gt;Isn't it more likely that the Form or the assignment to&amp;nbsp;the name variable is the issue ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you calling the Form ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is&amp;nbsp;&lt;SPAN&gt;the command method that instantiates the form is static or not ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What is the value of name if you add a WriteLine (or an Alert) in place of the layer making code call ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 00:26:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909079#M37928</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2015-11-16T00:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909099#M37929</link>
      <description>&lt;P&gt;please highlight the exact line that the code is breaking and what the exception is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't see a reason why it should fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps check what the name string is set to, by adding a break point and checking the watch window to see what the name variable is actually equal to.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 01:02:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909099#M37929</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2015-11-16T01:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909426#M37930</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks guys, so here it is, my code is something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;public string roomName = "";&lt;BR /&gt;&lt;BR /&gt;public void setCurrentRoomName(string CurrentName)&lt;BR /&gt; { &lt;BR /&gt; roomName = CurrrentName;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[CommandMethod("Walls")]
        public void setWalls()
        {
             if (roomName == "")
             {                 
                 Form8 formName = new Form8(this);
                 formAmbientName.Show();
             }       
             else
            {               
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;
                Database bd = doc.Database;
                Transaction tr = bd.TransactionManager.StartTransaction();
                ObjectIdCollection ids = new ObjectIdCollection();
                
                using (tr)
                {
                    BlockTable bT;
                    bT = tr.GetObject(bd.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btR;
                    btR = tr.GetObject(bT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                   

                    LayerTable lT = tr.GetObject(bd.LayerTableId, OpenMode.ForRead) as LayerTable;
                    string sLayerName = roomName;
                    
                    if (lT.Has(sLayerName) == false)
                    {
                        LayerTableRecord lTR = new LayerTableRecord();
                        lTR.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 10);
                        lTR.Name = sLayerName;                        
                        lT.UpgradeOpen();
                        lT.Add(lTR);
                        tr.AddNewlyCreatedDBObject(lTR, true);
                    }                   
                                 
                    PromptPointResult ppR;
                    PromptPointOptions ppO = new PromptPointOptions("");
                    Point2dCollection p2dC = new Point2dCollection();

                    ppO.Message = "Specify the first point of the wall: ";

                    ppR = doc.Editor.GetPoint(ppO);
                    p2dC.Add(new Point2d(ppR.Value.X, ppR.Value.Y));
                    Point2d pontoInicial = new Point2d(ppR.Value.X, ppR.Value.Y);

                    if (ppR.Status == PromptStatus.Cancel) return;
                    int auxStartWhile = 1;

                    while (pontoInicial != new Point2d(ppR.Value.X + auxStartWhile, ppR.Value.Y))
                    {
                        ppO.Message = "Specify next point of the wall: ";
                        ppO.UseBasePoint = true;
                        ppO.BasePoint = ppR.Value;
                        ppR = doc.Editor.GetPoint(ppO);
                        p2dC.Add(new Point2d(ppR.Value.X, ppR.Value.Y));
                       
                        auxStartWhile = 0;
                    }
                    using (SpecialBuildingWall pL = new SpecialBuildingWall())
                    {
                        for (int i = 0; i &amp;lt; (p2dC.Count); i++) // that -1 exclude the point (0,0) that is created when click esc 
                        {
                            pL.AddVertexAt(i, p2dC[i], 0, 0, 0);  // add points to the polyline
                        }
                        pL.Layer = sLayerName;
                        btR.AppendEntity(pL);
                        tr.AddNewlyCreatedDBObject(pL, true);

                        SpecialBuildingWall novoElementoEspecial = new SpecialBuildingWall(wallHeightParam, pL.Length, pL.Handle.ToString());
                        listadeRooms.Add(novoElementoEspecial);
                        listadeRoomsAtualizada.Clear();

                        for (long i = 0; i &amp;lt; bd.Handseed.Value; i++)
                        {
                            ObjectId id = ObjectId.Null;
                            bd.TryGetObjectId(new Handle(i), out id);
                            if (id != ObjectId.Null &amp;amp;&amp;amp; !id.IsErased)
                                ids.Add(id);
                        }
                        foreach (ObjectId id in ids)
                        {
                            DBObject obj = tr.GetObject(id, OpenMode.ForRead, false) as DBObject;
                            if (obj.GetRXClass().DxfName == "LWPOLYLINE")
                            {
                                object valueOfHandle_ = null;
                                valueOfHandle_ = obj.GetType().GetProperty("Handle").GetValue(obj, null);

                                for (int i = 0; i &amp;lt; listadelinhasespeciais.Count; i++)
                                {
                                    ed.WriteMessage(valueOfHandle_.ToString());
                                    if (listadeRooms[i].handle_.ToString() == valueOfHandle_.ToString())
                                    {
                                        auxiliarIndex = i;
                                        listadeRoomsAtualizada.Add(listadeRooms[i]);
                                        //listadelinhasespeciaisAtualizada.Add(listadelinhasespeciais[i]);                                        
                                    }
                                }
                            }
                        }                                             
                        Form9 roomComponentsForm = new Form9(roomName, this, novoAmbiente);
                        roomComponentsForm.Show();                        
                    }
                    tr.Commit();
                }
            } 
        } &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the code of the form8 is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; private void button1_Click(object sender, EventArgs e)
        {            
                instanciaDoMyCommands.setCurrentRoomName(textBox.Text);               
               Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute("Walls ", true, false, true);
                this.Close();          
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The exception message apears after the form8 desapears.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/200882i9F7707B5A4910C87/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Error Message" title="Error Message" /&gt;&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;</description>
      <pubDate>Mon, 16 Nov 2015 09:40:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909426#M37930</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-11-16T09:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909447#M37931</link>
      <description>Did you Lock the document before altering the Document/Database</description>
      <pubDate>Mon, 16 Nov 2015 09:50:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909447#M37931</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2015-11-16T09:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909518#M37932</link>
      <description>&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3076277" target="_blank"&gt;pericles-terto&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about you help others to help you.&lt;/P&gt;
&lt;P&gt;Could you attach a zipped solution containing the bare minimun required to demonstrate your issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is the only way someone can test your code without guessing about the stuff you don't show.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 11:04:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5909518#M37932</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2015-11-16T11:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919123#M37933</link>
      <description>&lt;P&gt;I finally found the solution for my problem guys, thanks for you all that tried helping me. really, thank you very much.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 17:09:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919123#M37933</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-11-21T17:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919242#M37934</link>
      <description>How about posting what you found to be the solution so others may benefit in the future?</description>
      <pubDate>Sat, 21 Nov 2015 21:00:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919242#M37934</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2015-11-21T21:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919735#M37935</link>
      <description>&lt;P&gt;I'm sorry, I wasn't at my computer to send u my solution before, well, my program was verifying the already created layer names two times&lt;/P&gt;&lt;PRE&gt;if (lT.Has(sLayerName) == false)&lt;/PRE&gt;&lt;P&gt;one into the same commandmethod as standard, and other into another external method called from the form that the user types the new layer name, I removed the verification of the other method and then the program worked fine.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2015 18:33:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-creating-layer/m-p/5919735#M37935</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-11-22T18:33:08Z</dc:date>
    </item>
  </channel>
</rss>

