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

Model 파일 Assemble

by ToolBOX01 2022. 12. 28.
반응형

■ 프로그램 화면

- 하드디스크에 있는 모델 파일을 불러 옵니다
- 모델 이름은 VBA Cell에 있습니다.

[ VBA 프로그램 ]

■ 프로그램 코드 

Option Explicit
Sub componentAssy()

Application.EnableEvents = False
On Error GoTo RunError

        Dim pathArray As New Collection
        Dim asynconn As New pfcls.CCpfcAsyncConnection
        Dim conn As pfcls.IpfcAsyncConnection
        Dim oSession As pfcls.IpfcBaseSession
        Dim oModel As IpfcModel
        Dim oSolid As IpfcSolid
        Dim oAssembly As IpfcAssembly
        Dim oAsmcomp As IpfcComponentFeat
        Dim oCreoFileName As String
        
         '// Session File Open
        Dim oCreateModelDescriptor As New CCpfcModelDescriptor
        Dim oModelDescriptor As IpfcModelDescriptor
        
 
        Set conn = asynconn.Connect("", "", ".", 5)
        Set oSession = conn.session
        Set oModel = oSession.CurrentModel

        oCreoFileName = Cells(8, "B")
        Set oModelDescriptor = oCreateModelDescriptor.CreateFromFileName(oCreoFileName)
        Set oSolid = oSession.RetrieveModel(oModelDescriptor)  '// Session으로 모델 불러오기
        
        Set oAssembly = oModel
        Set oAsmcomp = oAssembly.AssembleComponent(oSolid, Nothing)
        
        oAsmcomp.RedefineThroughUI
        
        
        conn.Disconnect (2)
    
        'Cleanup
        Set asynconn = Nothing
        Set conn = Nothing
        Set oSession = Nothing
        Set oModel = Nothing

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

 

■ 프로그램 실행 화면 

 

by lionkk@idt21c.com