본문 바로가기
  • Welcome!
VBA For Creo

Family Table Part

by ToolBOX01 2023. 1. 1.
반응형

하드 디스크에 저장된 Family Table Part의 Instance 이름을 표시 합니다

by PTC

Sub Main2()
'
' This routine will open a Pro/ENGINEER file from your WorkingDirectory in a new window:
'
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
Dim oModel As pfcls.IpfcModel
 
'Make an asynchronous connection with Pro/ENGINEER
Set conn = asynconn.Connect("", "", ".", 5)
 
'Get the current session
Set session = conn.session
 
'Show the current Working Directory
MsgBox "This is the current Working Directory: " & vbCrLf & session.GetCurrentDirectory
 
'Create a modeldescriptor to the Pro/E Model
Dim oModelDescriptorCreate As New CCpfcModelDescriptor
Dim oModelDescriptor As IpfcModelDescriptor
Set oModelDescriptor = oModelDescriptorCreate.Create(EpfcMDL_PART, "PRT0001.PRT", Null)
 
'Retrieve the model into the oModel handle
Set oModel = session.RetrieveModel(oModelDescriptor)
 
 
'Create a new window which displays the Pro/E Model
Dim oWindow As pfcls.IpfcWindow
Set oWindow = session.OpenFile(oModelDescriptor)
 
'Activate the new window
oWindow.Activate
 
'Show the name of the Pro/E Model in a messagebox
MsgBox "Model name = " & oModel.Filename
'
Dim A As IpfcBaseParameter
Dim Av As IpfcParamValue
Dim newA As IpfcParamValue
Dim A_value As Double
Dim generic As IpfcFamilyMember
Dim rows As IpfcFamilyTableRows
Dim row As IpfcFamilyTableRow
Dim InstName As String
 
'Declare (make) the Model as a IpfcFamilyMember type object
Set generic = oModel
' list the ROws of family table. If the part is not a generoc, there will be 0 rows
Set rows = generic.ListRows()
 
' Now, get each row and print the instance name. Once, each instance is obtained, perform required operations.
For Each row In rows
InstName = row.InstanceName
MsgBox "Fam Instance Name: " & InstName
Next
 
'Disconnect with Pro/ENGINEER
conn.Disconnect (2)
 
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set session = Nothing
Set oModel = Nothing
 
End Sub

 

'VBA For Creo' 카테고리의 다른 글

Template Model] 자동으로 치수 변경  (1) 2023.01.04
라이브러리 관리 프로그램 #2  (0) 2023.01.03
라이브러리 관리 프로그램 #1  (0) 2022.12.28
Model 파일 Assemble  (0) 2022.12.28
ToolBOX VBA 1.5 개발 작업 #4  (0) 2022.12.27