更新
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using Microsoft.Xaml.Behaviors;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
|
||||
@@ -26,6 +32,7 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
}
|
||||
|
||||
private readonly UIDocument uiDocument;
|
||||
|
||||
~InstanceCreatorViewModel()
|
||||
{
|
||||
uiDocument.Application.Application.FamilyLoadedIntoDocument -= Application_FamilyLoadedIntoDocument;
|
||||
@@ -122,7 +129,7 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
Reference reference;
|
||||
try
|
||||
{
|
||||
reference = uiDocument.Selection.PickObject(ObjectType.PointOnElement, new DwgBlockSelection(), "请选择dwg链接的块参照");
|
||||
reference = uiDocument.Selection.PickObject(ObjectType.PointOnElement, new DwgElementSelection(), "请选择dwg链接的块参照");
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
@@ -156,8 +163,8 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
foreach (var ins in geoInstances)
|
||||
{
|
||||
var level = document.ActiveView.GenLevel;
|
||||
var loc = ins.GetLocationPoint(dwgTransform, out var rotation);
|
||||
|
||||
GetPose(dwgTransform, ins, out var loc, out var rotation);
|
||||
var familyInstance = document.Create.NewFamilyInstance(loc, symbol, level, StructuralType.NonStructural);
|
||||
document.Regenerate();
|
||||
ElementTransformUtils.RotateElement(document, familyInstance.Id, Line.CreateUnbound(loc, XYZ.BasisZ), rotation);
|
||||
@@ -177,7 +184,8 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
var level = document.ActiveView.GenLevel;
|
||||
foreach (var ins in geoInstances)
|
||||
{
|
||||
GetPose(dwgTransform, ins, out var loc, out var rotation);
|
||||
var loc = ins.GetLocationPoint(dwgTransform, out var rotation);
|
||||
|
||||
var minPoint = loc - new XYZ(0.4, 0.4, -level.Elevation);
|
||||
var maxPoint = loc + new XYZ(0.4, 0.4, level.Elevation + 1);
|
||||
var outline = new Outline(minPoint, maxPoint);
|
||||
@@ -193,7 +201,8 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
foreach (var ins in geoInstances)
|
||||
{
|
||||
var level = document.ActiveView.GenLevel;
|
||||
GetPose(dwgTransform, ins, out var loc, out var rotation);
|
||||
var loc = ins.GetLocationPoint(dwgTransform, out var rotation);
|
||||
|
||||
var familyInstance = document.Create.NewFamilyInstance(loc, symbol, level, StructuralType.NonStructural);
|
||||
document.Regenerate();
|
||||
ElementTransformUtils.RotateElement(document, familyInstance.Id, Line.CreateUnbound(loc, XYZ.BasisZ), rotation);
|
||||
@@ -206,7 +215,7 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
case FamilyPlacementType.WorkPlaneBased:
|
||||
foreach (var ins in geoInstances)
|
||||
{
|
||||
GetPose(dwgTransform, ins, out var loc, out var rotation);
|
||||
var loc = ins.GetLocationPoint(dwgTransform, out var rotation);
|
||||
var familyInstance = document.Create.NewFamilyInstance(
|
||||
loc,
|
||||
symbol,
|
||||
@@ -267,53 +276,6 @@ public partial class InstanceCreatorViewModel : ObservableObject
|
||||
// e => e.Value
|
||||
// );
|
||||
//}
|
||||
/// <summary>
|
||||
/// 获取更加准确的位置
|
||||
/// </summary>
|
||||
/// <param name="dwgTransform"></param>
|
||||
/// <param name="ins"></param>
|
||||
/// <param name="loc"></param>
|
||||
/// <param name="rotation"></param>
|
||||
private static void GetPose(Transform dwgTransform, GeometryInstance ins, out XYZ loc, out double rotation)
|
||||
{
|
||||
var blockLocation = ins.Transform.Origin;
|
||||
|
||||
if (ins.Transform.Origin.GetLength() is > 1000 or 0) //块原点距离实际几何重心过远时
|
||||
{
|
||||
//存在标注的情况时,以多段线最准确
|
||||
var b = ins.GetInstanceGeometry().Any(i => i is PolyLine);
|
||||
foreach (var geometryObject in ins.GetInstanceGeometry())
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
if (geometryObject is PolyLine pl)
|
||||
{
|
||||
blockLocation = (pl.GetOutline().MaximumPoint + pl.GetOutline().MinimumPoint) / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (geometryObject is Line l)
|
||||
{
|
||||
blockLocation = l.Evaluate(0.5, true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (geometryObject is Arc arc)
|
||||
{
|
||||
blockLocation = arc.Center;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loc = dwgTransform.OfPoint(blockLocation);
|
||||
loc = new XYZ(loc.X, loc.Y, 0);
|
||||
rotation = Math.Abs(ins.Transform.BasisX.AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ) - (2 * Math.PI));
|
||||
}
|
||||
|
||||
partial void OnSelectedFamilyChanged(Family value)
|
||||
{
|
||||
var doc = value.Document;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -9,9 +12,6 @@ using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
using ShrlAlgoToolkit.Core.Assists;
|
||||
using ShrlAlgoToolkit.Mvvm.Attributes;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Windows;
|
||||
|
||||
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.RvCommon
|
||||
@@ -146,7 +146,7 @@ namespace ShrlAlgoToolkit.RevitAddins.RvCommon
|
||||
"请选择模型线并完成选择"
|
||||
);
|
||||
curves = refers.Select(r => doc.GetElement(r)).OfType<ModelCurve>().Select(mc => mc.GeometryCurve).ToList();
|
||||
var loops = SpatialAssist.ToCurveLoops(curves);
|
||||
var loops = SpatialAssist.GroupContinuousCurves(curves);
|
||||
if (loops.Count != 1)
|
||||
{
|
||||
MessageBox.Show("未选择路径或所选线条不止一条路径", "错误");
|
||||
@@ -427,7 +427,7 @@ namespace ShrlAlgoToolkit.RevitAddins.RvCommon
|
||||
ElementId.InvalidElementId
|
||||
);
|
||||
//获取截面的曲线集合
|
||||
var list = SpatialAssist.ToCurveLoops(profiles);
|
||||
var list = SpatialAssist.GroupContinuousCurves(profiles);
|
||||
//生成截面线串
|
||||
var loops = list.Select(cs => CurveLoop.Create(cs)).ToList();
|
||||
//两侧放在前面,先复制
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.RvCommon;
|
||||
/// <summary>
|
||||
/// 相对移动
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
internal class MoveElementByRelationshipCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ public partial class PipesCreatorViewModel : ObservableObject
|
||||
&& mep.GetType() == mep1.GetType()
|
||||
)
|
||||
{
|
||||
var connectors = ConnectorAssist.GetNearestConnectors(mep, mep1);
|
||||
var connectors = ConnectorExtensions.GetNearestConnectors(mep, mep1);
|
||||
if (connectors.Count == 2 && connectors[0].Origin.IsAlmostEqualTo(connectors[1].Origin))
|
||||
{
|
||||
connectors[0].ConnectByFitting(connectors[1]);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
|
||||
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.RvCommon;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.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, p) => 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "创建实例");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.RvCommon;
|
||||
|
||||
/// <summary>
|
||||
/// 分割族中的整体dwg模型为单个Solid
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class SplitImportInstanceCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var refer = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new GenericFilter<ImportInstance>(), "请选择导入的实体");
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
var elem = Document.GetElement(refer) as DirectShape;
|
||||
var geometryElement = elem.get_Geometry(new Options() { ComputeReferences = true });
|
||||
foreach(var item in geometryElement)
|
||||
{
|
||||
if(item is Solid solid)
|
||||
{
|
||||
//MessageBox.Show("获取到Solid");
|
||||
var element = DirectShape.CreateElement(
|
||||
Document,
|
||||
Category.GetCategory(Document, BuiltInCategory.OST_GenericModel).Id);
|
||||
element.AppendShape([solid]);
|
||||
//return;
|
||||
}
|
||||
}
|
||||
Document.Delete(refer.ElementId);
|
||||
},
|
||||
"拆分实体");
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user