调整代码
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.RvCommon;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.General;
|
||||
|
||||
/// <summary>
|
||||
/// 分割族中的整体dwg模型为单个Solid
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class SplitImportInstanceCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var refer = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new GenericFilter<ImportInstance>(), "请选择导入的实体");
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
var elem = Document.GetElement(refer) as DirectShape;
|
||||
var geometryElement = elem.get_Geometry(new Options() { ComputeReferences = true });
|
||||
foreach(var item in geometryElement)
|
||||
{
|
||||
if(item is Solid solid)
|
||||
{
|
||||
//MessageBox.Show("获取到Solid");
|
||||
var element = DirectShape.CreateElement(
|
||||
Document,
|
||||
Category.GetCategory(Document, BuiltInCategory.OST_GenericModel).Id);
|
||||
element.AppendShape([solid]);
|
||||
//return;
|
||||
}
|
||||
}
|
||||
Document.Delete(refer.ElementId);
|
||||
},
|
||||
"拆分实体");
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user