增加保温层和整理管线的功能,修复自动保存功能等修复多个bug
This commit is contained in:
58
RvAddinTest/CorrectSlope.cs
Normal file
58
RvAddinTest/CorrectSlope.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
using Nice3point.Revit.Toolkit.Utils;
|
||||
|
||||
using Sai.Toolkit.Revit.Assist;
|
||||
|
||||
namespace RvAddinTest;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
internal class CorrectSlope : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var ids = UiDocument.Selection.GetElementIds();
|
||||
Document.Modify(
|
||||
set => set.Transaction).Commit((doc, t) =>
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var elem = Document.GetElement(id);
|
||||
if (elem is MEPCurve mep)
|
||||
{
|
||||
var loc = mep.GetLocCurve() as Line;
|
||||
var x = loc.Direction.X;
|
||||
var y = loc.Direction.Y;
|
||||
var z = loc.Direction.Z;
|
||||
if (Math.Abs(loc.Direction.X) > 0 && Math.Abs(loc.Direction.X) < 10E-5)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (Math.Abs(loc.Direction.Y) > 0 && Math.Abs(loc.Direction.Y) < 10E-5)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
if (Math.Abs(loc.Direction.Z) > 0 && Math.Abs(loc.Direction.Z) < 10E-5)
|
||||
{
|
||||
z = 0;
|
||||
}
|
||||
|
||||
var dir = new XYZ(x, y, z);
|
||||
var endPoint = loc.Origin + dir * loc.Length;
|
||||
var li = Line.CreateBound(loc.Origin, endPoint);
|
||||
var locx = mep.GetLocationCurve();
|
||||
locx.Curve = li;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
78
RvAddinTest/FluentWindow.xaml
Normal file
78
RvAddinTest/FluentWindow.xaml
Normal file
@@ -0,0 +1,78 @@
|
||||
<ui:FluentWindow
|
||||
x:Class="RvAddinTest.FluentWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:RvAddinTest"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
xmlns:ws="https://schemas.elecho.dev/wpfsuite"
|
||||
xmlns:wsfd="https://schemas.elecho.dev/wpfsuite-design/fluent"
|
||||
Title="FluentWindow"
|
||||
Width="800"
|
||||
Height="450"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
WindowBackdropType="Mica"
|
||||
mc:Ignorable="d">
|
||||
<!--
|
||||
WindowOption.Backdrop="Mica"
|
||||
WindowOption.IsDarkMode="True"
|
||||
Background="Transparent"
|
||||
-->
|
||||
<Window.Resources>
|
||||
<!--<ResourceDictionary Source="pack://application:,,,/RvAddinTest;component/FluentStyles.xaml" />-->
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ui:ThemesDictionary Theme="Light" />
|
||||
<ui:ControlsDictionary />
|
||||
<!--<wsfd:FluentResources />-->
|
||||
<!--<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Themes/Dark.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Styles/TextBoxResources.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Styles/PasswordBoxResources.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Styles/CommonResources.xaml" />-->
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<DockPanel>
|
||||
<ui:TitleBar Title="测试" DockPanel.Dock="Top" />
|
||||
<ScrollViewer Margin="12">
|
||||
<StackPanel>
|
||||
<TextBox Width="200" />
|
||||
<PasswordBox />
|
||||
<Button Click="Button_Click" Content="按钮" />
|
||||
<ToggleButton Content="Tog" />
|
||||
<ComboBox>
|
||||
<ComboBoxItem Content="First" />
|
||||
<ComboBoxItem Content="Second" />
|
||||
<ComboBoxItem Content="Third" />
|
||||
</ComboBox>
|
||||
<CheckBox Content="CheckBox" />
|
||||
<TabControl>
|
||||
<TabItem Header="First" />
|
||||
<TabItem Header="Second" />
|
||||
<TabItem Header="Third" />
|
||||
</TabControl>
|
||||
<ListBox>
|
||||
<ListBoxItem Content="First" />
|
||||
<ListBoxItem Content="Second" />
|
||||
<ListBoxItem Content="Third" />
|
||||
</ListBox>
|
||||
<Menu>
|
||||
<MenuItem Header="First" />
|
||||
<MenuItem Header="Second" />
|
||||
<MenuItem Header="Third" />
|
||||
</Menu>
|
||||
<StackPanel>
|
||||
<TextBlock Text="WrapPanel with spacing" />
|
||||
<ItemsControl ItemsSource="{Binding TestItems}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</DockPanel>
|
||||
</ui:FluentWindow>
|
||||
47
RvAddinTest/FluentWindow.xaml.cs
Normal file
47
RvAddinTest/FluentWindow.xaml.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
using Wpf.Ui;
|
||||
using Wpf.Ui.Appearance;
|
||||
|
||||
namespace RvAddinTest;
|
||||
/// <summary>
|
||||
/// FluentWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class FluentWindow
|
||||
{
|
||||
public FluentWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
ApplicationThemeManager.Apply(this);
|
||||
ApplicationThemeManager.Changed -= ApplicationThemeManager_Changed;
|
||||
ApplicationThemeManager.Changed += ApplicationThemeManager_Changed;
|
||||
}
|
||||
private void ApplicationThemeManager_Changed(ApplicationTheme currentApplicationTheme, Color systemAccent)
|
||||
{
|
||||
ApplicationThemeManager.Apply(this);
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ApplicationThemeManager.GetAppTheme() == ApplicationTheme.Light)
|
||||
{
|
||||
ApplicationThemeManager.Apply(ApplicationTheme.Dark);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationThemeManager.Apply(ApplicationTheme.Light);
|
||||
}
|
||||
}
|
||||
}
|
||||
320
RvAddinTest/GASInstancesCreator.cs
Normal file
320
RvAddinTest/GASInstancesCreator.cs
Normal file
@@ -0,0 +1,320 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Documents;
|
||||
|
||||
using ACadSharp.Entities;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using CSMath;
|
||||
using XYZ = Autodesk.Revit.DB.XYZ;
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
using Nice3point.Revit.Toolkit.Options;
|
||||
using Nice3point.Revit.Toolkit.Utils;
|
||||
using Line = Autodesk.Revit.DB.Line;
|
||||
using Autodesk.Revit.DB.Plumbing;
|
||||
using System.IO;
|
||||
using System.Collections.ObjectModel;
|
||||
using Sai.Toolkit.Revit.Assist;
|
||||
using Microsoft.Win32;
|
||||
using Sai.Toolkit.Core.Helpers;
|
||||
|
||||
namespace RvAddinTest
|
||||
{
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class GASInstancesCreator : ExternalCommand
|
||||
{
|
||||
private XYZ XYToRevitXYZ(CSMath.XY point)
|
||||
{
|
||||
return new XYZ(point.X, point.Y, 0) / 304.8;
|
||||
}
|
||||
|
||||
private XYZ XYZToRevitXYZ(CSMath.XYZ point)
|
||||
{
|
||||
return new XYZ(point.X, point.Y, 0) / 304.8;
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
//var id = UiDocument.Selection.GetElementIds().First();
|
||||
//var elem = Document.GetElement(id) as FamilyInstance;
|
||||
//var point = elem.GetLocXYZ();
|
||||
|
||||
//var pipes = new FilteredElementCollector(Document).OfClass(typeof(Pipe)).Cast<Pipe>();
|
||||
//Pipe p;
|
||||
//foreach (var pipe in pipes)
|
||||
//{
|
||||
// var line = pipe.GetLocCurve() as Line;
|
||||
// var lineOrigin = line.Origin.Flatten();
|
||||
// var temp = double.MaxValue;
|
||||
// if (line.Direction == XYZ.BasisZ)
|
||||
// {
|
||||
// var dis = point.DistanceTo(lineOrigin);
|
||||
// if (dis < temp)
|
||||
// {
|
||||
// p = pipe;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//var conns = elem.MEPModel.ConnectorManager.UnusedConnectors.OfType<Connector>().FirstOrDefault();
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "dwg文件(*.dwg)|*.dwg"
|
||||
};
|
||||
if (dialog.ShowDialog()==true)
|
||||
{
|
||||
var file = dialog.FileName;
|
||||
var cad = new ACadSharp.IO.DwgReader(file).Read();
|
||||
var polylines = cad.Entities.OfType<LwPolyline>().Where(l => l.Layer.Name == "RQ" && l.Color.Equals(ACadSharp.Color.ByLayer));
|
||||
var sizes = cad.Entities.OfType<TextEntity>().Where(t => t.Layer.Name == "RQ" && t.Value.Contains("D"));
|
||||
var entities = cad.Entities.OfType<Insert>().Where(i => i.Layer.Name == "0" || i.Layer.Name == "RQ" || i.Layer.Name == "GAS" || i.Layer.Name == "燃具");
|
||||
Create(polylines, sizes, entities);
|
||||
}
|
||||
}
|
||||
|
||||
private void Create(IEnumerable<LwPolyline> polylines, IEnumerable<TextEntity> sizes, IEnumerable<Insert> entities)
|
||||
{
|
||||
var pipeType = new FilteredElementCollector(Document).OfClass(typeof(PipeType))
|
||||
.FirstOrDefault(pt => pt.Name == "低压燃气管道");
|
||||
var systemType = new FilteredElementCollector(Document).OfClass(typeof(PipingSystemType))
|
||||
.FirstOrDefault(pt => pt.Name == "低压燃气系统");
|
||||
|
||||
var mb = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("盲板")) as FamilySymbol;
|
||||
var xs = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("旋塞")) as FamilySymbol;
|
||||
var flqf = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("法兰球阀")) as FamilySymbol;
|
||||
var tqf = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("铜制球阀")) as FamilySymbol;
|
||||
var rqb = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("燃气表")) as FamilySymbol;
|
||||
var zbf = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("自闭阀")) as FamilySymbol;
|
||||
var rsq = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("热水器")) as FamilySymbol;
|
||||
var rqz = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name.Contains("燃气灶")) as FamilySymbol;
|
||||
var qf = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name == "球阀") as FamilySymbol;
|
||||
var sd = new FilteredElementCollector(Document).OfClass(typeof(FamilySymbol))
|
||||
.FirstOrDefault(pt => pt.Name == "丝堵") as FamilySymbol;
|
||||
var sb = new StringBuilder();
|
||||
using (var ts = new Transaction(Document, "翻模"))
|
||||
{
|
||||
ts.Start();
|
||||
|
||||
foreach (var line in polylines)
|
||||
{
|
||||
var tempDistance = double.MaxValue;
|
||||
TextEntity textNoteNearest = null;
|
||||
var vector = XYZ.BasisX;
|
||||
var locXY = line.Vertices.FirstOrDefault().Location;
|
||||
var firstPoint = XYToRevitXYZ(locXY);
|
||||
var lastPoint = XYToRevitXYZ(line.Vertices.LastOrDefault().Location);
|
||||
if (firstPoint.DistanceTo(lastPoint)<Application.ShortCurveTolerance)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var rLine = Line.CreateBound(firstPoint, lastPoint);
|
||||
TextEntity size = null;
|
||||
foreach (var text in sizes)
|
||||
{
|
||||
var rotation = text.Rotation;
|
||||
var transform = Autodesk.Revit.DB.Transform.CreateRotation(XYZ.BasisZ, rotation);
|
||||
var textVector = transform.OfVector(vector);
|
||||
XYZ flattenCoord = XYZToRevitXYZ(text.InsertPoint);
|
||||
var currentDistance = rLine.Distance(flattenCoord);
|
||||
if (currentDistance < tempDistance && 1 - rLine.Direction.DotProduct(textVector) < 10E-4)
|
||||
{
|
||||
tempDistance = currentDistance;
|
||||
textNoteNearest = text;
|
||||
size = text;
|
||||
//vector = text.ObliqueAngle;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
var first = line.Vertices.First().Location;
|
||||
var last = line.Vertices.Last().Location;
|
||||
|
||||
var pipe = Pipe.Create(
|
||||
Document,
|
||||
systemType.Id,
|
||||
pipeType.Id,
|
||||
Document.ActiveView.GenLevel.Id,
|
||||
XYToRevitXYZ(first) + 3200 / 304.8 * XYZ.BasisZ,
|
||||
XYToRevitXYZ(last) + 3200 / 304.8 * XYZ.BasisZ);
|
||||
var str = size.Value.Split('D').LastOrDefault();
|
||||
var str1 = str.Trim('N');
|
||||
if (double.TryParse(str1, out var d))
|
||||
{
|
||||
pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(d / 304.8);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.AppendLine(ex.Message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
foreach (var insert in entities)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (insert.Block.Name == "立管0")
|
||||
{
|
||||
var temp = double.MaxValue;
|
||||
string t = default;
|
||||
foreach (var item in sizes)
|
||||
{
|
||||
if (item.Value.StartsWith("DN") && item.Rotation < 10E-3)
|
||||
{
|
||||
var current = item.InsertPoint.DistanceFrom(insert.InsertPoint);
|
||||
if (current < temp)
|
||||
{
|
||||
temp = current;
|
||||
t = item.Value.Replace("DN", string.Empty);
|
||||
}
|
||||
}
|
||||
if (item.Value.StartsWith("D") && item.Rotation < 10E-3)
|
||||
{
|
||||
var current = item.InsertPoint.DistanceFrom(insert.InsertPoint);
|
||||
if (current < temp)
|
||||
{
|
||||
temp = current;
|
||||
t = item.Value.Replace("D", string.Empty).Split('*').First();
|
||||
}
|
||||
}
|
||||
}
|
||||
var pipe = Pipe.Create(
|
||||
Document,
|
||||
systemType.Id,
|
||||
pipeType.Id,
|
||||
Document.ActiveView.GenLevel.Id,
|
||||
XYZToRevitXYZ(insert.InsertPoint),
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 3200 / 304.8 * XYZ.BasisZ);
|
||||
if (double.TryParse(t, out var d))
|
||||
{
|
||||
pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(d / 304.8);
|
||||
}
|
||||
}
|
||||
//盲板
|
||||
else if (insert.Block.Name == "盲板")
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 2000 / 304.8 * XYZ.BasisZ,
|
||||
mb,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//旋塞阀
|
||||
else if (insert.Block.Name.Contains("旋塞"))
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 1100 / 304.8 * XYZ.BasisZ,
|
||||
rqb,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//商业预留,法兰球阀
|
||||
else if (insert.Block.Name.Contains("法兰球阀"))
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 2000 / 304.8 * XYZ.BasisZ,
|
||||
rqb,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//锁闭型螺纹铜球阀
|
||||
else if (insert.Block.Name.Contains("户内阀"))
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 1800 / 304.8 * XYZ.BasisZ,
|
||||
tqf,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//燃气表
|
||||
else if (insert.Block.Name == "计量表")
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 1600 / 304.8 * XYZ.BasisZ,
|
||||
rqb,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//自闭阀
|
||||
else if (insert.Block.Name == "自闭阀")
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 900 / 304.8 * XYZ.BasisZ,
|
||||
zbf,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//热水器
|
||||
//else if (insert.Block.Name == "RSQ")
|
||||
//{
|
||||
// Document.Create
|
||||
// .NewFamilyInstance(
|
||||
// XYZToRevitXYZ(insert.InsertPoint) + 1100 / 304.8 * XYZ.BasisZ,
|
||||
// rsq,
|
||||
// Document.ActiveView.GenLevel,
|
||||
// Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
//}
|
||||
//燃气灶
|
||||
else if (insert.Block.Name == "燃气灶")
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 900 / 304.8 * XYZ.BasisZ,
|
||||
rqz,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
//球阀+丝堵
|
||||
else if (insert.Block.Name.Contains("丝堵"))
|
||||
{
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 1800 / 304.8 * XYZ.BasisZ,
|
||||
qf,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
Document.Create
|
||||
.NewFamilyInstance(
|
||||
XYZToRevitXYZ(insert.InsertPoint) + 1600 / 304.8 * XYZ.BasisZ,
|
||||
sd,
|
||||
Document.ActiveView.GenLevel,
|
||||
Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.AppendLine(ex.Message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ts.Commit();
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
File.WriteAllText(@"D:\Users\Zhanggg\Desktop\Errors.txt", sb.ToString(), Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
89
RvAddinTest/InstancesCreator.cs
Normal file
89
RvAddinTest/InstancesCreator.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
using Nice3point.Revit.Toolkit.Options;
|
||||
using Nice3point.Revit.Toolkit.Utils;
|
||||
|
||||
namespace RvAddinTest
|
||||
{
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class InstancesCreator : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var doc = Document;
|
||||
var uidoc = UiDocument;
|
||||
//var uidoc = uiApplication.ActiveUIDocument;
|
||||
//var doc = uidoc.Document;
|
||||
var ids = uidoc.Selection.GetElementIds();
|
||||
|
||||
using (Transaction ts = new(doc, "旋转"))
|
||||
{
|
||||
ts.Start();
|
||||
var collector = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(TextNote));
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var elem = doc.GetElement(id);
|
||||
var loc = elem.Location as LocationPoint;
|
||||
var point = loc.Point;
|
||||
XYZ flattenXY = new(loc.Point.X, loc.Point.Y, 0);
|
||||
var tempDistance = double.MaxValue;
|
||||
TextNote textNoteNearest = null;
|
||||
var vector = XYZ.BasisX;
|
||||
foreach (var element in collector)
|
||||
{
|
||||
var textNote = element as TextNote;
|
||||
XYZ flattenCoord = new(textNote.Coord.X, textNote.Coord.Y, 0);
|
||||
var currentDistance = flattenCoord.DistanceTo(flattenXY);
|
||||
if (currentDistance < tempDistance)
|
||||
{
|
||||
tempDistance = currentDistance;
|
||||
textNoteNearest = textNote;
|
||||
vector = textNote.BaseDirection;
|
||||
}
|
||||
}
|
||||
if (textNoteNearest == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var radian = XYZ.BasisX.AngleTo(vector);
|
||||
|
||||
var crossProduct = XYZ.BasisX.CrossProduct(textNoteNearest.BaseDirection).Normalize();
|
||||
if (Math.Abs(radian - Math.PI) < 10E-6)
|
||||
{
|
||||
ElementTransformUtils.RotateElement(doc, id, Line.CreateUnbound(point, XYZ.BasisZ), Math.PI);
|
||||
}
|
||||
if (crossProduct.IsAlmostEqualTo(XYZ.BasisZ))
|
||||
{
|
||||
ElementTransformUtils.RotateElement(doc, id, Line.CreateUnbound(point, XYZ.BasisZ), radian);
|
||||
}
|
||||
if (crossProduct.IsAlmostEqualTo(-XYZ.BasisZ))
|
||||
{
|
||||
ElementTransformUtils.RotateElement(doc, id, Line.CreateUnbound(point, XYZ.BasisZ), 2 * Math.PI - radian);
|
||||
}
|
||||
}
|
||||
ts.Commit();
|
||||
}
|
||||
|
||||
//MainWindow window = new MainWindow(Document);
|
||||
//window.ShowDialog();
|
||||
}
|
||||
}
|
||||
public class InsertInfo
|
||||
{
|
||||
|
||||
public string Name { get; set; }
|
||||
public XYZ InsertPoint { get; set; }
|
||||
public double Radian { get; set; }
|
||||
public double Length { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@
|
||||
<DefineConstants>$(DefineConstants);REVIT2018</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bogus" Version="35.5.1" />
|
||||
<PackageReference Include="EleCho.WpfSuite.FluentDesign" Version="0.0.1" />
|
||||
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.30" />
|
||||
<PackageReference Include="ACadSharp" Version="1.0.2" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="EleCho.WpfSuite" Version="0.9.1.2" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.21" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.122" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
|
||||
<PackageReference Include="Nice3point.Revit.Api.Adwindows" Version="2018.*" PrivateAssets="All" />
|
||||
<PackageReference Include="Nice3point.Revit.Api.UIFramework" Version="2018.*" PrivateAssets="All" />
|
||||
<PackageReference Include="Nice3point.Revit.Api.RevitAPI" Version="2018.*" PrivateAssets="All" />
|
||||
@@ -36,6 +36,7 @@
|
||||
<PackageReference Include="EPPlus.Core.Extensions" Version="2.4.0" />
|
||||
<PackageReference Include="JerryShaw.AduSkin" Version="1.1.1.11" />
|
||||
<PackageReference Include="Nice3point.Revit.Toolkit" Version="2019.0.12" PrivateAssets="All" />
|
||||
<PackageReference Include="WPF-UI" Version="4.0.0-rc.2" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\Sai.Toolkit.Revit\Sai.Toolkit.Revit.projitems" Label="Shared" />
|
||||
<Import Project="..\Sai.Toolkit.Core\Sai.Toolkit.Core.projitems" Label="Shared" />
|
||||
|
||||
89
RvAddinTest/TempCmd.cs
Normal file
89
RvAddinTest/TempCmd.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Mechanical;
|
||||
using Autodesk.Revit.DB.Plumbing;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using Sai.Toolkit.Revit.Assist;
|
||||
using Sai.Toolkit.Revit.Helpers;
|
||||
|
||||
namespace RvAddinTest;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class TempCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var elemIds = Document.OfClass<Pipe>().Cast<Pipe>().Where(p => p.Diameter == 50 / 304.8 && !(p.GetLocCurve() as Line).Direction.IsParallelTo(XYZ.BasisZ)).Select(p => p.Id).ToList();
|
||||
//var elementIds = uidoc.Selection.GetElementIds();
|
||||
//var elementIds = new FilteredElementCollector(Document).OfClass(typeof(FamilyInstance)).Where(ins => ins.Name == "DN15").Select(ins => ins.Id).ToList();
|
||||
//using (var ts = new Transaction(Document, "Temp"))
|
||||
//{
|
||||
// ts.Start();
|
||||
//doc.Delete(elementIds);
|
||||
//foreach (var id in elementIds)
|
||||
//{
|
||||
// var elem = Document.GetElement(id) as FamilyInstance;
|
||||
// var p = elem.GetLocXYZ();
|
||||
// //ElementTransformUtils.MoveElement(Document,id,-elem.HandOrientation*125/304.8);
|
||||
// //Document.Regenerate();
|
||||
// //ElementTransformUtils.MoveElement(Document, id,-elem.FacingOrientation*95/304.8);
|
||||
// ElementTransformUtils.RotateElement(
|
||||
// Document,
|
||||
// id,
|
||||
// Line.CreateUnbound(p, XYZ.BasisZ),
|
||||
// Math.PI / 2);
|
||||
//}
|
||||
//内衬
|
||||
//var e = InsulationLiningBase.GetLiningIds(doc, elem.Id);
|
||||
//保温
|
||||
//var p = InsulationLiningBase.GetInsulationIds(doc, elem.Id);
|
||||
//var uidoc = UiApplication.ActiveUIDocument;
|
||||
//var doc = uidoc.Document;
|
||||
//var reference = uidoc.Selection.PickObject(ObjectType.Element);
|
||||
//var elem = doc.GetElement(reference);
|
||||
//var id = InsulationLiningBase.GetInsulationIds(Document, elem.Id).FirstOrDefault();
|
||||
// ts.Commit();
|
||||
//}
|
||||
Document.Invoke(
|
||||
ts =>
|
||||
{
|
||||
try
|
||||
{
|
||||
UiDocument.Selection.SetElementIds(elemIds);
|
||||
|
||||
//ElementTransformUtils.MoveElements(Document, elemIds, XYZ.BasisZ * 200 / 304.8);
|
||||
|
||||
//foreach (var elem in elems)
|
||||
//{
|
||||
// elem.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(50 / 304.8);
|
||||
//}
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
}
|
||||
}, "CMD");
|
||||
}
|
||||
public class ArrangeElement
|
||||
{
|
||||
public XYZ Translation { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public Element ElementToMove { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 与基准元素的间距及方向向量
|
||||
/// </summary>
|
||||
public XYZ HorizonDistanceVector { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user