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

Get the IDs of dimensions included in a drawing view

by ToolBOX01 2024. 9. 4.
반응형

□ Process of getting dimension

  • Step 1 :  IpfcModel2D
  • Step 2 :  IpfcView2D
  • Step 3 :  IpfcTransform3D
  • Step 4 :  IpfcBaseDimension
  • Step 5 :  IpfcDimension2D

This is a VBA program that gets the view name of a CREO PART drawing and the dimension ID included in the view.

 

  • You can get dimension values ​​and tolerance values.
  • You can track changed dimension values ​​and tolerance values.
  • You can compare dimension values ​​and tolerance values ​​between drawings.
  • You can analyze the dimension type of the drawing.
  • You can automatically number the dimensions in front of the dimensions.

 

Main Code

Option Explicit
Sub Drawing02()
    On Error GoTo RunError

    '// Module Name : CreoVBAStart
    Call CreoVBAStart.CreoConnt01
    
    Dim GetModel As IpfcModel
    Dim Model2D As IpfcModel2D
    Dim Drawing As IpfcDrawing
    
    Dim View2Ds As IpfcView2Ds
    Dim View2D As IpfcView2D
    Dim GetView2D As IpfcView2D
    Dim Transform3D As IpfcTransform3D
    Dim ViewOrigin As IpfcPoint3D

    Dim BaseDimension As pfcls.IpfcBaseDimension
    Dim Dimension2Ds As IpfcDimension2Ds
    Dim Dimension2D As IpfcDimension2D
    
    Dim i As Integer
    Dim j As Integer
    Dim lo As Integer
    lo = 1
    
    Set Model2D = BaseSession.CurrentModel
    Set Drawing = Model2D
    Set View2Ds = Model2D.List2DViews


    For i = 0 To View2Ds.Count - 1
        Set View2D = View2Ds.Item(i)
        Set Transform3D = View2Ds.Item(i).GetTransform
        Set ViewOrigin = Transform3D.GetOrigin

        Worksheets("drawing01").Cells(i + 6, "A") = i + 1
        Worksheets("drawing01").Cells(i + 6, "B") = View2D.Name
        Worksheets("drawing01").Cells(i + 6, "C") = ViewOrigin.Item(0)
        Worksheets("drawing01").Cells(i + 6, "D") = ViewOrigin.Item(1)
        Worksheets("drawing01").Cells(i + 6, "E") = View2D.GetSheetNumber
        
        
        Set GetModel = View2D.GetModel
        Set Dimension2Ds = Model2D.ListShownDimensions(GetModel, EpfcModelItemType.EpfcITEM_DIMENSION)
        
                For j = 0 To Dimension2Ds.Count - 1
                    
                         Set BaseDimension = Dimension2Ds.Item(j)
                         Set Dimension2D = BaseDimension
                         Set GetView2D = Dimension2D.GetView
                         
                         If GetView2D.Name = View2D.Name Then
                          
                            Worksheets("drawing01").Cells(i + 6, "E").Offset(, lo) = BaseDimension.Symbol
                            lo = lo + 1
                            
                         End If
                         
                Next j
                
                 lo = 1
    
    Next i
     MsgBox "I brought all the Drawing View names and Dimension IDs.", vbInformation, "korealionkk@gmail.com"
    
    conn.Disconnect (2)
    
    '// Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set BaseSession = Nothing
    Set model = Nothing
    
RunError:
            If Err.Number <> 0 Then
                MsgBox "Process Failed: An error occurred." & vbCrLf & _
                       "Error No: " & CStr(Err.Number) & vbCrLf & _
                       "Error Description: " & Err.Description & vbCrLf & _
                       "Error Source: " & Err.Source, vbCritical, "Error"
                If Not conn Is Nothing Then
                    If conn.IsRunning Then
                        conn.Disconnect (2)
                    End If
                End If
            End If

End Sub

 

DrawingViewname-dim.cls
0.00MB

 

★ Set Model2D = BaseSession.CurrentModel

Get the active drawing information

★ Set View2Ds = Model2D.List2DViews

Get view information for a drawing

★ Set GetModel = View2D.GetModel

To retrieve the dimension information stored in 3D, retrieve 3D information

★ Dimension2Ds = Model2D.ListShownDimensions(GetModel, EpfcModelItemType.EpfcITEM_DIMENSION)

Get 2D dimension information from 3D models

 

 

 

▷ Reference Code : Drawing Dimension All Display With Tolerence

 

developing . . . . Drawing Dimension All Display With Tolerence

도면에 배치된 치수를 표시합니다 Display dimensions linked to the drawing 공차와 함께 표시하는 프로그램 입니다 This is a program that displays with tolerances 1. Drawing Sheet ▶ IpfcSheetOwner Object 시트가 포함 된 모

tool-2020.tistory.com

 

▷ Reference

 

CS293191 - How to Show 3D model dimensions in a drawing view through Creo Parametric VB API

Article - CS293191 How to Show 3D model dimensions in a drawing view through Creo Parametric VB API Modified: 21-Jan-2022    Applies To Creo Parametric 1.0 to 8.0 Description How to Show 3D model dimensions in a drawing view through VB API ?How to show

www.ptc.com