public static void ChangeObject(string id, int colorIndex, bool visible, string name, string objectClass,
double pointX1, double pointX2, double pointY1, double pointY2, double circleRadius, double pointZ)
{
doc = Application.DocumentManager.MdiActiveDocument;
db = doc.Database;
using (doc.LockDocument())
{
using (trans = db.TransactionManager.StartOpenCloseTransaction())
{
if (objectClass == "Слой")
{
var lt = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
if (lt != null)
{
foreach (var objId in lt)
{
var ltr = trans.GetObject(objId, OpenMode.ForWrite) as LayerTableRecord;
if (ltr.Id.ToString() == id)
{
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci,
short.Parse(colorIndex.ToString()));
ltr.Name = name;
ltr.IsOff = visible != true;
}
}
}
trans.Commit();
}
else
{
PromptSelectionResult getSel = doc.Editor.SelectAll();
if (getSel.Status == PromptStatus.OK)
{
SelectionSet selSet = getSel.Value;
foreach (SelectedObject selObj in selSet)
{
switch (objectClass)
{
case "Точка":
var point = trans.GetObject(selObj.ObjectId, OpenMode.ForWrite) as DBPoint;
if (point != null && point.Id.ToString() == id)
{
//Type entType = ent.GetType();
//switch (entType.Name)
point.Position = new Point3d(pointX1, pointY1, pointZ);
//line = new Line();
//circle = new Circle();
}
break;
case "Линия":
var line = trans.GetObject(selObj.ObjectId, OpenMode.ForWrite) as Line;
if (line != null && line.Id.ToString() == id)
{
line.StartPoint = new Point3d(pointX1, pointY1, pointZ);
line.EndPoint = new Point3d(pointX2, pointY2, pointZ);
}
break;
case "Окружность":
var circle = trans.GetObject(selObj.ObjectId, OpenMode.ForWrite) as Circle;
if (circle != null && circle.Id.ToString() == id)
{
circle.Center = new Point3d(pointX1, pointY1, pointZ);
circle.Radius = circleRadius;
}
break;
default:
MessageBox.Show("Выберите объект, для которого необходимо внести изменения");
return;
}
}
}
trans.Commit();
}
}
}
Refresh(doc);
}