76 lines
2.8 KiB
C#
76 lines
2.8 KiB
C#
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())
|
|
{
|
|
try
|
|
{
|
|
if (obj is Solid solid)
|
|
{
|
|
var directShape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
|
|
directShape.SetShape(new GeometryObject[] { solid });
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
}
|
|
}
|
|
try
|
|
{
|
|
if (geoObj is Solid solid)
|
|
{
|
|
var directShape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
|
|
directShape.SetShape(new GeometryObject[] { solid });
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
Document.Delete(element.Id);
|
|
});
|
|
}
|
|
}
|
|
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TaskDialog.Show("Error", ex.Message);
|
|
}
|
|
}
|
|
} |