功能更新

This commit is contained in:
GG Z
2026-02-12 21:29:00 +08:00
parent a9faf251be
commit b3479d1f39
342 changed files with 4671 additions and 2223 deletions

View File

@@ -32,37 +32,64 @@ public class ExplodeDwgCmd : IExternalCommand
var element = Document.GetElement(refer);
var geoElem = element.get_Geometry(new Options() { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine });
var f = Document.OwnerFamily;
Document.Invoke(
_ =>
Document.InvokeGroup(
tg =>
{
foreach (var geoObj in geoElem)
{
if (geoObj is GeometryInstance instance)
Document.Invoke(
_ =>
{
foreach (var obj in instance.GetInstanceGeometry())
foreach (var geoObj in geoElem)
{
if (geoObj is GeometryInstance instance)
{
foreach (var obj in instance.GetInstanceGeometry())
{
try
{
if (obj is Solid solid && solid.Faces.Size > 0 && solid.Volume > 10e-6)
{
FreeFormElement.Create(Document, solid);//和分解的功能一样,仅保留几何信息
//try
//{
// // 如果是项目文档只能使用DirectShape创建适用于导入的几何体不能进行二次编辑
// // 如果是族文档使用FreeFormElement创建可以有更多的几何体支持支持编辑手柄族文档也支持DirectShape
// var shape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
// shape.SetShape([solid]);
//}
//catch (Exception)
//{
// FreeFormElement.Create(Document, solid);//和分解的功能一样,仅保留几何信息
//}
}
}
catch (Exception ex)
{
sb.AppendLine(ex.Message);
continue;
}
}
}
try
{
if (obj is Solid solid && solid.Faces.Size > 0 && solid.Volume > 10e-6)
if (geoObj is Solid topSolid && topSolid.Faces.Size > 0 && topSolid.Volume > 10e-6)
{
FreeFormElement.Create(Document, solid);//和分解的功能一样,仅保留几何信息
FreeFormElement.Create(Document, topSolid);//和分解的功能一样,仅保留几何信息
//try
//{
// // 如果是项目文档只能使用DirectShape创建适用于导入的几何体不能进行二次编辑
// // 如果是族文档使用FreeFormElement创建可以有更多的几何体支持支持编辑手柄族文档也支持DirectShape
// var shape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
// shape.SetShape([solid]);
// var directShape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
// directShape.SetShape([topSolid]);
//}
//catch (Exception)
//{
// FreeFormElement.Create(Document, solid);//和分解的功能一样,仅保留几何信息
// FreeFormElement.Create(Document, topSolid);
//}
}
}
catch (Exception ex)
@@ -71,36 +98,29 @@ public class ExplodeDwgCmd : IExternalCommand
continue;
}
}
}
try
{
if (geoObj is Solid topSolid && topSolid.Faces.Size > 0 && topSolid.Volume > 10e-6)
Document.Delete(element.Id);
});
MessageBox.Show("几何体炸开完成,请等待材质赋值完成", "提示");
Document.Invoke(
_ =>
{
FreeFormElement.Create(Document, topSolid);//和分解的功能一样,仅保留几何信息
//try
//{
// var directShape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
// directShape.SetShape([topSolid]);
//}
//catch (Exception)
//{
// FreeFormElement.Create(Document, topSolid);
//}
}
}
catch (Exception ex)
{
sb.AppendLine(ex.Message);
continue;
}
}
Document.Delete(element.Id);
});
var freeFormElements = Document.OfClass<FreeFormElement>().Cast<FreeFormElement>().ToList();
foreach (var form in freeFormElements)
{
var geoElement = form.get_Geometry(new Options() { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine });
foreach (var obj in geoElement)
{
if (obj is Solid solid && solid.Faces.Size > 0 && solid.Volume > 10e-6)
{
Face face = solid.Faces.get_Item(0);
Material material = Document.GetElement(face.MaterialElementId) as Material;
if (material != null)
form.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM).Set(material.Id);
}
}
}
});
},"炸开dwg");
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)