본문 바로가기
  • Welcome!
VBA, VB.NET For Creo

Get the Parameter name of the model and delete it

by ToolBOX01 2024. 9. 14.
반응형

□ Code to get the model's Parameter

Gets the number of parameters the model has.
Gets the parameters name that the model has.
Gets the value of the parameters name that the model has.
Gets the types of parameters that the model has.

 

 

□ Main Code

Option Explicit
Sub GetParameter01()
    On Error GoTo RunError

    '// Module Name : CreoVBAStart
    Call CreoVBAStart.CreoConnt01
    
    Dim ParameterOwner As IpfcParameterOwner
    Dim BaseParameter As IpfcBaseParameter
    Dim Parameters As IpfcParameters
    Dim ParameterObject As Object
    Dim Parameter As IpfcParameter
    Dim ParamValue As IpfcParamValue
    Dim i As Integer
    
    Set ParameterOwner = model
    Set Parameters = ParameterOwner.ListParams
    
    For i = 0 To Parameters.Count - 1
    
           Set ParameterObject = Parameters.Item(i)
           Set ParamValue = ParameterObject.Value
           
           Worksheets("GetParameter01").Cells(i + 6, "A") = i + 1
           Worksheets("GetParameter01").Cells(i + 6, "B") = ParameterObject.Name
           
             If ParamValue.discr = 0 Then

                     Worksheets("GetParameter01").Cells(i + 6, "C") = ParamValue.StringValue
                     Worksheets("GetParameter01").Cells(i + 6, "D") = "String"
                     
             ElseIf ParamValue.discr = 1 Then '// if parameter is real value
                
                      Worksheets("GetParameter01").Cells(i + 6, "C") = ParamValue.IntValue
                      Worksheets("GetParameter01").Cells(i + 6, "D") = "integer"
                      
              ElseIf ParamValue.discr = 2 Then '// if parameter is real value
                
                      Worksheets("GetParameter01").Cells(i + 6, "C") = ParamValue.BoolValue
                      Worksheets("GetParameter01").Cells(i + 6, "D") = "Boolean"
                    
             ElseIf ParamValue.discr = 3 Then '// if parameter is real value
                
                      Worksheets("GetParameter01").Cells(i + 6, "C") = ParamValue.DoubleValue
                      Worksheets("GetParameter01").Cells(i + 6, "D") = "Double"
                
                    
            End If
        
    Next i

    
    
     MsgBox "Get Model Parameter Name", vbInformation, "korealionkk@gmail.com"
    
    conn.Disconnect (2)
    
    '// Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set BaseSession = Nothing
    Set model = Nothing
    
RunError:
            If Err.Number <> 0 Then
            
               Dim ErrorMessage As String
               ErrorMessage = ErrorHandlerModule.MapErrorToMessage(Err.Number) '// 모듈에서 함수 호출
        
               MsgBox "Process Failed: " & vbCrLf & _
               "Error No: " & CStr(Err.Number) & vbCrLf & _
               "Description: " & ErrorMessage, vbCritical, "Error"
                       
                If Not conn Is Nothing Then
                    If conn.IsRunning Then
                        conn.Disconnect (2)
                    End If
                End If
            End If

End Sub

 

Dim ParameterObject As Object
Set ParameterObject = Parameters.Item(i)
Worksheets("GetParameter01").Cells(i + 6, "B") = ParameterObject.Name


Creo VBA API does not provide a function to retrieve the parameter names of a model.
However, Parameter.item() returns the value as an object.