Convert Catia parameters into Script Parameters

Options
Gabriel Messager
Gabriel Messager Member, Employee Posts: 49
5 Likes Name Dropper First Anniversary Ansys Employee
edited June 2023 in 3D Design

Comments

  • Gabriel Messager
    Gabriel Messager Member, Employee Posts: 49
    5 Likes Name Dropper First Anniversary Ansys Employee
    Options
    from SpaceClaim.Api.V23 import Command
    
    def is_valid_float(element):
        try:
            float(element)
            return True
        except ValueError:
            return False
    
    
    comp= GetRootPart().Components[0]
    dict_custom_prop = comp.Content.Master.CustomProperties
    keys = dict_custom_prop.Keys
    
    for key in keys:
        value = "".join([ele for ele in dict_custom_prop[key].Value if ele.isdigit() or ele=="."])
        if is_valid_float(value) is True:
            Command.Execute("CreateNamedScriptParameter")
            mygroup = GetActiveWindow().Groups[-1]
            mygroup.SetName(key)
            mygroup.SetDimensionValue(float(value))