美文网首页
009 - Inventor文件中创建或更新iProperty属

009 - Inventor文件中创建或更新iProperty属

作者: 怪怪001 | 来源:发表于2023-12-22 10:22 被阅读0次

设计背景:需要在零件和装配图中增加自定义属性每套数量。

利用正则表达式验证输入的数据是否为数字,如果不是数字弹出对话框要求用户输入数字。

如果不存在对应的自定义属性添加属性并赋值。

如果存在对应的自定义属性直接赋值。

代码来源:Inventor&Vault全国专业用户群 - LUCAS

Imports System.Text.RegularExpressions

doc=ThisDoc.Document

Dim summaryPropSet as PropertySet = doc.PropertySets.Item("Inventor User Defined Properties")

Dim PartQuantuty As Inventor.Property=Nothing

Try

    PartQuantuty=summaryPropSet.Item("每套数量")

Catch ex As Exception

    PartQuantuty=summaryPropSet.Add(1,"每套数量")

End Try

dim pattern as String = "^[1-9]\d*$"

Dim regex as New Regex(pattern)

Again:

Dim PropertyValue as String=InputBox("输入数量:","输入",PartQuantuty.Value)

If Not String.IsNullOrEmpty(PropertyValue) Then

    If regex.IsMatch(PropertyValue) Then

        PartQuantuty.Value=PropertyValue

    Else

        MsgBox("请输入一个整数",vbInformation + vbOKonly,"警告")

        GoTo Again

    End If

End If

相关文章

网友评论

      本文标题:009 - Inventor文件中创建或更新iProperty属

      本文链接:https://www.haomeiwen.com/subject/rzofndtx.html