更新
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;
|
||||
|
||||
Reference in New Issue
Block a user