diff --git a/.idea/.idea.Sai.RvKits/.idea/vcs.xml b/.idea/.idea.Sai.RvKits/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.Sai.RvKits/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj index 21403a2..7aee2c3 100644 --- a/ConsoleApp/ConsoleApp.csproj +++ b/ConsoleApp/ConsoleApp.csproj @@ -1,15 +1,17 @@  - net472 + net48 Exe false + + \ No newline at end of file diff --git a/ConsoleApp/Program.cs b/ConsoleApp/Program.cs index 87dd594..823dc63 100644 --- a/ConsoleApp/Program.cs +++ b/ConsoleApp/Program.cs @@ -1,26 +1,128 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using ACadSharp.Entities; + using CommunityToolkit.Diagnostics; +using CSMath; + +using OpenAI.Chat; + namespace ConsoleApp { internal class Program { static void Main(string[] args) { - string str = ""; - double a = 10.0; + //TEST(); + + ChatClient client = new ChatClient("gpt-4o", Environment.GetEnvironmentVariable("OPEN_API_KEY")); + ChatCompletion completion = client.CompleteChat("say 'this is a test.'"); + Console.WriteLine($"[ASSISTANT]:{completion.Content[0].Text}"); + } + + private static void TEST() + { + var str = ""; + var a = 10.0; double b = 100; Debug.Assert(a == b); //确保str满足条件才能继续执行,不满足即抛出异常 Guard.IsNotNullOrEmpty(str);//抛出异常 - Guard.IsLessThan(a,b); + Guard.IsLessThan(a, b); + } + + public void ReadCAD() + { + var file = @"D:\Users\Zhanggg\Desktop\Drawing1.dwg"; + var cad = new ACadSharp.IO.DwgReader(file).Read(); + var polylines = cad.Entities.OfType().Where(l => l.Layer.Name == "RQ"); + var sizes = cad.Entities.OfType().Where(t => t.Layer.Name == "RQ"); + var entities = cad.Entities.OfType().Where(i => i.Layer.Name == "0" || i.Layer.Name == "RQ" || i.Layer.Name == "GAS" || i.Layer.Name == "燃具"); + var sb = new StringBuilder(); + sb.AppendLine("多段线"); + foreach (var line in polylines) + { + var first = line.Vertices.First(); + var last = line.Vertices.Last(); + sb.AppendLine($"起点:{first.Location};终点:{last.Location}"); + } + foreach (var insert in entities) + { + if (insert.Block.Name == "立管0") + { + var temp = double.MaxValue; + string t = default; + foreach (var item in sizes) + { + var current = item.InsertPoint.DistanceFrom(insert.InsertPoint); + if (current < temp) + { + temp = current; + t = item.Value; + } + } + } + //盲板 + else if (insert.Block.Name == "盲板") + { + + } + //旋塞阀 + else if (insert.Block.Name.Contains("旋塞")) + { + + } + //商业预留,法兰球阀 + else if (insert.Block.Name.Contains("法兰球阀")) + { + + } + //锁闭型螺纹铜球阀 + else if (insert.Block.Name.Contains("户内阀")) + { + + } + //燃气表 + else if (insert.Block.Name == "计量表") + { + + } + //自闭阀 + else if (insert.Block.Name == "自闭阀") + { + + } + //热水器 + else if (insert.Block.Name == "RSQ") + { + + } + //燃气灶 + else if (insert.Block.Name == "燃气灶") + { + + } + //球阀+丝堵 + else if (insert.Block.Name.Contains("丝堵")) + { + + } + + sb.AppendLine($"图层名:{insert.Layer.Name};图块名:{insert.Block.Name};插入点:{insert.InsertPoint}"); + } + File.WriteAllText(@"D:\Users\Zhanggg\Desktop\Drawing1.dwg" + ".txt", sb.ToString(), Encoding.UTF8); + //foreach (var insert in entities) + //{ + // var blocks = insert.Block.Entities.OfType().Where(d=>d.Text.Contains("52D")); + //} } } } diff --git a/RvAddinTest/CorrectSlope.cs b/RvAddinTest/CorrectSlope.cs new file mode 100644 index 0000000..3e3c8f3 --- /dev/null +++ b/RvAddinTest/CorrectSlope.cs @@ -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; + } + } + }); + + } +} diff --git a/RvAddinTest/FluentWindow.xaml b/RvAddinTest/FluentWindow.xaml new file mode 100644 index 0000000..934d29d --- /dev/null +++ b/RvAddinTest/FluentWindow.xaml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + +