본문 바로가기
  • 환영 합니다 ! Welcome!
VBA For Creo

part 파일에서 paramter 및 value 표시 하기

by ToolBOX01 2022. 9. 5.
반응형

Part 파일에 있는 Parameter 값을 표시 합니다. Parameter 타입을 검색 해야 합니다.

 

■ 소스 코드

  Sub part_parameter()
    
  On Error GoTo RunError
    Dim asynconn As New pfcls.CCpfcAsyncConnection
    Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
    Dim oSession As pfcls.IpfcBaseSession:  Set oSession = conn.session
    Dim oModel As pfcls.IpfcModel: Set oModel = oSession.CurrentModel
     
    Dim oPowner As pfcls.IpfcParameterOwner: Set oPowner = oModel
    Dim oParams As IpfcParameters: Set oParams = oPowner.ListParams()


    Dim oParam As IpfcBaseParameter
    Dim oParamValue As IpfcParamValue
    Dim oParamName As IpfcNamedModelItem
    Dim NewDesignation As String


    For i = 0 To oParams.Count - 1
        Set oParam = oParams(i)
        Set oParamValue = oParam.Value
        Set oParamName = oParam
        
        Cells(i + 3, "C") = i + 1
        Cells(i + 3, "D") = oParamName.Name

      If oParamValue.discr = 0 Then 'If parameter is string
           Cells(i + 3, "E") = oParamValue.StringValue
           
        ElseIf oParamValue.discr = 3 Then 'if parameter is real value
           Cells(i + 3, "E") = oParamValue.DoubleValue
           
        End If
           Cells(i + 4, "E") = oParams(i).Description
    Next i


'Disconnect with Creo
    conn.Disconnect (2)

 

 'Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set session = Nothing
    Set Model = Nothing
    
Exit Sub
    
RunError:
    If Err.Number <> 0 Then
        MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
                "Error No: " + CStr(Err.Number) + Chr(13) + _
                "Error: " + Err.Description, vbCritical, "Error"
        If Not conn Is Nothing Then
            If conn.IsRunning Then
                conn.Disconnect (2)
            End If
        End If
    End If

End Sub