본문 바로가기
  • You find inspiration to create your own path !
업무 자동화/VBA, VB.NET For Creo

초보자를 위해 . . . . IpfcBaseSession 세션에 로드된 모델을 찾기

by ToolBOX01 2026. 5. 4.
반응형

GetModel() vs ListModels()

두 메서드 모두 이미 세션에 로드된 모델을 찾는 기능입니다. GetModel()은 이름으로 하나를 콕 집어 찾고, ListModels()는 세션 전체 목록을 가져옵니다.

GetModel() — 이름으로 특정 모델 찾기 Sub GetModelExample()

Sub GetModelExample()

    '// 변수 선언
    Dim asynconn As New pfcls.CCpfcAsyncConnection
    Dim conn     As pfcls.IpfcAsyncConnection
    Dim oSession As pfcls.IpfcBaseSession
    Dim Model    As IpfcModel

    '// Creo 연결
    Set conn     = asynconn.Connect("", "", ".", 5)
    Set oSession = conn.Session

    '// 에러 발생 시 ErrHandler 로 이동
    On Error GoTo ErrHandler

    '// 모델 검색
    Set Model = oSession.GetModel("korea", IpfcModelType.MDL_PART)

    '// 찾았을 때
    MsgBox "찾음: " & Model.FileName

    '// 정상 종료
    On Error GoTo 0
    conn.Disconnect (2)
    Exit Sub

ErrHandler:
    '// 못 찾았을 때
    MsgBox "세션에 해당 모델이 없습니다." & vbCrLf & _
           "오류: " & Err.Description
    On Error GoTo 0
    conn.Disconnect (2)

End Sub

 

ListModels() — 세션 전체 모델 순회

Dim oSession As pfcls.IpfcBaseSession
Dim Models   As IpfcModels
Dim Model    As IpfcModel
Dim i        As Integer

Set oSession = conn.Session
Set Models   = oSession.ListModels()

'// 전체 모델 목록 출력
For i = 0 To Models.Count - 1
    Set Model = Models.Item(i)
    MsgBox i & ": " & Model.FileName & " / " & Model.Type
Next i


    

반응형