Search code examples
vbams-accessvbscriptcatia

Adding Catia part properties through VBA, converted from CATScript


I am trying to manipulate Catia Part properties using Access VBA. I know there are some incompatibilities between the CAT scripting language and VBA. I am wondering if there are any work arounds or other options for the following built in functions.

.CreateString
.SetEnumerateValues

At the moment I get a "Method or Data member not found" with the code below on both functions:

Dim oDoc As Document
Dim oPart As Part
Dim params As Parameters
Dim strParam As StrParam
Dim arrVendorList(1)

Set oDoc = CATIA.ActiveDocument
Set oPart = oDoc.Part
Set params = oPart.Parameters
Set strParam = params.CreateString("VENDOR", "")

arrVendorList(0) = "abc"
arrVendorList(1) = "def"
strParam.SetEnumerateValues arrVendorList

Solution

  • In a scripting document about portability I found the simple workaround is to un-type the variable on which the method is applied. The code below will work in access. It adds a new part and creates a custom vendor dropdown list in properties.

    Dim oDoc       '**As Document
    Dim i As Integer
    Dim param      '**As Paramaters
    Dim StrParam   '**As StrParam
    Dim arrVendorList(2) As Variant
    
    Set oDoc = CATIA.Documents
    Set AddPart = oDoc.Add("Part") ' create new part
    Set newPart = AddPart.GetItem("Part1") ' set new part
    Set param = newPart.UserRefProperties
    Set StrParam = param.CreateString("VENDOR", "") ' create new custom property
    
    ' add vender array list to part
    arrVendorList(0) = "" ' initial value
    arrVendorList(1) = "abc"
    arrVendorList(2) = "def"
    StrParam.SetEnumerateValues arrVendorList