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

Materials : Creo 모델에 지정된 재질 파일 검색

by ToolBOX01 2022. 9. 7.
반응형

Creo 모델에 재질 파일을 지정 하는 방법을 알아봅니다.

 

 


■ VBA Start Template 소스 코드

VBA 프로그램 개발은 아래 코드를 기본으로 사용 합니다. 현재 활성된 모델을 가져옵니다.

 

 

Sub tempname ()

On Error GoTo RunError

        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 Model As pfcls.IpfcModel: Set Model = session.CurrentModel

 

 

 

 

 

 

 

    'Disconnect with Creo
    conn.Disconnect (2)\

 

Exit Sub
    
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

 


■ 재질 파일 안의 사용자 Parameter 이름 및 값

 

{
  Name = PTC_XHATCH_FILE
  Type = String
  Default = 'AL2014'
  Access = Full
},
{
  Name = KOREA
  Type = String
  Default = '이것은 테스트 립니다'
  Access = Full
}

}

 

 

 


■ 현재 모델 안에 있는 재질 파일  LIST - 소스 코드

Sub cells_parameterinput()

On Error GoTo RunError

        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 Model As pfcls.IpfcModel: Set Model = session.CurrentModel
        

        Dim oSolid As IpfcSolid: Set oSolid = Model
        Dim oPart As IpfcPart: Set oPart = oSolid
        Dim oMaterials As IpfcMaterials
        Set oMaterials = oPart.ListMaterials
        
        If oMaterials.Count > 0 Then
        
            For i = 0 To oMaterials.Count - 1
                MsgBox oMaterials.Item(i).name
            Next i
            
         Else
            
                MsgBox ("지정된 Material 파일이 없습니다")
       
         End If
       


    'Disconnect with Creo
    conn.Disconnect (2)

        
Exit Sub
    
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

 


■ 현재 모델 안에 있는 지정된  재질 파일 이름 표시 - 소스 코드

 

 

Sub cells_parameterinput()

On Error GoTo RunError

        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 Model As pfcls.IpfcModel: Set Model = session.CurrentModel
        
        Dim oSolid As IpfcSolid: Set oSolid = Model
        Dim oPart As IpfcPart: Set oPart = oSolid
        Dim oMaterial As IpfcMaterial: Set oMaterial = oPart.CurrentMaterial
        Dim oMaterialname As String: oMaterialname = oMaterial.name
                               
        MsgBox ("재질 파일" & oMaterialname & " 설정 되었습니다")


    'Disconnect with Creo
    conn.Disconnect (2)
         
Exit Sub
    
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