본문 바로가기
  • Welcome!
VBA, VB.NET For Creo

Display all dimension names and values ​​contained in a part file

by ToolBOX01 2025. 3. 12.
반응형

Importing dimensional information from your Creo model into Excel can help you increase the efficiency of your design process and create better designs.

  • Provide visual information: Leverage Excel's chart and graph features to visually represent dimensional data and effectively communicate design information.
  • Automate data extraction: Automatically extract dimensional information into Excel using Creo API or other tools.
  • Bulk Changes: Make design changes efficiently by batch changing dimension values ​​in Excel and then applying them to your Creo model.
  • Design Variable Analysis: You can find optimal design conditions by analyzing the changes in model performance according to changes in various design variables (dimensions).
  • Sensitivity Analysis: Analyze how sensitive the model's performance is to changes in specific dimensions to identify important design variables.

▷Code

Option Explicit

Sub ModelDimensionList()
	Application.EnableEvents = False
	On Error GoTo RunError
    
    	Dim asynconn As New pfcls.CCpfcAsyncConnection
    	Dim conn As pfcls.IpfcAsyncConnection
    	Dim BaseSession As pfcls.IpfcBaseSession
        Dim Model as IpfcModel
        Dim Modelowner As IpfcModelItemOwner
        Dim modelitems As IpfcModelItems
        Dim BaseDimension As IpfcBaseDimension
        Dim i As Long

        Set conn = asynconn.Connect("", "", ".", 5)
        Set BaseSession = conn.session
        set Model = BaseSession.CurrentModel  
        Set Modelowner = Model
        Set modelitems = Modelowner.ListItems(EpfcModelItemType.EpfcITEM_DIMENSION)

        For i = 0 To modelitems.Count - 1
                Set BaseDimension = modelitems(i)
                Cells(i + 10, "A") = i + 1
                Cells(i + 10, "B") = BaseDimension.Symbol
                Cells(i + 10, "C") = BaseDimension.DimValue
         Next i
   
        MsgBox "Dimension Quantity:" & modelitems.Count, vbInformation
     
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 : 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

Retrieve the dimensions of the model in the following order:

IpfcModel >   IpfcModelItemOwner > IpfcModelItems > IpfcBaseDimension


▷ IpfcModelItemOwner

 

PTC Help Center

Your browser has DOM storage disabled. Make sure DOM storage is enabled and try again.

support.ptc.com

IpfcModelItem :
IpfcModelItems refers to IpfcModelItem.

 

PTC Help Center

Your browser has DOM storage disabled. Make sure DOM storage is enabled and try again.

support.ptc.com

 

IpfcBaseDimension :

 

PTC Help Center

Your browser has DOM storage disabled. Make sure DOM storage is enabled and try again.

support.ptc.com

Get dimension name and value from Part, Assemble file. The above code can't get dimension from Drawing file. You have to use another way. But it's not difficult. 

Dimension names can be changed.

▷ Change Creo Model

 

Change Creo Model and Get Volume Values (Creo 9.0)

Change the dimensions of a Creo model in Excel.Use the promised dimension name.Get measured volume values ​​automatically calculated in Creo.  You can develop various template programs using the code below.▷Main CodeOption ExplicitSub Mode

tool-2020.tistory.com

 

korealionkk@gmail.com


 

'VBA, VB.NET For Creo' 카테고리의 다른 글

How to display all model names in a session  (0) 2025.03.11
Output the currently active 3D model name  (0) 2025.03.11
Installation and setup for using Creo VBA  (0) 2025.03.10
IpfcSurface  (0) 2025.02.01
Creo] IpfcModel  (0) 2025.02.01