1

I want to export parameters from Par to text file.

See the Tree here.

enter image description here

I wrote a script that should export all the values.

Sub CATMain()
    ' Declare variables
    Dim CATIA
    Dim partDocument
    Dim part
    Dim parameters
    Dim parameter
    Dim fileName
    Dim fso
    Dim file

    ' Initialize CATIA and get the active document
    Set CATIA = GetObject(, "CATIA.Application")
    Set partDocument = CATIA.ActiveDocument
    Set part = partDocument.Part
    Set parameters = part.Parameters

    ' Specify the file to write the parameters to
    fileName = "C:\Users\zezul001\parameters.txt"
    
    ' Create FileSystemObject
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    ' Create or open the file for writing
    Set file = fso.OpenTextFile(fileName, 2, True)

    ' Loop through each parameter and write its name and value to the file
    For i = 1 To parameters.Count
        Set parameter = parameters.Item(i)
       Select Case TypeName(parameter)
            Case "RealParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Double)"
            Case "StrParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (String)"
            Case "IntParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Integer)"
            Case "BoolParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Boolean)"
          Case "LengthParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Length)"
            Case "AngleParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Angle)"
            Case "MassParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Mass)"
            Case "AreaParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Area)"
            Case "VolumeParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Volume)"
            Case "TimeParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Time)"
            Case "DensityParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Density)"
            Case "FrequencyParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Frequency)"
            Case Else
                file.WriteLine parameter.Name & ": " & "Unsupported parameter type"
        End Select
    Next

    ' Close the file
    file.Close
    
    ' Notify the user
    MsgBox "Parameters exported successfully to " & fileName

However, in the test file I have this:

Bobbin_thickness: Unsupported parameter type

Core_offset: Unsupported parameter type

Bobin_spacer: Unsupported parameter type

WIre_sec_diamater: Unsupported parameter type

First_layer_num_of_strands_support_secondar: 10 (Integer)

12242228-1-0000A\First_layer_wire\Sketch.9\Activity: True (Boolean)

What data type is the length parameter in catia so I can export it? Boolean, integer works, however when there is length parameter in catia like 20mm it doesn't work.

Thank you

2 Answers 2

0

Did you try changing "LengthParam" to "Length"? This works on my side.

Sign up to request clarification or add additional context in comments.

Comments

0

All "physical" parameters belong to the type Dimension. For angular and length parameters there are special sub-types Lenght and Angle.
All Dimension parameters have the property Unit. Also you can use ValueAsString to get the value including its unit.

     Select Case TypeName(parameter)
         Case "RealParam"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Real)"
         Case "Length"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Length)"
         Case "Angle"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (Angle)"
         Case "Dimension"
                file.WriteLine parameter.Name & ": " & parameter.Value & " (" & parameter.Unit.Symbol & ")"
         Case Else
                file.WriteLine parameter.Name & ": " & "Unsupported parameter type"
    End Select

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.