[CommandMethod("8test")]
public static void CreateTableStart()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
ObjectId contourNumberId = SelectObjectsOnScreen()[0];
var contourNumber = GetStringParameter2("SetStrPar", contourNumberId);
tr.Commit();
}
}
public static string GetStringParameter2(string message, ObjectId objectId)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
PromptStringOptions pso = new PromptStringOptions(message);
string contourNumber = "NotSet";
using (tr)
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
MLeader ml = tr.GetObject(objectId, OpenMode.ForRead) as MLeader;
BlockTableRecord content = tr.GetObject(ml.BlockContentId, OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId blkEntId in content)
{
AttributeDefinition AttributeDef = tr.GetObject(blkEntId, OpenMode.ForRead) as AttributeDefinition;
if (AttributeDef != null)
{
AttributeReference att = new AttributeReference();
if (att.Tag == "ContourNumber")
{
contourNumber = att.TextString;
break;
}
}
}
tr.Commit();
}
return contourNumber;
}
public static List<ObjectId> SelectObjectsOnScreen()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
List<ObjectId> listOfEntities = new List<ObjectId>();
using (tr)
{
// Request for objects to be selected in the drawing area
PromptSelectionResult PrSeRes = doc.Editor.GetSelection();
// If the prompt status is OK, objects were selected
if (PrSeRes.Status == PromptStatus.OK)
{
SelectionSet SelSet = PrSeRes.Value;
// Step through the objects in the selection set
foreach (SelectedObject SelObj in SelSet)
{
// Check to make sure a valid SelectedObject object was returned
if (SelObj != null)
{
listOfEntities.Add(SelObj.ObjectId);
}
}
}
tr.Commit();
}
return listOfEntities;
}