업무 자동화/VBA, VB.NET For Creo
Feature ID 및 Feature 이름 검색 프로그램 # 1/3
ToolBOX01
2021. 1. 3. 10:54
Feature ID and Feature Name Search Program
모델 | 프로그램 실행 |
![]() |
![]() |
왼쪽 모델 Tree는 Feature를 추가 하면 자동적으로 Feature 이름이 제공 됩니다. Feature의 이름에 공란이 있습니다. "extrude 1", "Round 1" ... PTC에서 제공 하는 API로는 인식이 불가능 합니다. ipfcmodelItem.GetName 함수를 이용
하여 Feature 이름을 리턴 받습니다. 하지만 "extrude 1", "Round 1"등은 "no_name"으로 표시 됩니다.
사용자가 정의한 Feature 이름은 공란을 넣을수 없습니다.
Feature 타입 이름 표시 기능 사이트
VB API Fundamentals -- VBA 예제 (2) part 파일 Feature LIST
tool-2020.tistory.com
Source code
Sub feature_id()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Set conn = asynconn.Connect("", "", ".", 5)
Dim session As pfcls.IpfcBaseSession
Set session = conn.session
Dim oModel As pfcls.IpfcModel
Set oModel = session.CurrentModel
Dim oModelowner As IpfcModelItemOwner
Set oModelowner = session.CurrentModel
Dim oModelitems As IpfcModelItems
Set oModelitems = oModelowner.ListItems(EpfcModelItemType.EpfcITEM_FEATURE)
Dim oModelitem As IpfcModelItem
Dim oFeatureid As Long
Dim i As Integer
For i = 0 To oModelitems.Count - 1
Set oModelitem = oModelitems.Item(i)
oFeatureid = oModelitem.ID
Cells(i + 5, 1) = i + 1
Cells(i + 5, 2) = oFeatureid
Cells(i + 5, 3) = oModelitem.Type
Cells(i + 5, 4) = oModelitem.GetName
Next i
'Disconnect with Creo
conn.Disconnect (2)
End Sub
Using the for each syntax
Sub feature_nameList()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Set conn = asynconn.Connect("", "", ".", 5)
Dim session As pfcls.IpfcBaseSession
Set session = conn.session
Dim oModel As pfcls.IpfcModel
Set oModel = session.CurrentModel
Dim oSolid As IpfcSolid
Set oSolid = oModel
Dim features As IpfcFeatures
Set features = oSolid.ListFeaturesByType(False, EpfcFeatureType.EpfcFeatureType_nil)
Dim feature As IpfcFeature
Dim oModelItem As IpfcModelItem
Dim i As Integer
For Each feature In features
Set oModelItem = feature
Cells(i + 5, 1) = i + 1
Cells(i + 5, 2) = oModelItem.ID
Cells(i + 5, 3) = oModelItem.GetName
Cells(i + 5, 4) = oModelItem.Type
i = i + 1
Next
'Disconnect with Creo
conn.Disconnect (2)
End Sub