using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CustomDialogs
{
public partial class TypeViewerForm : Form
{
public TypeViewerForm()
{
InitializeComponent();
}
public void SetObjectText(string text)
{
typeTextBox.Text = text;
}
public void SetObjectIds(ObjectIdCollection ids)
{
if (ids.Count < 0)
{
SetObjectText("");
}
else
{
Document doc =
Autodesk.AutoCAD.ApplicationServices.
Application.DocumentManager.MdiActiveDocument;
DocumentLock loc =
doc.LockDocument();
using (loc)
{
string info =
"Number of objects: " +
ids.Count.ToString() + "\r\n";
Transaction tr =
doc.TransactionManager.StartTransaction();
using (tr)
{
foreach (ObjectId id in ids)
{
Entity ent =
(Entity)tr.GetObject(id, OpenMode.ForRead);
Solid3d sol = ent as Solid3d;
if (sol != null)
{
Acad3DSolid oSol =
(Acad3DSolid)sol.AcadObject;
// Put in a try-catch block, as it's possible
// for solids to not support this property,
// it seems (better safe than sorry)
try
{
string solidType = oSol.SolidType;
info +=
ent.GetType().ToString() +
" (" + solidType + ") : " +
ent.ColorIndex.ToString() + "\r\n";
}
catch (System.Exception)
{
info +=
ent.GetType().ToString() +
" : " +
ent.ColorIndex.ToString() + "\r\n";
}
}
else
{
info +=
ent.GetType().ToString() +
" : " +
ent.ColorIndex.ToString() + "\r\n";
}
}
tr.Commit();
}
SetObjectText(info);
}
}
}
public void SetObjectId(ObjectId id)
{
if (id == ObjectId.Null)
{
SetObjectText("");
}
else
{
Document doc =
Autodesk.AutoCAD.ApplicationServices.
Application.DocumentManager.MdiActiveDocument;
DocumentLock loc =
doc.LockDocument();
using (loc)
{
Transaction tr =
doc.TransactionManager.StartTransaction();
using (tr)
{
DBObject obj =
tr.GetObject(id, OpenMode.ForRead);
SetObjectText(obj.GetType().ToString());
tr.Commit();
}
}
}
}
private void closeButton_Click(object sender, EventArgs e)
{
this.Hide();
}
}
}