更新
This commit is contained in:
65
ShrlAlgo.Addin.Test/PlaceInstanceByCircleCmd.cs
Normal file
65
ShrlAlgo.Addin.Test/PlaceInstanceByCircleCmd.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.Revit.Assists;
|
||||
using ShrlAlgoToolkit.Revit.Extensions;
|
||||
|
||||
namespace ShrlAlgo.Addin.Test;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class PlaceInstanceByCircleCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
//var id = UiDocument.Selection.GetElementIds().FirstOrDefault();
|
||||
//PipingSystemType type = Document.GetElement(id) as PipingSystemType;
|
||||
//type.LineColor = Color.InvalidColorValue;
|
||||
//var ids = UiDocument.Selection.GetElementIds();
|
||||
//foreach (var id in ids)
|
||||
//{
|
||||
// var elem = Document.GetElement(id) as FamilyInstance;
|
||||
// ;
|
||||
// ElementTransformUtils.MoveElement(Document, id, elem.FacingOrientation * 121 / 304.8);
|
||||
//}
|
||||
//return;
|
||||
|
||||
var refer = UiDocument.Selection.PickObject(ObjectType.Element, "请选择一个实例");
|
||||
var familyInstance = Document.GetElement(refer) as FamilyInstance;
|
||||
var reference = UiDocument.Selection.PickObject(ObjectType.Element, new FuncFilter(e => e is ImportInstance), "请选择一个实例");
|
||||
var importInstance = Document.GetElement(reference);
|
||||
|
||||
Element elem = Document.GetElement(reference);
|
||||
var geoElem = importInstance.get_Geometry(new Options());
|
||||
GeometryObject geoObj = elem.GetGeometryObjectFromReference(refer);
|
||||
|
||||
foreach (var geo in geoElem)
|
||||
{
|
||||
if (geo is GeometryInstance instance)
|
||||
{
|
||||
if (!familyInstance.Symbol.IsActive)
|
||||
{
|
||||
familyInstance.Symbol.Activate();
|
||||
}
|
||||
var tf = instance.Transform;
|
||||
foreach (var geom in instance.GetSymbolGeometry())
|
||||
{
|
||||
if (geom is Arc arc && arc.IsCyclic && geom.GraphicsStyleId == geoObj.GraphicsStyleId)//( Document.GetElement(item.GraphicsStyleId) as GraphicsStyle).GraphicsStyleCategory.Name == "平面布置"图层名称
|
||||
{
|
||||
var point = tf.OfPoint(arc.Center);
|
||||
Document.Create.NewFamilyInstance(point, familyInstance.Symbol, Document.ActiveView.GenLevel, Document.ActiveView.GenLevel, familyInstance.StructuralType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "创建实例");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user