创建C#工程
创建工程
1、创建C#的类库工程
2、设置工程适用x64或x86
右键点击解决方案,点击属性
3、选择代码优化
4、引入ZwmPEBridgePluginsLib 依赖库
书写代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Collections;
using System.Diagnostics;
namespace cadtest
{
[ComVisible(true)]
[Guid("31B711CA-308A-4C8E-B307-E42BB5BB84B9")]
[ProgId("ZwcadmPEB.LYH003")]
public class ClassZwTc : ZwmPEBridgePluginsLib.IProjectFrameworkAddin
{
public void CallBomMenuFunction(string bstrCommandName, string FileName, ref ZwmPEBridgePluginsLib.PETitleCollection ppPETitleCollection, ref ZwmPEBridgePluginsLib.PEBomCollections ppPEBomCollections, ref string bstrErrorMsg, ref int bSucceeded)
{
//读取
if (bstrCommandName == "readCommand")
{
//获得明细栏数据
ArrayList list_mx = new ArrayList();
for (int i = 0; i < ppPEBomCollections.Counts; i++)
{
var pBomCollection = ppPEBomCollections.GetItem(i + 1);
Dictionary<string, string> dicBom = new Dictionary<string, string>();
for (int j = 0; j < pBomCollection.Counts; j++)
{
var pBom = pBomCollection.GetItem(j + 1);
// MessageBox.Show("---pBom.BomName--:" + pBom.BomName +"--"+ " pBom.BomValue:" + pBom.BomValue+"---");
dicBom.Add(pBom.BomName, pBom.BomValue);
}
list_mx.Add(dicBom);
}
//获得标题栏的数据
Dictionary<string, string> dicTitle = new Dictionary<string, string>();
for (int i = 0; i < ppPETitleCollection.Counts; i++)
{
var pPETitle = ppPETitleCollection.GetItem(i + 1);
// MessageBox.Show("---PETitle.TitleName--:" + pPETitle.TitleName +"--"+ " pPETitle.TitleValue:" + pPETitle.TitleValue+"---");
dicTitle.Add(pPETitle.TitleName, pPETitle.TitleValue);
}
}
//写入
if (bstrCommandName == "writeCommand")
{
//明细表写入值
int count = ppPEBomCollections.Counts;
for (int i = 0; i < count; i++)
{
var pBomCollection = ppPEBomCollections.GetItem(i + 1);
for (int j = 0; j < pBomCollection.Counts; j++)
{
ZwmPEBridgePluginsLib.PEBom bom = pBomCollection.GetItem(j + 1);
//MessageBox.Show("---bom.name--:"+bom.BomName);
bom.BomValue = "想要设置的值";
}
}
}
}
public void CallTitleMenuFunction(string bstrCommandName, ref ZwmPEBridgePluginsLib.PETitleCollection ppPETitleCollection, string bstrFileName, ref string bstrErrorMsg, ref int bSucceeded)
{
throw new NotImplementedException();
}
}
}
生成dll
注册菜单
书写配置菜单xml文件
文件名为ZwmPEBridgePlugins.xml
<?xml version="1.0" encoding="gb2312"?>
<Style xmlns="http://www.knowthink.com/mechanical/Style" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.knowthink.com/mechanical/Style
../Zwmstyle.xsd">
<FrameworkAddins>
<FrameworkAddin Name="ZWPBE003" ProgId="ZwcadmPEB.LYH003" Load = "1">
<MenuStyles>
<MenuStyle Name="读取" Function="readCommand" IconPath="" Type="bom"/>
<MenuStyle Name="写入" Function="writeCommand" IconPath="" Type="bom"/>
</MenuStyles>
</FrameworkAddin>
</FrameworkAddins>
</Style>
书写注册bat
set SELFCD=%~dp0
:: 获取.net
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /t:cadtest.tlb "%SELFCD%\cadtest.dll" /Codebase
:: 判断系统
for /f "tokens=1* delims=[" %%a in ('ver') do set b=%%b
set b=%b:* =%
goto %b:~0,4%%PROCESSOR_ARCHITECTURE:~-1%
:5.1.6
echo xp_32位
set DOCFOLDER=%ALLUSERSPROFILE%\Documents\
goto next
:6.1.6
:6.1.4
:6.0.6
:6.0.4
:10.04
SET DOCFOLDER=%PUBLIC%\Documents\
goto next
:next
:: 样式文件夹名称,修改样式时修改此处
set STYLE_NAME=GB
set STYLE_FOLDER=%DOCFOLDER%ZWSOFT\ZWCADM\2019\zh-CN\Styles\%STYLE_NAME%
md "%STYLE_FOLDER%"
copy /Y ZwmPEBridgePlugins.xml "%STYLE_FOLDER%\"
pause
双击注册
将dll、bat和xml文件放在同一目录下,双击bat文件
tld文件是注册之后生成的