[CommandMethod("SectionElevation")]
public void svminmax()
{
try
{
SVMinMaxcommand();
}
catch
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("****Uh oh! This command is unable to be used in C3D 2013 or older!****");
}
finally
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nThis Utility brought to you by: Quux Software, creators of the Sincpac-C3D.");
}
}
private void SVMinMaxcommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
double min = Double.MinValue, max = Double.MaxValue;
PromptSelectionOptions ssOpts = new PromptSelectionOptions();
ssOpts.MessageForAdding = "Select SectionViews to adjust Min/Max values:";
ssOpts.MessageForRemoval = "...Select SectionViews to remove from selection:";
ssOpts.RejectObjectsOnLockedLayers = true;
TypedValue[] tv = { new TypedValue(0, "AECC_GRAPH_SECTION_VIEW") };
SelectionFilter filter = new SelectionFilter(tv);
PromptSelectionResult ssRes = ed.GetSelection(ssOpts, filter);
if (ssRes.Status != PromptStatus.OK)
return;
PromptDoubleOptions dOpts = new PromptDoubleOptions("\nEnter new Minimum elevation for sectionviews:");
dOpts.AllowArbitraryInput = false;
PromptDoubleResult dRes = ed.GetDouble(dOpts);
if (dRes.Status != PromptStatus.OK)
return;
min = dRes.Value;
dOpts.Message = "\nEnter new Maximum elevation for sectionviews:";
dOpts.DefaultValue = min + 1;
dOpts.UseDefaultValue = true;
dRes = ed.GetDouble(dOpts);
if (dRes.Status != PromptStatus.OK)
return;
max = dRes.Value;
while (max < min)
{
dOpts.Message = "...Max must be higher than Min, try again:";
dRes = ed.GetDouble(dOpts);
if (dRes.Status != PromptStatus.OK)
return;
max = dRes.Value;
}
using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
foreach (ObjectId id in ssRes.Value.GetObjectIds())
{
SectionView sv = (SectionView)id.GetObject(OpenMode.ForWrite);
if (sv.IsElevationRangeAutomatic)
sv.IsElevationRangeAutomatic = false;
sv.ElevationMax = max;
sv.ElevationMin = min;
}
tr.Commit();
}
}
0 Nhận xét