solidworks代名称分离宏命令属性自定义或配置特定中
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
s o l i d w o r k s代名称分离宏命令属性自定义或配置
特定中
The pony was revised in January 2021
S o l i d W o r k s2014基于宏实现快速"图号名称"分离1.两类代码
代码1(内容添加至“自定义下”)
DimswAppAsObject
DimPartAsObject
DimSelMgrAsObject
DimboolstatusAsBoolean
DimlongstatusAsLong,longwarningsAsLong
DimFeatureAsObject
DimaAsInteger
DimbAsString
DimmAsString
DimeAsString
DimkAsString
DimtAsString
DimcAsString
DimjAsInteger
DimstrmatAsString
DimtempvalueAsString
Submain()
'linksolidworks
SetswApp=Application.SldWorks
SetPart=swApp.ActiveDoc
SetSelMgr=Part.SelectionManager
=1
'设定变量
c=()'零件名
strmat=Chr(34)+Trim("SW-Material"+"@")+c+Chr(34)
blnretval=Part.DeleteCustomInfo2("","图样代号")
blnretval=Part.DeleteCustomInfo2("","图样名称")
blnretval=Part.DeleteCustomInfo2("","材料")
a=InStr(c,"")-1'重点:分隔标识符,这里是一个空格,也可用其他符号区分
Ifa>0Then
k=Left(c,a)
t=Left(LTrim(e),3)
Ift="GBT"Then
e="GB/T"+Mid(k,4)
Else
e=k
EndIf
b=Mid(c,a+2)
t=Right(c,7)
Ift=".SLDPRT"Ort=".SLDASM"Ort=".sldprt"Ort=".sldasm"Then j=Len(b)-7'消除后缀(区分大小写,即含4种)
Else
j=Len(b)
EndIf
m=Left(b,j)
EndIf
blnretval=Part.AddCustomInfo3("","图样代号",swCustomInfoText,e)'代号blnretval=Part.AddCustomInfo3("","图样名称",swCustomInfoText,m)'名称blnretval=Part.AddCustomInfo3("","表面处理",swCustomInfoText,"") EndSub
代码2(内容添加至“配置特定”下)
'定义sw
DimaAsInteger
DimbAsString
DimmAsString
DimeAsString
DimkAsString
DimtAsString
DimcAsString
DimjAsInteger
DimstrmatAsString
DimtempvalueAsString
DimPartAsObject
DimswAppAsSldWorks.SldWorks DimswModelDocAsSldWorks.ModelDoc2 DimswConfigAsSldWorks.Configuration DimCustPropMgrAsSldWorks.CustomPropertyManager DimswModelAsSldWorks.ModelDoc2
Submain()
SetswApp=Application.SldWorks
SetswModelDoc=swApp.ActiveDoc
SetswConfig=
SetswModel=swApp.ActiveDoc
SetCustPropMgr='配置特定延伸
'设定变量
c=()'零件名
strmat=Chr(34)+Trim("SW-Material"+"@")+c+Chr(34)
a=InStr(c,"")-1'重点:分隔标识符,这里是一个空格,也可换成其他符号Ifa>0Then
k=Left(c,a)
t=Left(LTrim(e),3)
Ift="GBT"Then
e="GB/T"+Mid(k,4)
Else
e=k
EndIf
b=Mid(c,a+2)
t=Right(c,7)
Ift=".SLDPRT"Ort=".SLDASM"Ort=".sldprt"Ort=".sldasm"Then
j=Len(b)-7'消除后缀(区分大小写,即含4种)
Else
j=Len(b)
EndIf
m=Left(b,j)
EndIf
'删除栏
CustPropMgr.Delete("图样代号")
CustPropMgr.Delete("图样名称")
CustPropMgr.Delete("材料")
'新增
CustPropMgr.Add2"图样代号",swCustomInfoText,e CustPropMgr.Add2"图样名称",swCustomInfoText,m CustPropMgr.Add2"数量",swCustomInfoText,"" CustPropMgr.Add2"材料",swCustomInfoText,strmat CustPropMgr.Add2"单重",swCustomInfoText,"" CustPropMgr.Add2"总重",swCustomInfoText,"" CustPropMgr.Add2"备注",swCustomInfoText,"" EndSub