成语大全网 - 汉语词典 - CATIA二次开发(VBA)——通过参数获取特征Id的方法

CATIA二次开发(VBA)——通过参数获取特征Id的方法

Function GetFeatureId(ByVal prd As product, ByVal Feature As AnyObject)

On Error Resume Next

Dim prms As parameters

Set prms = prd.parameters

Dim prm As parameter

Set prm = prms.CreateString("FeatureId", "")

Dim rlts As Relations

Set rlts = prd.Relations

Dim prmExp As String

prmExp = prms.GetNameToUseInRelation(Feature)

If left(prmExp, 1) = "`" Then

prmExp = prmExp & "->Id()"

Else

prmExp = "`" & prd.PartNumber & "" & prmExp & "`->Id()"

End If

Dim frml As Formula

Set frml = rlts.CreateFormula("GetId", "获取Id", prm, prmExp)

GetFeatureId = prm.ValueAsString

rlts.Remove frml.name

prms.Remove prm.name

End Function

调用示例:

Sub test_getFeatId()

Dim doc As Document

Set doc = CATIA.ActiveDocument

Dim prd As product

Set prd = doc.product

Dim prt As Part

Set prt = doc.Part

Dim sel As Selection

Set sel = doc.Selection

Dim selObj As AnyObject

Set selObj = sel.Item(1).value

Debug.Print GetFeatureId(prd, selObj)

Debug.Print selObj.name

End Sub