Thanks guys, so here it is, my code is something like:
public string roomName = "";
public void setCurrentRoomName(string CurrentName)
{
roomName = CurrrentName;
}
[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 < (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 < bd.Handseed.Value; i++)
{
ObjectId id = ObjectId.Null;
bd.TryGetObjectId(new Handle(i), out id);
if (id != ObjectId.Null && !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 < 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();
}
}
}
And the code of the form8 is:
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();
}
The exception message apears after the form8 desapears.
