2024-09-22 11:05:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-10-08 16:21:39 +08:00
|
|
|
|
using System.Diagnostics;
|
2024-10-27 00:19:48 +08:00
|
|
|
|
using System.IO;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2024-10-27 00:19:48 +08:00
|
|
|
|
using ACadSharp.Entities;
|
|
|
|
|
|
|
2024-09-22 11:05:41 +08:00
|
|
|
|
using CommunityToolkit.Diagnostics;
|
|
|
|
|
|
|
2024-10-27 00:19:48 +08:00
|
|
|
|
using CSMath;
|
|
|
|
|
|
|
|
|
|
|
|
using OpenAI.Chat;
|
|
|
|
|
|
|
2024-09-22 11:05:41 +08:00
|
|
|
|
namespace ConsoleApp
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
|
{
|
2024-10-27 00:19:48 +08:00
|
|
|
|
//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;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
double b = 100;
|
2024-10-08 16:21:39 +08:00
|
|
|
|
|
|
|
|
|
|
Debug.Assert(a == b);
|
2024-09-22 11:05:41 +08:00
|
|
|
|
//确保str满足条件才能继续执行,不满足即抛出异常
|
|
|
|
|
|
Guard.IsNotNullOrEmpty(str);//抛出异常
|
2024-10-27 00:19:48 +08:00
|
|
|
|
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<LwPolyline>().Where(l => l.Layer.Name == "RQ");
|
|
|
|
|
|
var sizes = cad.Entities.OfType<TextEntity>().Where(t => t.Layer.Name == "RQ");
|
|
|
|
|
|
var entities = cad.Entities.OfType<Insert>().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<Dimension>().Where(d=>d.Text.Contains("52D"));
|
|
|
|
|
|
//}
|
2024-09-22 11:05:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|