- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我目前正在开发一个新的 Solidworks 任务 Pane ,主要是实现一些我以更方便的格式编写的“旧”宏。其中一些需要用户通过文本框输入,我想将其包含在任务 Pane 中。
问题是,我找不到编写临时文件或将这些字符串导入我的宏的方法(我不想花时间重写)
有没有其他方法可以将这些字符串发送到我的宏?插件在 C# 中,我目前正在使用 Solidworks“RunMacro2”方法。
谢谢!
编辑: 在下面添加一些代码片段。有问题的主要宏旨在在整个程序集中传播自定义属性文件。
namespace Efficiency_Interface
{
[ComVisible(true)]
[ProgId(ProjMan_Tab_PROGID)]
public partial class Project_Management_Tab : UserControl
{
SwAddin SolidRun = new SwAddin();
public const string ProjMan_Tab_PROGID = "Proj Management";
public const string scratchFile = "C:\\keyStoneAddinScratch.txt";
StreamWriter writeText = new StreamWriter(scratchFile);
public Project_Management_Tab()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (var textBox in this.Controls.OfType<TextBox>())
{
writeText.WriteLine(textBox.Text);
}
writeText.Close();
SolidRun.runGen("proc");
}
}
}
以上是我的任务 Pane 的基本代码。下面是我的主要插件类的代码片段,它还包含我的其他按钮之一的代码。
public void runCreate4Pack()
{
iSwApp.RunMacro2(macroPath + "CREATE 4 SIZE PACKAGE.swp", "", "", 0, out runMacroError);
return;
}
public void runGen(string procName)
{
iSwApp.RunMacro2(macroPath + "Efficiency Interface.swp", "hitButton", procName, 0, out runMacroError);
File.Delete("C:\\Users\\Public\\keyStoneAddinScratch.txt");
return;
}
最后,是我尝试与之交互的宏的主要代码。
Private Sub fillProps_Click()
Dim doneParts() As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set part = swApp.ActiveDoc
If firstAssem = "" Then
referenceList (0)
End If
i = 0
ReDim Preserve doneParts(1)
Set custPropMgr = part.Extension.CustomPropertyManager(part.GetActiveConfiguration.name)
setProps "", "", ""
While i <= 1000 And Not assemComps(i, j) = ""
parentAssemNum = Left(assemComps(i, 0), InStrRev(assemComps(i, 0), ".") - 1)
parentAssemDesc = assemComps(i, 1)
j = 2
While j <= 10000 And Not assemComps(i, j) = ""
k = 0
While k < UBound(doneParts())
If doneParts(k) = assemComps(i, j) Then
GoTo skipEntry
End If
k = k + 1
Wend
Set part = swApp.ActivateDoc3(assemComps(i, j), True, 1, 1)
If part.GetType = 1 Then
Set swpartdoc = part
End If
If InStr(part.IGetActiveConfiguration.name, "Default") > 0 Then
Set custPropMgr = part.Extension.CustomPropertyManager("")
End If
Debug.Print custPropMgr.Get("Description")
setProps parentAssemNum + "", parentAssemDesc + "", ""
ReDim Preserve doneParts(UBound(doneParts) + 1)
doneParts(UBound(doneParts)) = assemComps(i, j)
If i > 0 Or j > 0 Then
swApp.QuitDoc (assemComps(i, j))
End If
skipEntry:
j = j + 1
Wend
i = i + 1
Wend
End Sub
Sub setProps(parentAssemNum As String, parentAssemDesc As String, stockSize As String)
If custPropMgr.Get("StockSize") = "" Then
If part.GetType = swDocPART Then
If swpartdoc.IsWeldment = False Then
Dim sizeArray(2)
vboundbox = swpartdoc.GetPartBox(False)
size1 = Round(Abs(vboundbox(0) - vboundbox(3)), 2)
size2 = Round(Abs(vboundbox(1) - vboundbox(4)), 2)
size3 = Round(Abs(vboundbox(2) - vboundbox(5)), 2)
sizeArray(0) = size1
sizeArray(1) = size2
sizeArray(2) = size3
rectVol = size1 * size2 * size3
Set swmass = part.Extension.CreateMassProperty
swmass.UseSystemUnits = False
swVol = swmass.Volume
QuickSort sizeArray, LBound(sizeArray), UBound(sizeArray)
eq = 0
If size1 = size2 Then
eq = 1
cylVol = 3.14159 * ((size1 / 2) * (size1 / 2)) * size3
End If
If size1 = size3 Then
eq = 1
cylVol = 3.14159 * ((size1 / 2) * (size1 / 2)) * size2
End If
If size3 = size2 Then
eq = 1
cylVol = 3.14159 * ((size2 / 2) * (size2 / 2)) * size1
End If
If eq = 1 Then
If Abs(swVol - cylVol) < Abs(swVol - rectVol) Then
boolstatus = custPropMgr.Set("StockSize", "ROUND BAR, " & size2 & " OD X " & size3 & "LG")
End If
If Abs(swVol - rectVol) < Abs(swVol - cylVol) Then
'If size3 > size2 Then
boolstatus = custPropMgr.Set("StockSize", size2 & " SQ X " & size3 & "LG")
'End If
'If size3 < size2 Then
' boolstatus = custPropMgr.Set("StockSize", "PLATE," & size2 & " SQ X " & size3 & "LG")
'End If
End If
If Abs(swVol - cylVol) = Abs(swVol - rectVol) Then
'If size3 > size2 Then
boolstatus = custPropMgr.Set("StockSize", "BAR, " & size2 & " X " & size3 & "LG")
'End If
'If size3 < size2 Then
' boolstatus = custPropMgr.Set("StockSize", "PLATE," & size2 & " SQ X " & size3 & "LG")
'End If
End If
End If
If eq = 0 Then
boolstatus = custPropMgr.Set("StockSize", sizeArray(2) & " X " & sizeArray(1) & " X " & sizeArray(0))
End If
End If
End If
End If
If Len(custPropMgr.Get("DATE")) = 0 Then
boolstatus = custPropMgr.Set("Date", Left(Now, InStrRev(Now, "/") + 4))
End If
boolstatus = custPropMgr.Set("Workorder", Interface.workorder.Text)
boolstatus = custPropMgr.Set("Plant", Interface.plantBox.Text)
boolstatus = custPropMgr.Set("AssemblyNumber", parentAssemNum)
boolstatus = custPropMgr.Set("Line2", parentAssemDesc)
boolstatus = custPropMgr.Set("Line3", Interface.projBox.Text)
If Len(custPropMgr.Get("Finish")) = 0 Then
'boolstatus = custPropMgr.Set("Finish", Interface.finish.Text)
End If
If Len(custPropMgr.Get("DesignBy")) = 0 Then
'boolstatus = custPropMgr.Set("DesignBy", Interface.creator.Text)
End If
If Len(custPropMgr.Get("DrawnBy")) = 0 Then
'boolstatus = custPropMgr.Set("DrawnBy", Interface.creator.Text)
End If
End Sub
我确实希望这会有所帮助,并且不要太困惑。
最佳答案
Solidworks 支持两种类型的 VB 宏文件
swb - 较旧的纯文本宏,这里是空 swb 宏的示例:
Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
End Sub
如果您可以访问宏的源代码,您可以将它们转换为纯文本并保留占位符。
MsgBox "--MyParameter1--"
用户在任务 Pane 中填写参数后,用实际值替换 swb 宏中的占位符并运行它。
关于c# - Solidworks C# 插件 - 将字符串发送到宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33345908/
我在互联网上搜索了很多小时,但没有找到满意的结果,所以 -VSTO Addin 和 COM Addin(我们作为类库项目制作并使用 Excel 对象)之间有什么区别?VSTO 项目是否有任何限制,例如
我在互联网上搜索了很多小时,但没有找到满意的结果,所以 -VSTO Addin 和 COM Addin(我们作为类库项目制作并使用 Excel 对象)之间有什么区别?VSTO 项目是否有任何限制,例如
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我正在寻找有关如何构建可扩展 WCF 服务器(具有动态加载的服务)的建议,最好使用 System.Addins 或 MEF。 服务器应托管实现最小“插件”API(StartService/StopSe
有没有一种方法可以使用加载浏览器扩展/插件/插件的 headless 浏览器(即 PhantomJS、Selenium)来运行自动测试? 更具体地说,我想模拟广告拦截器(如 Ghostery、ad-b
我是 gradle 的新手,我使用 artifactory 作为我的 repo 服务器。我在网上查看了如何将我的项目发布到我的 repo 服务器,发现我可以使用 maven-publish 或使用 a
我想禁用某些状态的点击/事件,并仅使少数状态可点击。我通读了http://newsignature.github.io/us-map/处的文档,并且找不到与此问题相关的任何内容。 最佳答案 http:
据我了解,在Intellij中使用idea插件打开Maven构建的项目并不是最好的方法,即调用: mvn idea:idea 但是直接打开pom文件(Intellij有默认的Maven插件);同样的事
使用Artifactory plugin对于 Jenkins pipeline 来说是一种幸福,只要遵循文档就可以了。但后来我介绍了Maven Flatten plugin解析父模块和子模块 mvn
我已经安装了Elasticsearch版本1.7.1。一切正常。我也安装了 JDBC 驱动程序。检查下面我的插件文件夹 目录E:\Xampp\htdocs\my-elastic\elasticsear
在我使用 webpack common chunks 插件创建包含第三方库(如 angular、react、lodash 等)的 vendor 包之前,但后来我知道了 webpack dll
我们正在尝试使用(Jenkins、sonar、eclipse ...)安装 CI 平台。 为了让每个开发人员都可以在提交之前对他的代码进行分析,我想知道两种选择: 使用 Sonar 插件运行本地分析。
我知道这是一个比较特殊的问题。尽管如此,也许有些人知道这一点: 我想在 Eclipse 中使用 Maven 编译 Hector=> 分支:0.7.0 和标签:hector-0.7.0-29(https
我卡住了。我一直在尝试寻找或自己创建一个简单的准系统示例,说明如何为 VS 2010 Express 创建 Outlook 插件。我知道这在 VS 2010 Pro 中更简单,但是,在快速版本中真的不
我有以下排除过滤器来忽略所有 R 文件类: findbugs-exclude-filter.xml 当我将它用于 FindBugs-IDEA 插件时,它可以
我刚开始玩 CakePHP,我发现了 Wildflower CMS .我喜欢这个想法,并打算开始修补它。不过,我有一个问题。 在自述文件中,我发现了以下内容:“Wildflower 不是也不会是 Ca
虽然现在大部分情况都是使用n-api来编写插件,但是底层毕竟是v8(和libuv),使用v8编写简单的插件,同时熟悉v8的使用。 本文介绍在写c++插件时,简单又常用的写法,其实本质上,写插件
本篇是 Python 系列教程第 3 篇,更多内容敬请访问我的 Python 合集 Visual Studio Code的安装非常简单,就不放这里增加文章篇幅了。 相比PyCharm,V
Maven – 插件 什么是 Maven 插件? Maven 实际上是一个依赖插件执行的框架,每个任务实际上是由插件完成。Maven 插件通常被用来: 创建 jar 文件 创建 war
我正在编写一个插件来添加带有标签 [deposit_page] 的页面;该标记应替换为一些 PHP 代码。 这就是我所拥有的,但它不起作用。有什么我遗漏或做错了什么吗? function deposi
我是一名优秀的程序员,十分优秀!