namespace Example_Pipe_Project
{
public class Class1
{
[CommandMethod("PipeLengthenExample", CommandFlags.UsePickSet | CommandFlags.Modal)]
public static void PipeLengthenExample()
{
Pipe pipe = null;
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
var promptSelectOptions
= new PromptSelectionOptions
(); promptSelectOptions.MessageForAdding = "Select a Pipe Object:";
promptSelectOptions.SingleOnly = true;
PromptSelectionResult promptSelectionResult
= editor
.SelectByClass(promptSelectOptions,
typeof(Pipe
)); if (promptSelectionResult.Status == PromptStatus.OK && promptSelectionResult.Value.Count == 1)
{
try
{
using (Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
pipe = (Pipe)transaction.GetObject(promptSelectionResult.Value.GetObjectIds()[0], OpenMode.ForRead, false);
}
AddToLength(pipe);
pipe.Dispose();
}
catch (System.Exception exception)
{
editor.WriteMessage(exception.Message);
}
}
else
{
editor.WriteMessage("\n\nIncorrect type or number of objects selected.");
}
}
private static void AddToLength(Pipe pipe)
{
using (Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
try
{
transaction.GetObject(pipe.ObjectId, OpenMode.ForWrite, false);
pipe.Length = pipe.Length + 10;
transaction.Commit();
}
catch (System.Exception exception)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(exception.Message);
}
}
}
}
}