Files
Shrlalgo.RvKits/ShrlAlgoToolkit.RevitAddins/RvCommon/PlaceInstanceByCircleCmd.cs

57 lines
3.2 KiB
C#
Raw Normal View History

2026-02-20 16:47:26 +08:00
using Autodesk.Revit.Attributes;
2025-07-11 09:20:23 +08:00
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Nice3point.Revit.Toolkit.External;
namespace ShrlAlgoToolkit.RevitAddins.RvCommon;
[Transaction(TransactionMode.Manual)]
public class PlaceInstanceByCircleCmd : ExternalCommand
{
public override void Execute()
{
Document.Invoke(
_ =>
{
var refer = UiDocument.Selection.PickObject(ObjectType.Element, "请选择一个实例");
var familyInstance = Document.GetElement(refer) as FamilyInstance;
var dwgRefer = UiDocument.Selection.PickObject(ObjectType.PointOnElement, new FuncFilter(e => e.Document.GetElement(e.GetTypeId()) is CADLinkType, (r, _) => r.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_LINEAR), "请拾取dwg链接的圆弧获取图层创建");
2025-07-11 09:20:23 +08:00
Element elem = Document.GetElement(dwgRefer);
GeometryElement geoElem = elem.get_Geometry(new Options());
GeometryObject geoObj = elem.GetGeometryObjectFromReference(dwgRefer);
//var arcs = new List<Arc>();
foreach (var geo in geoElem)
{
if (geo is GeometryInstance instance)
{
//实例集合为准确位置,只需要竖向移动
foreach (var geom in instance.GetInstanceGeometry())
{
if (geom is Arc arc && arc.IsCyclic && geom.GraphicsStyleId == geoObj.GraphicsStyleId)
{
var transform = Transform.CreateTranslation(new XYZ(0, 0, Document.ActiveView.GenLevel.Elevation - arc.Center.Z));
arc = arc.CreateTransformed(transform) as Arc;
if (!familyInstance.Symbol.IsActive)
{
familyInstance.Symbol.Activate();
}
Document.Create.NewFamilyInstance(arc.Center, familyInstance.Symbol, Document.ActiveView.GenLevel, Document.ActiveView.GenLevel, familyInstance.StructuralType);
//dwg类型几何的Transform可能会影响到实例的放置位置所以需要进行转换如果是块的话需要使用类型几何
//Transform tf = instance.Transform;
//foreach (var item in instance.GetSymbolGeometry())
//{
// //var graphicsStyle = Document.GetElement(item.GraphicsStyleId) as GraphicsStyle;
// //item.GraphicsStyleId.IntegerValue ==
// var point = tf.OfPoint(arc.Center);
// Document.Create.NewFamilyInstance(point, familyInstance.Symbol, Document.ActiveView.GenLevel, Document.ActiveView.GenLevel, familyInstance.StructuralType);
//}
//arcs.Add(arc);
}
}
}
}
}, "创建实例");
}
}