Init commit

This commit is contained in:
lihanbo 2025-03-04 11:35:11 +08:00
commit 62b982cf17
68 changed files with 5987 additions and 0 deletions

289
.gitignore vendored Normal file
View File

@ -0,0 +1,289 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# VS Code
.vscode/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

BIN
AutoSW_bin/AntdUI.dll Normal file

Binary file not shown.

BIN
AutoSW_bin/AutoSW.Agent.dll Normal file

Binary file not shown.

BIN
AutoSW_bin/AutoSW.UI.dll Normal file

Binary file not shown.

BIN
AutoSW_bin/AutoSW.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
AutoSW_bin/OpenAI.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutoSW.Agent;
[AttributeUsage(AttributeTargets.Method)]
public class AIFuncAttribute : Attribute
{
}

View File

@ -0,0 +1,577 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AntdUI;
using Microsoft.Extensions.AI;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using SolidWorks.Interop.swdimxpert;
using SolidWorks.Interop.swpublished;
namespace AutoSW.Agent;
public class AgentExecutor
{
private static List<AITool> _allAiFunc = new();
public static List<MethodInfo> Funcs = new();
internal static SldWorks SldWorksApp
{
get; set;
}
public static void Init(SldWorks sld)
{
SldWorksApp = sld;
SWFunctions.SwApp = sld;
Debug.WriteLine("AgentExecutor init");
//var funcs = typeof(SWFunctions).GetMethods().Where(it => it.GetCustomAttributes(true).Any(it => it is AIFuncAttribute)).ToList();
var funcs = typeof(AgentExecutor).GetMethods().Where(it => it.GetCustomAttributes(true).Any(it => it is AIFuncAttribute)).ToList();
foreach (var method in funcs)
{
_allAiFunc.Add(AIFunctionFactory.Create(method, null, null));
}
}
/// <summary>
/// 获取所有的工具函数
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static List<AITool> GetDefaultTools()
{
_allAiFunc.AddRange(new List<AITool>
{
AIFunctionFactory.Create(GetCurrentDoc),
AIFunctionFactory.Create(GetModelDocInfo)
});
return _allAiFunc;
}
#region AIFunc
[AIFunc]
[Description("获取当前打开的文档")]
public static string GetCurrentDoc()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
var resultStr = @$"文档文件名:{model.GetTitle()},文档路径:{model.GetPathName()}";
return resultStr;
}
}
}
[AIFunc]
[Description("打开Solidworks文件返回该文件的所有配置名称")]
public static string GetModelDocInfo(string filePath)
{
SWFunctions.OpenDocument(filePath, true);
ModelDoc2 doc = SldWorksApp.IActiveDoc2;
var configNames = ((string[])doc.GetConfigurationNames());
return @$"Name:{doc.GetTitle()},
ConfigNames:{string.Join(",", configNames)}";
}
/// <summary>
/// 关闭当前打开的文档
/// </summary>
/// <returns></returns>
[AIFunc]
[Description("关闭当前打开的文档")]
public static string CloseCurrentDoc()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
SldWorksApp.CloseDoc(model.GetTitle());
return "关闭成功";
}
}
}
[AIFunc]
[Description("读取文档属性")]
public static string GetDocProperty(string configName,string propertyName)
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
var property = model.Extension.CustomPropertyManager[configName];
var value = property.Get5(propertyName,false,out string val,out string resolvedVal,out bool wasResolved);
//if()
if (wasResolved)
{
return resolvedVal;
}
else
{
return val;
}
}
}
}
[AIFunc]
[Description("获取文档所有属性名")]
public static string GetDocPropertyNames(string configName)
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
var property = model.Extension.CustomPropertyManager[configName];
var names = property.GetNames();
return string.Join(",", names);
}
}
}
[AIFunc]
[Description("获取文档所有配置名")]
public static string GetDocConfigNames()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
var configNames = model.GetConfigurationNames();
return string.Join(",", configNames);
}
}
}
[AIFunc]
[Description("获取文档所有特征信息")]
public static string GetDocFeatureInfo()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
var features = model.FeatureManager.GetFeatures(true);
var result = new List<string>();
foreach (Feature feature in features)
{
if(!feature.GetTypeName().Contains("Folder"))
result.Add($"特征名称:{feature.Name},特征类型:{feature.GetTypeName()}");
}
return string.Join(",", result);
}
}
}
[AIFunc]
[Description("获取装配体下所有的子项")]
public static string GetAssemblyChildren()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
if (model.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY)
{
return "当前打开的不是装配体";
}
else
{
var assembly = (AssemblyDoc)model;
var children = assembly.GetComponents(false);
var result = new List<string>();
foreach (Component2 child in children)
{
result.Add(child.Name2);
}
return string.Join(",", result);
}
}
}
}
[AIFunc]
[Description("获取当前打开的文档类型(装配体 零件 工程图)")]
public static string GetDocType()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
var type = model.GetType();
if (type == (int)swDocumentTypes_e.swDocPART)
{
return "零件";
}
else if (type == (int)swDocumentTypes_e.swDocASSEMBLY)
{
return "装配体";
}
else if (type == (int)swDocumentTypes_e.swDocDRAWING)
{
return "工程图";
}
else
{
return "未知类型";
}
}
}
}
[AIFunc]
[Description("获取零件所有孔位信息")]
public static string GetPartHoles()
{
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
ModelDoc2 model = SldWorksApp.IActiveDoc2;
if (model == null)
{
return "未打开任何文档";
}
else
{
if (model.GetType() != (int)swDocumentTypes_e.swDocPART)
{
return "当前打开的不是零件";
}
else
{
//var part = (PartDoc)model;
var features = model.FeatureManager.GetFeatures(true);
var result = new List<string>();
foreach (Feature feature in features)
{
if (feature.GetTypeName() == "HoleWzd")
{
result.Add($"孔名称:{feature.Name}");
}
}
return string.Join(",", result);
}
}
}
}
[AIFunc]
[Description("获取工程图所有的标注")]
public static string GetDrwInfo()
{
var result = new StringBuilder();
ModelDoc2 modelDoc2 = (ModelDoc2)(SldWorksApp.ActiveDoc);
if(modelDoc2.GetType() == (int)swDocumentTypes_e.swDocDRAWING)
{
DrawingDoc drawingDoc = (DrawingDoc)modelDoc2;
SolidWorks.Interop.sldworks.View view = drawingDoc.GetFirstView();
do
{
// 第一次获取到的视图,会是整个工程图,所以跳过第一个
if (view != null)
{
object[] displayDimensions = view.GetDisplayDimensions();
if (displayDimensions != null)
foreach (var displayDimension in displayDimensions)
{
var swDisplayDimension = (DisplayDimension)displayDimension;
//swDisplayDimension.get
//尺寸对象
var swDimension = (Dimension)(swDisplayDimension).GetDimension();
var anno = (Annotation)swDisplayDimension.GetAnnotation();
anno.Select3(false, null);
// 标注名称
var annoName = anno.GetName();
//获取尺寸的公差
var cruToleranceType = swDimension.GetToleranceType();
var cruTolerance = swDimension.Tolerance;
var ToleranceValue = "";
if (cruToleranceType == (int)swTolType_e.swTolBILAT)
{
cruTolerance.GetMaxValue2(out var ToleranceValueMax); //上公差
cruTolerance.GetMinValue2(out var ToleranceValueMin);//下公差
// 默认单位应该是M 转换为mm
ToleranceValue = $"上公差{ToleranceValueMax * 1000},下公差{ToleranceValueMin * 1000}";
}
double[] positions = anno.GetPosition();
for (var i = 0; i < positions.Length; i++)
{
Debug.WriteLine(positions[i]);
}
// 取文本
DisplayData displayData = (DisplayData)swDisplayDimension.GetDisplayData();
var textCount = displayData.GetTextCount();
var textList = new List<string>();
for (var i = 0; i < textCount; i++)
{
var text = displayData.GetTextAtIndex(i);
//Debug.WriteLine(text);
textList.Add(text);
}
// 获取标注对应的零件特征
//swDisplayDimension.
//var feature = swDimension.get
//Debug.WriteLine();<{feature.Name}>
if (swDisplayDimension.IsHoleCallout())
{
result.Append($"<孔标注 - {annoName}@{view.Name}>:");
}
else
{
result.Append($"<{annoName}@{view.Name}>:");
}
if(positions != null && positions.Length > 1)
{
result.Append($"位置[{positions[0]},{positions[1]}]");
}
if (!string.IsNullOrEmpty(ToleranceValue))
{
result.Append(ToleranceValue);
result.Append("_");
}
result.Append($"标注内容[{string.Join(",", textList)}]");
result.AppendLine();
}
}
view = view.GetNextView();
} while (view != null);
}
//Debug.WriteLine(result);
return result.ToString();
}
[AIFunc]
[Description("获取默认模板地址")]
public static string GetDefaultTemplatePath()
{
return SldWorksApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
}
[AIFunc]
[Description("保存宏文件内容到临时路径")]
public static string SaveMacroToTemp(string macroContent)
{
var tempPath = System.IO.Path.GetTempPath();
var tempFile = System.IO.Path.Combine(tempPath, $"tempMacro_{DateTime.Now.Ticks}.swp");
System.IO.File.WriteAllText(tempFile, macroContent);
return tempFile;
}
[AIFunc]
[Description("执行宏")]
public static string RunMacroToTemp(string macroPath, string ModuleName,string procedureName)
{
try
{
Debug.WriteLine($"{Path.GetFileName(macroPath)},{ModuleName},{procedureName}");
if (SldWorksApp == null)
{
return "未连接到SolidWorks";
}
else
{
SldWorksApp.RunMacro2(macroPath, ModuleName, procedureName, (int)swRunMacroOption_e.swRunMacroDefault, out int errorCount);
if (errorCount > 0)
{
/*
swRunMacroError_BadParmCount 9
swRunMacroError_BadVarType 10
swRunMacroError_Busy 17
swRunMacroError_CallFailed 20
swRunMacroError_CallRejected 19
swRunMacroError_CantSave 27
swRunMacroError_ConnectionTerminated 18
swRunMacroError_DiskError 26
swRunMacroError_Exception 12
swRunMacroError_InvalidArg 1
swRunMacroError_Invalidindex 22
swRunMacroError_InvalidProcname 6
swRunMacroError_InvalidPropertyType 7
swRunMacroError_MacrosAreDisabled 2
swRunMacroError_NoPermission 23
swRunMacroError_NotInDesignMode 3
swRunMacroError_OnlyCodeModules 4
swRunMacroError_OpenFileFailed 28
swRunMacroError_OutOfMemory 5
swRunMacroError_Overflow 13
swRunMacroError_ParmNotOptional 15
swRunMacroError_Reverted 24
swRunMacroError_SuborfuncExpected 8
swRunMacroError_TooManyOpenFiles 25
swRunMacroError_TypeMismatch 14
swRunMacroError_UnknownLcid 16
swRunMacroError_UserInterrupt 11
swRunMacroError_Zombied 21
*/
switch (errorCount)
{
case (int)swRunMacroError_e.swRunMacroError_BadParmCount:
return "参数数量错误";
case (int)swRunMacroError_e.swRunMacroError_BadVarType:
return "变量类型错误";
case (int)swRunMacroError_e.swRunMacroError_Busy:
return "SolidWorks繁忙请稍后再试";
case (int)swRunMacroError_e.swRunMacroError_CallFailed:
return "调用失败";
case (int)swRunMacroError_e.swRunMacroError_CallRejected:
return "调用被拒绝";
case (int)swRunMacroError_e.swRunMacroError_CantSave:
return "无法保存";
case (int)swRunMacroError_e.swRunMacroError_ConnectionTerminated:
return "连接终止";
case (int)swRunMacroError_e.swRunMacroError_DiskError:
return "磁盘错误";
case (int)swRunMacroError_e.swRunMacroError_Exception:
return "异常";
case (int)swRunMacroError_e.swRunMacroError_InvalidArg:
return "无效参数";
case (int)swRunMacroError_e.swRunMacroError_Invalidindex:
return "无效索引";
case (int)swRunMacroError_e.swRunMacroError_InvalidProcname:
return "无效过程名";
case (int)swRunMacroError_e.swRunMacroError_InvalidPropertyType:
return "无效属性类型";
case (int)swRunMacroError_e.swRunMacroError_MacrosAreDisabled:
return "宏被禁用";
case (int)swRunMacroError_e.swRunMacroError_NoPermission:
return "无权限";
case (int)swRunMacroError_e.swRunMacroError_NotInDesignMode:
return "不在设计模式";
case (int)swRunMacroError_e.swRunMacroError_OnlyCodeModules:
return "仅代码模块";
case (int)swRunMacroError_e.swRunMacroError_OpenFileFailed:
return "打开文件失败";
case (int)swRunMacroError_e.swRunMacroError_OutOfMemory:
return "内存不足";
case (int)swRunMacroError_e.swRunMacroError_Overflow:
return "溢出";
case (int)swRunMacroError_e.swRunMacroError_ParmNotOptional:
return "参数不可选";
case (int)swRunMacroError_e.swRunMacroError_Reverted:
return "已还原";
case (int)swRunMacroError_e.swRunMacroError_SuborfuncExpected:
return "子或函数预期";
case (int)swRunMacroError_e.swRunMacroError_TooManyOpenFiles:
return "打开文件过多";
case (int)swRunMacroError_e.swRunMacroError_TypeMismatch:
return "类型不匹配";
case (int)swRunMacroError_e.swRunMacroError_UnknownLcid:
return "未知LCID";
case (int)swRunMacroError_e.swRunMacroError_UserInterrupt:
return "用户中断";
case (int)swRunMacroError_e.swRunMacroError_Zombied:
return "僵尸";
default:
return "未知错误";
}
}
return "执行成功";
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
#endregion
}

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{27AAE225-5B43-4E08-A5D5-4B2108E53523}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AutoSW.Agent</RootNamespace>
<AssemblyName>AutoSW.Agent</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<LangVersion>12.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SolidWorks.Interop.sldworks">
<HintPath>..\lib\SolidWorks.Interop.sldworks.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swcommands">
<HintPath>..\lib\SolidWorks.Interop.swcommands.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swconst">
<HintPath>..\lib\SolidWorks.Interop.swconst.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swdimxpert">
<HintPath>..\lib\SolidWorks.Interop.swdimxpert.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swdocumentmgr">
<HintPath>..\lib\SolidWorks.Interop.swdocumentmgr.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="solidworks.interop.swpublished">
<HintPath>..\lib\solidworks.interop.swpublished.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="solidworkstools">
<HintPath>..\lib\solidworkstools.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AgentExecutor.cs" />
<Compile Include="AIFuncAttribute.cs" />
<Compile Include="Enum\FileType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SWFunctions.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI">
<Version>9.3.0-preview.1.25114.11</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AntdUI\src\AntdUI\AntdUI.csproj">
<Project>{3B833B9B-654C-1404-DC46-374BC4D37160}</Project>
<Name>AntdUI</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,17 @@
/**
* Copyright (C) DCIS
* FileType类型
* LiuJiao 2010-05-23
**/
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoSW.Agent.Enum
{
public enum FileType
{
Part, Assembly, Drawing, SheetMetal, Other
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AutoSW.Agent")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoSW.Agent")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("27aae225-5b43-4e08-a5d5-4b2108e53523")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D126D2A6-3023-4C8F-A810-50A27B747C33}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AutoSW.UI</RootNamespace>
<AssemblyName>AutoSW.UI</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<LangVersion>12.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AntdUI, Version=1.8.9.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\AntdUI\src\AntdUI\bin\Debug\net48\AntdUI.dll</HintPath>
</Reference>
<Reference Include="SolidWorks.Interop.swdimxpert">
<HintPath>..\lib\SolidWorks.Interop.swdimxpert.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
<Compile Include="UIEntry.cs" />
<Compile Include="Util\ChatClient.cs" />
<Compile Include="Util\PromptUtil.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI">
<Version>9.3.0-preview.1.25114.11</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.AI.Ollama">
<Version>9.3.0-preview.1.25114.11</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.AI.OpenAI">
<Version>9.3.0-preview.1.25114.11</Version>
</PackageReference>
<PackageReference Include="OpenAI">
<Version>2.2.0-beta.2</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>9.0.2</Version>
</PackageReference>
<PackageReference Include="Xarial.XCad">
<Version>0.8.1</Version>
</PackageReference>
<PackageReference Include="Xarial.XCad.SolidWorks">
<Version>0.8.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutoSW.Agent\AutoSW.Agent.csproj">
<Project>{27AAE225-5B43-4E08-A5D5-4B2108E53523}</Project>
<Name>AutoSW.Agent</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

172
src/AutoSW.UI/MainForm.Designer.cs generated Normal file
View File

@ -0,0 +1,172 @@
namespace AutoSW.UI
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
AntdUI.Tabs.StyleLine styleLine1 = new AntdUI.Tabs.StyleLine();
this.UserQuestionInput = new AntdUI.Input();
this.UseFuncCall = new AntdUI.Checkbox();
this.ModelList = new AntdUI.Select();
this.sendBtn = new AntdUI.Button();
this.MessageList = new AntdUI.Chat.ChatList();
this.MainTabs = new AntdUI.Tabs();
this.MsgListPage = new AntdUI.TabPage();
this.TestTabPage = new AntdUI.TabPage();
this.GetDrwInfoBtn = new AntdUI.Button();
this.MainTabs.SuspendLayout();
this.MsgListPage.SuspendLayout();
this.TestTabPage.SuspendLayout();
this.SuspendLayout();
//
// UserQuestionInput
//
this.UserQuestionInput.AllowClear = true;
this.UserQuestionInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.UserQuestionInput.Location = new System.Drawing.Point(-3, 659);
this.UserQuestionInput.Multiline = true;
this.UserQuestionInput.Name = "UserQuestionInput";
this.UserQuestionInput.Size = new System.Drawing.Size(350, 76);
this.UserQuestionInput.TabIndex = 4;
//
// UseFuncCall
//
this.UseFuncCall.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.UseFuncCall.BackColor = System.Drawing.Color.Transparent;
this.UseFuncCall.Location = new System.Drawing.Point(156, 744);
this.UseFuncCall.Name = "UseFuncCall";
this.UseFuncCall.Size = new System.Drawing.Size(75, 23);
this.UseFuncCall.TabIndex = 4;
this.UseFuncCall.Text = "识别图纸";
this.UseFuncCall.CheckedChanged += new AntdUI.BoolEventHandler(this.UseFuncCall_CheckedChanged);
//
// ModelList
//
this.ModelList.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ModelList.List = true;
this.ModelList.Location = new System.Drawing.Point(0, 735);
this.ModelList.Name = "ModelList";
this.ModelList.Placement = AntdUI.TAlignFrom.TL;
this.ModelList.Size = new System.Drawing.Size(150, 38);
this.ModelList.TabIndex = 3;
//
// sendBtn
//
this.sendBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.sendBtn.Location = new System.Drawing.Point(272, 735);
this.sendBtn.Name = "sendBtn";
this.sendBtn.Size = new System.Drawing.Size(75, 38);
this.sendBtn.TabIndex = 1;
this.sendBtn.Text = "发送";
this.sendBtn.Click += new System.EventHandler(this.sendBtn_Click);
//
// MessageList
//
this.MessageList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.MessageList.Location = new System.Drawing.Point(-3, 3);
this.MessageList.Name = "MessageList";
this.MessageList.Size = new System.Drawing.Size(349, 647);
this.MessageList.TabIndex = 3;
//
// MainTabs
//
this.MainTabs.BackColor = System.Drawing.SystemColors.Control;
this.MainTabs.Cursor = System.Windows.Forms.Cursors.Default;
this.MainTabs.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainTabs.Location = new System.Drawing.Point(0, 0);
this.MainTabs.Name = "MainTabs";
this.MainTabs.Pages.Add(this.MsgListPage);
this.MainTabs.Pages.Add(this.TestTabPage);
this.MainTabs.SelectedIndex = 1;
this.MainTabs.Size = new System.Drawing.Size(350, 798);
this.MainTabs.Style = styleLine1;
this.MainTabs.TabIndex = 4;
//
// MsgListPage
//
this.MsgListPage.Controls.Add(this.sendBtn);
this.MsgListPage.Controls.Add(this.UseFuncCall);
this.MsgListPage.Controls.Add(this.UserQuestionInput);
this.MsgListPage.Controls.Add(this.ModelList);
this.MsgListPage.Controls.Add(this.MessageList);
this.MsgListPage.Location = new System.Drawing.Point(-344, -770);
this.MsgListPage.Name = "MsgListPage";
this.MsgListPage.Size = new System.Drawing.Size(344, 770);
this.MsgListPage.TabIndex = 0;
this.MsgListPage.Text = "AutoSW";
//
// TestTabPage
//
this.TestTabPage.Controls.Add(this.GetDrwInfoBtn);
this.TestTabPage.Location = new System.Drawing.Point(3, 25);
this.TestTabPage.Name = "TestTabPage";
this.TestTabPage.Size = new System.Drawing.Size(344, 770);
this.TestTabPage.TabIndex = 1;
this.TestTabPage.Text = "Test";
//
// GetDrwInfoBtn
//
this.GetDrwInfoBtn.Location = new System.Drawing.Point(9, 14);
this.GetDrwInfoBtn.Name = "GetDrwInfoBtn";
this.GetDrwInfoBtn.Size = new System.Drawing.Size(105, 23);
this.GetDrwInfoBtn.TabIndex = 0;
this.GetDrwInfoBtn.Text = "GetDrwInfo";
this.GetDrwInfoBtn.Click += new System.EventHandler(this.GetDrwInfoBtn_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(350, 798);
this.ControlBox = false;
this.Controls.Add(this.MainTabs);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MinimumSize = new System.Drawing.Size(350, 0);
this.Name = "MainForm";
this.MainTabs.ResumeLayout(false);
this.MsgListPage.ResumeLayout(false);
this.TestTabPage.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private AntdUI.Button sendBtn;
private AntdUI.Chat.ChatList MessageList;
private AntdUI.Select ModelList;
private AntdUI.Checkbox UseFuncCall;
private AntdUI.Input UserQuestionInput;
private AntdUI.Tabs MainTabs;
private AntdUI.TabPage MsgListPage;
private AntdUI.TabPage TestTabPage;
private AntdUI.Button GetDrwInfoBtn;
}
}

224
src/AutoSW.UI/MainForm.cs Normal file
View File

@ -0,0 +1,224 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using AntdUI;
using AntdUI.Chat;
using AutoSW.Agent;
using AutoSW.UI.Util;
using Microsoft.Extensions.AI;
using static AntdUI.Tour;
namespace AutoSW.UI
{
public partial class MainForm: BaseForm
{
public static MainForm MainFormIns;
public MainForm()
{
InitializeComponent();
UIInit();
MainFormIns = this;
}
private Dictionary<string, string> Models = new Dictionary<string, string>
{
//{"火山-DeepSeek-V3","deepseek-v3-241226" },
{"火山-豆包-1.5-Pro","doubao-1-5-pro-32k-250115"}
};
private void UIInit()
{
MessageList.ChatItemContextMenus.Add(new ContextMenuStripItem("复制"));
//MessageList.ChatItemContextMenus.Add(new ContextMenuStripItem("删除"));
MessageList.ChatItemContextMenus.Add(new ContextMenuStripItem("重发"));
MessageList.ChatItemContextMenuClick += MessageList_ChatItemContextMenuClick;
UserQuestionInput.HandShortcutKeys = true;
UserQuestionInput.KeyDown += UserQuestionInput_KeyDown;
ModelList.Items = [.. Models.Keys];
ModelList.SelectedIndex = 0;
ModelList.Text = ModelList.Items[0].ToString();
}
private void UserQuestionInput_KeyDown(object sender, KeyEventArgs e)
{
System.Windows.Forms.Message msg = new();
UserQuestionInput.IProcessCmdKey(ref msg, e.KeyData);
}
private void MessageList_ChatItemContextMenuClick(object sender, ChatItemMenuEventArgs e)
{
switch (e.Menu.Text)
{
case "复制":
{
if (e.Item is TextChatItem item)
{
Clipboard.SetText(item.Text);
}
}
break;
//case "删除":
// MessageList.(e.ChatItem);
//break;
case "重发":
{
if (e.Item is TextChatItem item)
{
//Clipboard.SetText(item.Text);
UserQuestionInput.Text = item.Text;
sendBtn.PerformClick();
}
}
break;
default:
break;
}
}
private void sendBtn_Click(object sender, EventArgs e)
{
// chatList.AddToBottom(new AntdUI.Chat.TextChatItem("阿威十八式 🙌🖖🤘👋", Properties.Resources.head, "AduSkin"));
//Thread.Sleep(700);
// chatList.AddToBottom(new AntdUI.Chat.TextChatItem("搭配 Nuget Tom.HttpLib 可以轻松实现GPT流式传输\n\nhttps://gitee.com/EVA-SS/HttpLib", Properties.Resources.head, "Tom") { Me = true });
var question = UserQuestionInput.Text;
var modelName = ModelList.Text;
if (string.IsNullOrEmpty(question))
{
return;
}
else
{
UserQuestionInput.Clear();
}
Task.Run(async () =>
{
var questionPrompt = PromptUtil.GetPrompt(question);
Bitmap dsIcon = null;
Bitmap userIcon = null;
using (var ms = new MemoryStream(Resource.mainicon_128))
{
userIcon = new Bitmap(ms);
}
MessageList.AddToBottom(new AntdUI.Chat.TextChatItem(question, userIcon) { Me = true });
MessageList.ToBottom();
var modelId = Models[modelName];
if (modelName.Contains("豆包") || modelName.Contains("doubao"))
{
using var ms = new MemoryStream(Resource.doubao);
dsIcon = new Bitmap(ms);
}
else
{
using var ms = new MemoryStream(Resource.ds);
dsIcon = new Bitmap(ms);
}
var chatItem = new AntdUI.Chat.TextChatItem("正在思考中...", dsIcon, modelName);
var isBut = MessageList.AddToBottom(chatItem);
if (isBut)
{
MessageList.ToBottom();
}
try
{
//var isFirstRec = true;
//var chatClient = new ChatClient(modelName);
//// 订阅消息接收事件
//chatClient.OnMessageReceived += (s, message) =>
//{
// // 处理接收到的消息片段
// if (isBut)
// {
// MessageList.ToBottom();
// }
// if (isFirstRec)
// {
// chatItem.Text = "";
// isFirstRec = false;
// }
// chatItem.Text += message;
//};
//// 开始流式对话
var isFirstRec = true;
ChatClient chatClient;
if (modelName.StartsWith("火山"))
{
chatClient = new ChatClient(modelId, false);
chatClient.UseOpenAI();
}
else
{
chatClient = new ChatClient(modelName);
}
await foreach (var result in chatClient.GetStreamingResponseAsync(questionPrompt))
{
MessageList.ToBottom();
if (isFirstRec)
{
chatItem.Text = "";
isFirstRec = false;
}
chatItem.Text += result;
}
//IChatClient client = new OllamaChatClient(new Uri("http://localhost:11434/"), "deepseek-r1:1.5b");
//await foreach (var update in client.GetStreamingResponseAsync("What is AI?"))
//{
// chatItem.Text += update;
//}
}
catch (Exception ex)
{
chatItem.Text = ex.ToString();
}
});
}
private void UseFuncCall_CheckedChanged(object sender, BoolEventArgs e)
{
}
private void GetDrwInfoBtn_Click(object sender, EventArgs e)
{
try
{
var info = AgentExecutor.GetDrwInfo();
MessageBox.Show(info);
Debug.WriteLine(info);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

120
src/AutoSW.UI/MainForm.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AutoSW.UI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoSW.UI")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("d126d2a6-3023-4c8f-a810-50a27b747c33")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

93
src/AutoSW.UI/Resource.Designer.cs generated Normal file
View File

@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace AutoSW.UI {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutoSW.UI.Resource", typeof(Resource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] doubao {
get {
object obj = ResourceManager.GetObject("doubao", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] ds {
get {
object obj = ResourceManager.GetObject("ds", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] mainicon_128 {
get {
object obj = ResourceManager.GetObject("mainicon_128", resourceCulture);
return ((byte[])(obj));
}
}
}
}

130
src/AutoSW.UI/Resource.resx Normal file
View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="doubao" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\doubao.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ds" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\ds.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="mainicon_128" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\mainicon_128.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

17
src/AutoSW.UI/UIEntry.cs Normal file
View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutoSW.UI
{
public class UIEntry
{
public static void Init()
{
Debug.WriteLine("UIEntry init");
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.ClientModel;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using AutoSW.Agent;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Chat;
namespace AutoSW.UI.Util
{
internal class ChatClient
{
/// <summary>
/// 火山方舟API Key
/// </summary>
private readonly string API_KEY = "58e5c6fd-a5da-400e-b889-715febce478f";
private readonly string OLLAMA_ENDPOINT = "http://localhost:11434/";
private readonly string API_ENDPOINT = "https://ark.cn-beijing.volces.com/api/v3/";
private string MODEL;
private readonly IChatClient _client;
private bool useOpenAIClient;
private OpenAIClient _openAICLient;
public ChatClient(string modelName = "deepseek-r1:1.5b", bool useOllama = true)
{
//MODEL = modelName;
//var apiKeyCredential = new ApiKeyCredential(API_KEY);
//var openAIClientOptions = new OpenAIClientOptions
//{
// Endpoint = new Uri(ENDPOINT)
//};
//_client = new OpenAIClient(apiKeyCredential, openAIClientOptions)
// .AsChatClient(MODEL);
if (useOllama)
{
var client = new OllamaChatClient(new Uri(OLLAMA_ENDPOINT), modelName);
_client = new ChatClientBuilder(client)
.UseFunctionInvocation()
.Build();
}
else
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var client = new OpenAIClient(new ApiKeyCredential(API_KEY), new OpenAIClientOptions
{
Endpoint = new Uri(API_ENDPOINT),
});
_client = client.AsChatClient(modelName);
}
}
public IChatClient Client => _client;
public async Task<string> GetChatResponseAsync(string question)
{
var response = await _client.GetResponseAsync(question);
return response.Message.ToString();
}
public async IAsyncEnumerable<string> GetStreamingResponseAsync(string question)
{
// 获取所有的工具函数
var toolsList = AgentExecutor.GetDefaultTools();
var chatOptions = new ChatOptions
{
Tools = toolsList,
ToolMode = ChatToolMode.Auto,
};
if (useOpenAIClient)
{
var chatClient = _openAICLient.AsChatClient("doubao-1-5-pro-32k-250115")
.AsBuilder()
.UseFunctionInvocation()
.Build();
var response = chatClient.GetResponseAsync(question, chatOptions);
yield return response.Result.Choices[0].Text;
}
else
{
await foreach (var response in _client.GetStreamingResponseAsync(question, chatOptions))
{
yield return response.Text;
}
}
}
public void UseOpenAI()
{
useOpenAIClient = true;
_openAICLient = new OpenAIClient(new ApiKeyCredential(API_KEY), new OpenAIClientOptions
{
Endpoint = new Uri(API_ENDPOINT)
});
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutoSW.UI.Util;
internal class PromptUtil
{
public static string GetPrompt(string question)
{
var prompt = $@"
- {DateTime.Now},{DateTime.Now.DayOfWeek}
- SolidWorks软件中2016SolidWorks的技巧
- 使
- ,使
- SolidWorksVBA宏使便
- VBA宏脚本
-
- {question}
";
return prompt;
}
}

43
src/AutoSW.sln Normal file
View File

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35806.99
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoSW", "AutoSW\AutoSW.csproj", "{B5013BE5-2752-49D7-AB2B-771414F9B6AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoSW.Agent", "AutoSW.Agent\AutoSW.Agent.csproj", "{27AAE225-5B43-4E08-A5D5-4B2108E53523}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoSW.UI", "AutoSW.UI\AutoSW.UI.csproj", "{D126D2A6-3023-4C8F-A810-50A27B747C33}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntdUI", "..\..\AntdUI\src\AntdUI\AntdUI.csproj", "{3B833B9B-654C-1404-DC46-374BC4D37160}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B5013BE5-2752-49D7-AB2B-771414F9B6AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5013BE5-2752-49D7-AB2B-771414F9B6AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5013BE5-2752-49D7-AB2B-771414F9B6AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5013BE5-2752-49D7-AB2B-771414F9B6AD}.Release|Any CPU.Build.0 = Release|Any CPU
{27AAE225-5B43-4E08-A5D5-4B2108E53523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27AAE225-5B43-4E08-A5D5-4B2108E53523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27AAE225-5B43-4E08-A5D5-4B2108E53523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27AAE225-5B43-4E08-A5D5-4B2108E53523}.Release|Any CPU.Build.0 = Release|Any CPU
{D126D2A6-3023-4C8F-A810-50A27B747C33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D126D2A6-3023-4C8F-A810-50A27B747C33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D126D2A6-3023-4C8F-A810-50A27B747C33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D126D2A6-3023-4C8F-A810-50A27B747C33}.Release|Any CPU.Build.0 = Release|Any CPU
{3B833B9B-654C-1404-DC46-374BC4D37160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B833B9B-654C-1404-DC46-374BC4D37160}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B833B9B-654C-1404-DC46-374BC4D37160}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B833B9B-654C-1404-DC46-374BC4D37160}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {857E2370-5BFC-46CF-B7EF-F5DA3B58D7FD}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,71 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
namespace AutoSW
{
public class AppDomainDllLoader
{
public static bool isLoaded = false;
public static void SetLaoder()
{
if (isLoaded)
{
return;
}
// 接管DLL加载,解决依赖问题
// 插件被加载时,AppContext.BaseDirectory 会指向Eplan的安装目录,导致一部分依赖的DLL在加载时找不到
// 接管之后,从两个目录都查找一次
//throw new NotImplementedException();
try
{
// 防止重复加载 先卸载事件
AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolveHandle;
}
catch (Exception ex)
{
Trace.TraceError(ex.Message);
}
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandle;
isLoaded = true;
}
public static Assembly AssemblyResolveHandle(object sender, ResolveEventArgs args)
{
var assemblyName = new AssemblyName(args.Name);
// 判断是否已经被加载
var loadedAssembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.FullName == assemblyName.FullName);
if (loadedAssembly != null)
{
Debug.WriteLine($"DLL is loaded -> {loadedAssembly.FullName}");
return loadedAssembly;
}
// 从当前路径下加载
var path = Path.Combine(AppContext.BaseDirectory, $"{assemblyName.Name}.dll");
if (File.Exists(path))
{
Debug.WriteLine($"Load dll for path -> {path}");
return Assembly.LoadFile(path);
}
var envPath = System.Environment.CurrentDirectory;
// 从插件路径中加载依赖
path = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(AppDomainDllLoader)).Location), $"{assemblyName.Name}.dll");
if (File.Exists(path))
{
//MessageBox.Show($"Load dll for self path -> {path}");
Debug.WriteLine($"Load dll for self path -> {path}");
return Assembly.LoadFile(path);
}
//MessageBox.Show(path);
Debug.WriteLine($"File not load! -> {path}");
return null;
}
}
}

114
src/AutoSW/AutoSW.csproj Normal file
View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B5013BE5-2752-49D7-AB2B-771414F9B6AD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AutoSW</RootNamespace>
<AssemblyName>AutoSW</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\AutoSW_bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\AutoSW_bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>AutoSWKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="SolidWorks.Interop.sldworks">
<HintPath>..\lib\SolidWorks.Interop.sldworks.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swcommands">
<HintPath>..\lib\SolidWorks.Interop.swcommands.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swconst">
<HintPath>..\lib\SolidWorks.Interop.swconst.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="SolidWorks.Interop.swdocumentmgr">
<HintPath>..\lib\SolidWorks.Interop.swdocumentmgr.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="solidworks.interop.swpublished">
<HintPath>..\lib\solidworks.interop.swpublished.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="solidworkstools, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bd18593873b4686d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\solidworkstools.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppDomainDllLoader.cs" />
<Compile Include="PluginEntry.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="AutoSWKey.snk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AntdUI\src\AntdUI\AntdUI.csproj">
<Project>{3b833b9b-654c-1404-dc46-374bc4d37160}</Project>
<Name>AntdUI</Name>
</ProjectReference>
<ProjectReference Include="..\AutoSW.Agent\AutoSW.Agent.csproj">
<Project>{27AAE225-5B43-4E08-A5D5-4B2108E53523}</Project>
<Name>AutoSW.Agent</Name>
</ProjectReference>
<ProjectReference Include="..\AutoSW.UI\AutoSW.UI.csproj">
<Project>{D126D2A6-3023-4C8F-A810-50A27B747C33}</Project>
<Name>AutoSW.UI</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="assest\edit32.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if $(ConfigurationName)==Debug (
$(SolutionDir)lib\RegAsm.exe /codebase $(TargetPath)
)</PostBuildEvent>
</PropertyGroup>
</Project>

BIN
src/AutoSW/AutoSWKey.snk Normal file

Binary file not shown.

128
src/AutoSW/PluginEntry.cs Normal file
View File

@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Shapes;
using AutoSW.Agent;
using AutoSW.UI;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swpublished;
using SolidWorksTools;
namespace AutoSW
{
[Guid("2DCEBF76-EA1A-487D-A963-F8ED3EDBCBC4")]
[SwAddinAttribute(
Description = "Solidworks Ai 自动化",
Title = "Solidworks-Ai",
LoadAtStartup = true
)]
[ComVisible(true)]
public class PluginEntry : SwAddin
{
private SldWorks iSwApp;
private TaskpaneView swTaskPane;
private Form taskForm;
public bool ConnectToSW(object ThisSW, int Cookie)
{
iSwApp = ThisSW as SldWorks;
#region UI init
AppDomainDllLoader.SetLaoder();
UIEntry.Init();
AddUIPane();
#endregion
#region Agent Init
AgentExecutor.Init(iSwApp);
#endregion
return true;
}
private void AddUIPane()
{
if (swTaskPane != null)
{
swTaskPane.DeleteView();
Marshal.FinalReleaseComObject(swTaskPane);
swTaskPane = null;
}
var dllpath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
dllpath = dllpath.Substring(8, dllpath.Length - 8);
dllpath = System.IO.Path.GetDirectoryName(dllpath);
var imagePath = System.IO.Path.Combine(dllpath, "assest","edit32.bmp");
swTaskPane = (TaskpaneView)iSwApp.CreateTaskpaneView2(imagePath, "AutoSW");
taskForm = new MainForm()
{
Dock = DockStyle.Fill
};
swTaskPane.DisplayWindowFromHandlex64(taskForm.Handle.ToInt64());
swTaskPane.HideView();
}
public bool DisconnectFromSW()
{
return true;
}
#region SolidWorks Registration
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Console.WriteLine(t.ToString());
#region Get Custom Attribute: SwAddinAttribute
SwAddinAttribute SWattr = null;
foreach (var attr in t.GetCustomAttributes(false))
{
Console.WriteLine(attr.ToString() ?? "NULL");
if (attr is SwAddinAttribute)
{
SWattr = attr as SwAddinAttribute;
break;
}
}
Console.WriteLine($"SWattr is {SWattr?.ToString() ?? "NULL"}");
#endregion
var hklm = Microsoft.Win32.Registry.LocalMachine;
var hkcu = Microsoft.Win32.Registry.CurrentUser;
var keyname = "SOFTWARE\\SolidWorks\\Addins\\{" + t.GUID.ToString() + "}";
Console.WriteLine(keyname);
var addinkey = hklm.CreateSubKey(keyname);
if (addinkey != null)
{
addinkey.SetValue(null, 0);
addinkey.SetValue("Description", SWattr?.Description ?? "Solidworks Ai 自动化");
addinkey.SetValue("Title", SWattr?.Title ?? "Solidworks-Ai");
}
keyname = "Software\\SolidWorks\\AddInsStartup\\{" + t.GUID.ToString() + "}";
addinkey = hkcu.CreateSubKey(keyname);
addinkey.SetValue(null, Convert.ToInt32(SWattr?.LoadAtStartup ?? true), Microsoft.Win32.RegistryValueKind.DWord);
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
var hklm = Microsoft.Win32.Registry.LocalMachine;
var hkcu = Microsoft.Win32.Registry.CurrentUser;
var keyname = "SOFTWARE\\SolidWorks\\Addins\\{" + t.GUID.ToString() + "}";
hklm.DeleteSubKey(keyname);
keyname = "Software\\SolidWorks\\AddInsStartup\\{" + t.GUID.ToString() + "}";
hkcu.DeleteSubKey(keyname);
}
#endregion
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AutoSW")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoSW")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(true)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("b5013be5-2752-49d7-ab2b-771414f9b6ad")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

BIN
src/lib/RegAsm.exe Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
src/lib/solidworkstools.dll Normal file

Binary file not shown.