更新
This commit is contained in:
@@ -4,36 +4,27 @@ using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.Revit.Assists;
|
||||
|
||||
namespace ShrlAlgo.Addin.Test;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class CADCurveToModelCurveCmd : IExternalCommand
|
||||
public class CADCurveToModelCurveCmd : ExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
public override void Execute()
|
||||
{
|
||||
//程序UI界面
|
||||
UIApplication uiapp = commandData.Application;
|
||||
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
|
||||
UIDocument uidoc = uiapp.ActiveUIDocument;
|
||||
//程序
|
||||
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
|
||||
//获取位置和场地 视图(多个视图)管理 获取元素(Revit 项目里的全部元素)
|
||||
Document doc = uidoc.Document;
|
||||
//获取所有打开文档
|
||||
DocumentSet docset = uiapp.Application.Documents;
|
||||
//当前视图
|
||||
View view = doc.ActiveView;
|
||||
|
||||
|
||||
#region SelectExecute
|
||||
|
||||
using (Transaction trans = new Transaction(doc, "default"))
|
||||
using (Transaction trans = new Transaction(Document, "default"))
|
||||
{
|
||||
try
|
||||
{
|
||||
Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "请选择CAD");
|
||||
Element e = uidoc.Document.GetElement(refer);
|
||||
Reference refer = UiDocument.Selection.PickObject(ObjectType.Element, "请选择CAD");
|
||||
Element e = UiDocument.Document.GetElement(refer);
|
||||
if (e is ImportInstance ins)
|
||||
{
|
||||
trans.Start();
|
||||
@@ -54,10 +45,10 @@ public class CADCurveToModelCurveCmd : IExternalCommand
|
||||
ReferencePointArray array = new ReferencePointArray();
|
||||
foreach (var p in points)
|
||||
{
|
||||
var rp = doc.FamilyCreate.NewReferencePoint(p);
|
||||
var rp = Document.FamilyCreate.NewReferencePoint(p);
|
||||
array.Append(rp);
|
||||
}
|
||||
var curveBypoints = doc.FamilyCreate.NewCurveByPoints(array);
|
||||
var curveBypoints = Document.FamilyCreate.NewCurveByPoints(array);
|
||||
}
|
||||
}
|
||||
if (c is PolyLine poly)
|
||||
@@ -85,22 +76,17 @@ public class CADCurveToModelCurveCmd : IExternalCommand
|
||||
{
|
||||
trans.Commit();
|
||||
}
|
||||
|
||||
return Result.Succeeded;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = ex.Message;
|
||||
ErrorMessage = ex.Message;
|
||||
if (trans.GetStatus() == TransactionStatus.Started)
|
||||
{
|
||||
trans.RollBack();
|
||||
}
|
||||
return Result.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion SelectExecute
|
||||
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user