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

Windchill & VBA 10) Get CADDocuments #2

by ToolBOX01 2024. 8. 3.
반응형

□ Creo 파일 이름 및 정보 가져오기 (Get Creo file names and information)

제품 > 폴더 아래에 있는 Creo 파일 이름 및 정보를 가져오는 코드 입니다
Here is the code to get the Creo file name and information under Products > Folders

※ 주의(caution)
제품이 가지고 있는 기본 폴더의 주소를 입력 해야 합니다
You must enter the address of the default folder that the product has.

□ Code

1. URL

 "http://WC Adress/Windchill/servlet/odata/v4/DataAdmin/Containers('A')/Folders('B')/Folders('C')/FolderCon

A : 제품 주소 (Product Adress)
ex) OR:wt.pdmlink.PDMLinkProduct:1376268

B: 제품의 기본 폴더 주소 (The product's default folder address)
ex) OR:wt.folder.Cabinet:1376613

C: 제품의 하위 폴더 주소 ( Product subfolder address)
ex) OR:wt.folder.SubFolder:1376871

Option Explicit
Sub FileName02()

        '// 오류 발생 시 오류 메시지 출력
        On Error Resume Next
        
        Call MainGetToken.GetToken001
     
       '// 변수
        Dim xmlhttp As Object
        Set xmlhttp = CreateObject("MSXML2.XMLHTTP.6.0")
        Dim Url As String
        Dim requestBody As String
        Dim GetresponseText As String
        Dim status As Integer
        Dim jsonObject As Object
        Dim jsonItem As Object
        Dim ProductType As String
        
        Dim j As Integer
        

         '// URL 설정
        Url = "http://WC Adress/Windchill/servlet/odata/v4/DataAdmin/Containers('OR:wt.pdmlink.PDMLinkProduct:1376268')/Folders('OR:wt.folder.Cabinet:1376613')/Folders('OR:wt.folder.SubFolder:1376871')/FolderContents"
                    
        '// 서버와의 연결 열기
        xmlhttp.Open "GET", Url, False
        
        '//요청 헤더 설정
        xmlhttp.SetRequestHeader "Content-Type", "application/json"
        xmlhttp.SetRequestHeader "CSRF_NONCE", NonceTorken("NonceValue")
        
         '//요청 보내기
        xmlhttp.Send requestBody
    
        '// 오류 발생 시 디버그 창에 오류 메시지 출력
        If Err.Number <> 0 Then
            Debug.Print "Error " & Err.Number & ": " & Err.Description
            On Error GoTo 0
            Exit Sub
        End If
    
        '// 응답 상태 코드 가져오기
        status = xmlhttp.status
        
        '// 응답 텍스트 가져오기
        GetresponseText = xmlhttp.responseText
        
        '// JSON 파싱
        Set jsonObject = JsonConverter.ParseJson(GetresponseText)
        
        '// 데이터 엑셀에 출력
                j = 1
                For Each jsonItem In jsonObject("value")

                               Worksheets("Creo File NameII").Cells(j + 4, "A") = j
                               Worksheets("Creo File NameII").Cells(j + 4, "B") = jsonItem("FileName")
                               Worksheets("Creo File NameII").Cells(j + 4, "C") = jsonItem("ID")
                               Worksheets("Creo File NameII").Cells(j + 4, "D") = jsonItem("FolderLocation")
                               Worksheets("Creo File NameII").Cells(j + 4, "E") = jsonItem("Number")
                               Worksheets("Creo File NameII").Cells(j + 4, "F") = jsonItem("PARTNO")
                               Worksheets("Creo File NameII").Cells(j + 4, "G") = jsonItem("PARTNAME")
                               Worksheets("Creo File NameII").Cells(j + 4, "H") = jsonItem("@odata.type")
                               Worksheets("Creo File NameII").Cells(j + 4, "I") = jsonItem("ObjectType")
                                                              
                                j = j + 1
                                
                Next jsonItem
        
        '// 응답 상태 및 텍스트 출력 (디버깅 용도)
        '//Debug.Print "Status: " & status
        '//Debug.Print "Response: " & GetresponseText
        
        '// 정리 작업
        Set xmlhttp = Nothing

End Sub

2. 프로그램 실행 (Run the program)

Creo 모델이 가지고 있는 Parameter 값을 가져올수 있습니다.
You can get the parameter values ​​that the Creo model has.

 

 

 

Windchill & VBA 10) Retrieving Folder Contents of a Specific Type

□ WTPart 이름 및 속정 정보 가져오기        (Get WTPart name and attribute information)FolderContents/PTC.ProdMgmt.Part □  URL Url = "http://WC Adress/Windchill/servlet/odata/v4/DataAdmin/Containers('A')/Folders('B')/Folders('C')/Fold

tool-2020.tistory.com