본문 바로가기
  • 환영 합니다 ! Welcome!
VBA For Creo

현재 활성화 된 파일 상태 표시 및 BACKUP ()

by ToolBOX01 2022. 9. 26.
반응형

■ 아래 코드를 이용하여,  IpfcModel 클래스에 대해 알아 봅니다

이 클래스는 현재 세션에 있는 모델에 대한 정보를 지정합니다. 현재 활성화된 모델의 타입을 메세지 박스로 표시하는 프로그램 입니다 .  IpfcModel은 파일 개체 단위로 정보를 얻고, 저장하고, 정보를 가져 옵니다. CREO 화면에 활성화된 모델이 DRW, ASM,PRT인지 알아보는 방법은 IpfcModel의 Property를 사용 하는 것 입니다. 변수 "oModel"를 만들고, "oSession.CurrentModel" 개체를 지정 합니다. 개체는 모든 정보가 있는 덩어리 입니다. CREO VBA API 메뉴얼에 "Type"이라는 속성은  IpfcModelType 정의된 변수로 반환 됩니다. 하지만  Enum EpfcModelType 으로 반환 된다고 합니다.

즉, 숫자 번호로 반환 됩니다. ( 변수를 IpfcModelType으로 정의 불가능 합니다) 

++++++++++++++++++++++++++++

Property  Type    as IpfcModelType
 -  The model type 번호를 반환 합니다.

++++++++++++++++++++++++++++

 

MsgBox oModel.Type은 엑셀 화면에 메세지 박스로  "숫자"를 출력 합니다

 


Sub Testmodel()
On Error GoTo RunError
     
        Dim asynconn As New pfcls.CCpfcAsyncConnection
        Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
        Dim oSession As pfcls.IpfcBaseSession: Set oSession = conn.session
        Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
        
        MsgBox oModel.Type
             
        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

 


메세지 박스에 현재 활성화된 파일의 타입을 아라비아 숫자로 표시 합니다. 다양한 파일 포맷을 표시 할 수 있습니다.

       Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
       MsgBox oModel.Type

 

1. ".asm" 파일은 "0"이 표시 됩니다.

2. ".prt" 파일은 "1"이 표시 됩니다

3. "<Family Table>.prt" 파일은 "1"이 표시 됩니다.

4. drawing 파일은 "2"가 표시 됩니다.

 

다음과 같이 코드를 변경 할수 있습니다.

 

Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel

 

IF oModel.Type = 0 Then

    msgbox " .asm 파일 입니다"

    Elseif  oModel.Type = 1 Then

            msgbox " .prt 파일 입니다"

            Elseif  oModel.Type = 2 Then

                    msgbox " .drw 파일 입니다"

                    Else 

                           msgbox " 기본 옵션  파일 입니다"

 End if

 

[ Code 실행 결과 ]


■ Property

1) Property GenericName as String [readonly, optional]

일반 모델의 이름입니다. 모델이 인스턴스가 아닌 경우 이 속성은 null이거나 빈 문자열이 됩니다.

 

2) Property InstanceName as String
모델의 이름 또는 모델이 인스턴스인 경우 인스턴스 이름입니다.

 

추가로 Family Table 파일  Instance,  Generic 파일 이름을 표시 할수 있습니다. 특정 Creo 파일이 Family Table 파일 인지,

아닌지  "oModel.InstanceName" 와 "oModel.GenericName" 판별은 불가능 합니다

 

       Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
       

      MsgBox oModel.GenericName

 

      1)  Family Table Instance 파일을 open 합니다.  "Generic Name" 이름을 표시 합니다. 

      2) 일반 Creo 파일 또는 Family Table Generic파일을 open 하고 코드를 실행 하면, 파일 이름이 null 입니다.
           
- Creo 파일이 Family Table 파일인지 아닌지 구분을 못합니다.

 

 

       MsgBox oModel.InstanceName

 

       1) Family Table Instance 파일을 open 합니다.  "Instance Name" 이름을 표시 합니다. 

 

 

sub ()

 IpfcModel 클래스에 포함된 "Backup" 함수를 사용 하여, 현재의 모델을 특정한 폴더에 저장 할수 있습니다. 

 

Sub Backup (WhereTo as IpfcModelDescriptor)

  - WhereTo :  백업 복사본이 생성되는 디렉터리의 경로입니다. (백업은 원본과 동일한 파일 이름을 가집니다.)
 - 모델(2D, 3D)을 지정된 디렉토리에 백업합니다. 3D를 Backup 하면 동일한 이름의 2D를 자동으로 Backup 하지 않습니다.

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
 Dim oModelDescriptor As IpfcModelDescriptor: Set oModelDescriptor = oModel.Descr
        
        oModelDescriptor.Path = "c:\idt\backup"
        oModel.Backup oModelDescriptor

        MsgBox "c:\idt\backup 폴더에 저장 했습니다"
           
       
    conn.Disconnect (2)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++