Solidworks自动取文件名后三位字符的方程式
时间: 2023-06-23 22:09:37 浏览: 195
在SolidWorks中,可以使用以下VB.NET代码获取文件名的后三个字符:
```
Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(Document.FullName)
Dim lastThreeCharacters As String = fileName.Substring(fileName.Length - 3)
```
这段代码首先获取当前文档的完整文件名(包括扩展名),然后使用`GetFileNameWithoutExtension`函数将其转换为不带扩展名的文件名。接下来,使用`Substring`函数从文件名末尾提取最后三个字符。
你可以将这段代码放在SolidWorks宏中,以便在需要时自动获取文件名后三个字符。
相关问题
Solidworks自动截取文件名后三位做为自定义属性的版本的属性值方程式
在 Solidworks 中,可以使用以下方程式来截取文件名后三位作为自定义属性的版本属性值:
```
=RIGHT(MID("@",FIND("~",SUBSTITUTE("@","\\","~",LEN("@")-LEN(SUBSTITUTE("@","\","")))))+1,3)
```
这个方程式的含义是,首先使用 SUBSTITUTE 函数将反斜杠(\)替换为波浪号(~),然后使用 LEN 函数计算出字符串中反斜杠的数量。接下来使用 MID 函数和 FIND 函数定位最后一个反斜杠,并将其替换为波浪号。最后使用 RIGHT 函数获取文件名的最后三个字符作为版本属性值。
将该方程式输入到自定义属性值的公式栏中即可。请注意,该方程式假定您的文件名中包含一个反斜杠,因此,如果您的文件名不包含反斜杠,则需要对方程式进行修改。
solidworks自动截取文件名后三位做为自定义属性的版本的属性值
可以通过SolidWorks的宏来实现自动截取文件名后三位做为自定义属性的版本的属性值。
以下是实现的步骤:
1. 打开SolidWorks,点击菜单栏上的“工具”->“宏”->“编辑”打开宏编辑器。
2. 在宏编辑器中,点击“新建”创建一个新的宏,然后命名为“AddVersionProperty”。
3. 在宏编辑器中,输入以下代码:
```
Option Explicit
Sub AddVersionProperty()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustomInfoMgr As SldWorks.CustomPropertyManager
Dim swFileProp As Variant
Dim filepath As String
Dim filename As String
Dim version As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swCustomInfoMgr = swModel.Extension.CustomPropertyManager("")
filepath = swModel.GetPathName()
filename = Right(filepath, Len(filepath) - InStrRev(filepath, "\"))
version = Right(filename, 3)
swCustomInfoMgr.Add2 "Version", swCustomInfoMgr.GetType("Version"), version
Else
MsgBox "No document is currently open."
End If
End Sub
```
4. 点击菜单栏上的“文件”->“保存”保存宏,然后关闭宏编辑器。
5. 在SolidWorks中打开需要添加自定义属性的文件,点击菜单栏上的“工具”->“宏”->“执行”,选择刚才创建的宏“AddVersionProperty”,点击“运行”按钮。
6. 宏运行后,自定义属性“Version”将会被添加到文件中,并且属性值将会被设置为文件名的后三位。
注意:此宏只会添加自定义属性“Version”,如果需要添加其他自定义属性,需要修改代码中的属性名称和类型。同时,如果文件名不是以数字结尾,截取后三位可能会出现错误,需要根据实际情况进行修改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)