71 lines
2.8 KiB
C#
71 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Architecture;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.UI.Selection;
|
|
|
|
using GeologyToolkit;
|
|
|
|
namespace GeologyToolkit
|
|
{
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
internal class AddPointCmd : IExternalCommand
|
|
{
|
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|
{
|
|
var uiapp = commandData.Application;
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|
var app = uiapp.Application;
|
|
var doc = uidoc.Document;
|
|
var docset = uiapp.Application.Documents;
|
|
var isContinue = true;
|
|
try
|
|
{
|
|
var refer = uidoc.Selection.PickObject(ObjectType.Element, new SelectTopographySurface(), "请选择要调整地层面");
|
|
var surface = doc.GetElement(refer) as TopographySurface;
|
|
while (isContinue)
|
|
{
|
|
var refer1 = uidoc.Selection.PickObject(ObjectType.Element, new SelectLayer(), "请选择要添加到的钻孔土层");
|
|
var familyinstance = doc.GetElement(refer1) as FamilyInstance;
|
|
var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyinstance);
|
|
var referpoint = doc.GetElement(placePointIds[1]) as ReferencePoint;
|
|
|
|
var scope = new TopographyEditScope(doc, "添加地层点");
|
|
if (scope.IsPermitted)
|
|
{
|
|
scope.Start(surface.Id);
|
|
}
|
|
else
|
|
{
|
|
return Result.Failed;
|
|
}
|
|
|
|
GeologyFailureProcessor processor = null;
|
|
using (var ts = new Transaction(doc, "添加地层点"))
|
|
{
|
|
ts.Start();
|
|
if (scope.IsActive)
|
|
{
|
|
var points = new List<XYZ>
|
|
{
|
|
referpoint.Position
|
|
};
|
|
surface.AddPoints(points);
|
|
processor = new GeologyFailureProcessor();
|
|
}
|
|
ts.Commit();
|
|
}
|
|
scope.Commit(processor);
|
|
}
|
|
}
|
|
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
|
{
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
}
|
|
} |