◎ ModelItemOwner
모델 항목(Model Items)을 소유하고 관리하는 객체의 기본 틀(Base Class) 역할을 합니다. 이 인터페이스는 특정 객체가 Creo 모델의 구성 요소들(예: 피처, 서피스, 기준면, 치수 등)을 포함하고, 이들을 체계적으로 접근하고 관리할 수 있는 능력을 부여합니다. IpfcModelItemOwner 인터페이스가 정의하는 가장 중요한 기능은 바로 모델 항목 목록을 가져오는 메서드입니다. 예를 들어, IpfcModel 객체가 이 인터페이스를 상속받기 때문에, 개발자는 IpfcModel 객체를 통해 모델 내의 모든 피처(Features) 목록이나 모든 치수(Dimensions) 목록을 쉽게 얻을 수 있습니다.
관계 요약
- 소유자 (Owner): IpfcModelItemOwner를 구현하는 객체 (예: IpfcModel - 파트/어셈블리 파일).
- 소유된 항목 (Items): IpfcFeature, IpfcDatum, IpfcDimension 등과 같은 실제 모델 구성 요소들.
IpfcModel과 ModelItemOwner의 관계
모델 항목의 소유권 부여
1) 비유: 당신이 가진 큰 건축 도면(IpfcModel 객체)이 있다고 가정해 봅시다.
2) 소유권 부여: 이 도면이 IpfcModelItemOwner라는 자격을 갖게 됩니다. 이 자격 덕분에 도면은 내부적으로 기둥, 벽, 창문, 배관 라인 같은 개별 항목들(IpfcModelItem들, 즉 피처나 치수 등)을 '내 것이다' 라고 포함하고 관리할 권한을 갖게 됩니다.
3) 결론: 이 자격이 없으면, 객체는 Creo 모델 항목을 자신의 일부로 인식하고 제어할 수 없습니다.
기반 구조 제공 (비유: 표준화된 서랍장)
1) 비유: 모든 모델 항목 관리자(IpfcModelItemOwner)가 따라야 하는 표준 서랍장 사용 설명서가 있다고 생각해 보세요.
2) 기반 구조: 이 설명서에는 "목록을 뽑아주는 버튼(ListItems 메서드)을 반드시 가지고 있어야 한다"는 규칙이 명시되어 있습니다.
3) 상속: 실제 도면(IpfcModel)이 이 설명서(IpfcModelItemOwner)를 상속받으면, 그 도면은 자동으로 그 버튼(목록화 기능)을 갖게 됩니다.
4) 결론: 이 덕분에 모든 Creo 모델은 항목을 검색하고 나열하는 동일한 방법(ListItems)을 사용하게 되어,
개발자가 어떤 모델이든 쉽게 코드를 작성하고 관리할 수 있게 됩니다.
▶ 다양한 종류의 모델 항목(Model Item)
Interface ModelItemOwner를 사용하여 모델 안의 모든 구성 요소(피처, 기준면, 치수 등)를 가져올수 있고, 구성요소는 유한 ID 코드를 부여 합니다. 구성 요소들을 "EpfcModelItemType" 식별자(Enum 값)를 제공 합니다.
Enum 값들은 주로 IpfcModelItemOwner.ListItems() 또는 IpfcFeature.ListSubItems()와 같은 메서드를 호출할 때 필터(Filter) 역할로 사용됩니다. 예를 들어, 모델에서 모든 피처를 검색하고 싶다면, 이 Enum 목록에서 해당하는 값(예: EpfcITEM_FEATURE)을 인수로 전달하여 해당 유형의 항목만 반환하도록 지정합니다. EpfcModelItemType Enum에는 Creo 모델에 존재하는 거의 모든 종류의 항목이 포함됩니다. 일반적인 항목들은 다음과 같습니다:
| ID | Enum 값 | 의미 |
| 0 | EpfcITEM_FEATURE | 피처 (돌출, 회전, 라운드 등 모델링 작업) |
| 1 | EpfcITEM_SURFACE | 서피스 또는 곡면 |
| 2 | EpfcITEM_EDGE | 엣지 |
| 3 | EpfcITEM_COORD_SYS | 좌표계 (Coordinate System) |
| 4 | EpfcITEM_AXIS | 축 (Axis) |
✨ Sample code
Let's create a code that gets the total number of Features (EpfcITEM_FEATURE) included in the model (Part).
Since Model inherits IpfcModelItemOwner, it uses the ListItems method directly.
Sub GetFeatureCount()
'// 변수 선언 //'
Dim Model As pfcls.IpfcModel
Dim ModelItems As pfcls.IpfcModelItems
Dim FeatureCount As Long
'// Creo 세션 연결 시도 //'
Call Connect.CreoConnect
On Error GoTo ErrorHandler
'//현재 활성화된 모델 가져오기 //'
Set Model = BaseSession.CurrentModel
If Model Is Nothing Then
MsgBox "현재 Creo에 활성화된 모델이 없습니다.", vbExclamation, "모델 없음"
Exit Sub
End If
'// EpfcITEM_FEATURE 목록 가져오기 및 수량 계산 //'
'// Model은 IpfcModelItemOwner를 상속받으므로 ListItems 메서드를 직접 사용합니다. //'
'// EpfcITEM_FEATURE 타입을 필터로 사용하여 모든 피처 목록을 가져옵니다. //'
Set ModelItems = Model.ListItems(EpfcModelItemType.EpfcITEM_FEATURE)
FeatureCount = ModelItems.Count
'// 결과 메시지 처리 //'
Debug.Print "-----------------------------------------------------"
Debug.Print "모델 이름: " & Model.FullName
Debug.Print "총 피처 (EpfcITEM_FEATURE) 수: " & FeatureCount
Debug.Print "-----------------------------------------------------"
If FeatureCount > 0 Then
MsgBox "모델 [" & Model.FullName & "]이 가지고 있는 총 피처 수는 " & FeatureCount & "개 입니다.", vbInformation, "피처 수량 확인"
Else
'// 피처가 없는 경우 메시지 처리 //'
MsgBox "모델 [" & Model.FullName & "]에는 모델링 피처 (EpfcITEM_FEATURE)가 존재하지 않습니다.", vbExclamation, "피처 없음"
End If
Exit Sub
ErrorHandler:
MsgBox "런타임 오류 발생: " & Err.Description, vbCritical, "오류"
End Sub
✨ Module name CreoConnect Code (module name : Connect)
Option Explicit
'// Declare a public variable: Make it accessible throughout the module. //'
Public asynconn As pfcls.CCpfcAsyncConnection
Public conn As pfcls.IpfcAsyncConnection
Public BaseSession As pfcls.IpfcBaseSession
'*******************************************************************************
' Sub: CreoConnect
' Description: Connect to Creo Parametric and initialize the BaseSession object.
' Checks whether Creo is running, including error handling.
'*******************************************************************************'
Public Sub CreoConnect()
'// Jump to ErrorHandler label when an error occurs //'
On Error GoTo ErrorHandler
' // 1. If a Connection object has not yet been created, a new one is created. //'
If asynconn Is Nothing Then
'// Create a CCpfcAsyncConnection object (assign an instance to a variable declared using the New keyword) //'
Set asynconn = New pfcls.CCpfcAsyncConnection
End If
' // 2. Creo Connection Settings: Attempt to connect asynchronously to Creo //'
' // Connect(ServerName, Password, WorkingDirectory, Timeout) //'
' // Typically, ServerName and Password are set to "", and WorkingDirectory is set to "." (current directory). //'
' // Timeout is in seconds. //'
Set conn = asynconn.Connect("", "", ".", 5) '// 5 second timeout //'
'// 3.Get the BaseSession object //'
'// If the connection is successful, the conn object contains a BaseSession. //'
Set BaseSession = conn.Session
'// If the connection is successful, skip the error handler and exit. //'
'// Terminates the Sub gracefully, preventing the flow from passing to the ErrorHandler. //'
Exit Sub
'// ------------------------------------------------------------------------------- //'
'// Error handling handler //'
ErrorHandler:
'// Error handling when Creo connection library (Toolkit) is not found or Creo is not running //'
If InStr(Err.Description, "XToolKitNotFound") > 0 Or _
InStr(Err.Description, "Connect:") > 0 Then '// Errors that may occur in the Connect function //'
MsgBox "오류: Creo Parametric에 연결할 수 없습니다." & vbCrLf & _
"1. Creo가 실행 중인지 확인하십시오." & vbCrLf & _
"2. Creo API 환경 설정(Pro/TOOLKIT)을 확인하십시오.", vbCritical, "Creo Connection Error"
Else
' // Other general error handling //'
MsgBox "예기치 않은 오류가 발생했습니다." & vbCrLf & _
"오류 번호: " & Err.Number & vbCrLf & _
"오류 내용: " & Err.Description, vbCritical, "General Error"
End If
'// Initialize global variables when an error occurs (if necessary) //'
Set conn = Nothing
Set BaseSession = Nothing
Set asynconn = Nothing '// Since asynconn can be reused depending on the error type, you can decide whether to keep it or release it depending on your error recovery strategy. //'
End Sub
by korealionkk@gmail.com

'업무 자동화 > VBA, VB.NET For Creo' 카테고리의 다른 글
| IpfcModelItemOwner : Function ListItems (0) | 2025.11.16 |
|---|---|
| Interface ModelItemOwner - 사용자 정의 함수 만들기 (0) | 2025.11.16 |
| Creo 자동 프로그램 만들기 #3 - beginner (1) | 2025.11.15 |
| IpfcModel : Sub Rename() (0) | 2025.11.15 |
| IpfcModel : Function ListDependencies() (1) | 2025.11.15 |