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

returns a list of all the solid models used in the drawing.

by ToolBOX01 2021. 3. 8.
반응형

Drawing에 포함된 3D 모델을 표시 합니다.

반드시 drawing을 open 하고 실행 합니다.

Be sure to open the drawing.

 

Open Button Click

 

Sorce Code

Set model = model2D.ListModels()

 


Sub Solid_name_2d()
        Dim asynconn As New pfcls.CCpfcAsyncConnection
        Dim conn As pfcls.IpfcAsyncConnection
        Dim session As pfcls.IpfcBaseSession
    
    On Error GoTo RunError
        Set conn = asynconn.Connect("", "", ".", 5)
        Set session = conn.session
              
        Dim model2D As IpfcModel2D
        Set model2D = session.CurrentModel
        
        Dim drawingFilename As IpfcModel
        Set drawingFilename = session.CurrentModel
        
        Cells(3, "C") = drawingFilename.Filename
        
        Dim model As IpfcModels
        Set model = model2D.ListModels()
              
        For i = 0 To model.Count - 1
            Cells(i + 7, "b") = model(i).Filename
            
        Next i
              
    conn.Disconnect (2)
    
    'Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set session = Nothing
    Set model = 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


Drawing List Solid.xlsm
0.03MB

 

Business inquiries : lionkk@idt21c.com