调整代码
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.RvCommon;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Modeling;
|
||||
[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链接的圆弧获取图层创建");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "创建实例");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user