更新
This commit is contained in:
56
ShrlAlgoToolkit.RevitAddins/RvFamily/ExplodeDwgCmd.cs
Normal file
56
ShrlAlgoToolkit.RevitAddins/RvFamily/ExplodeDwgCmd.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.RvFamily;
|
||||
/// <summary>
|
||||
/// 炸开族中的dwg或嵌套族图元
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class ExplodeDwgCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
var refer = UiDocument.Selection.PickObject(ObjectType.Element);
|
||||
var element = Document.GetElement(refer);
|
||||
var geoElem = element.get_Geometry(new Options() { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine });
|
||||
if (Document.IsFamilyDocument)
|
||||
{
|
||||
var f = Document.OwnerFamily;
|
||||
Document.Invoke(
|
||||
ts =>
|
||||
{
|
||||
foreach (var geoObj in geoElem)
|
||||
{
|
||||
if (geoObj is GeometryInstance instance)
|
||||
{
|
||||
foreach (var obj in instance.GetInstanceGeometry())
|
||||
{
|
||||
if (obj is Solid solid)
|
||||
{
|
||||
var directShape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
|
||||
directShape.SetShape(new GeometryObject[] { solid });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Document.Delete(element.Id);
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskDialog.Show("Error", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user