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

Select a parameter to delete it from the model

by ToolBOX01 2024. 9. 15.
반응형

▷ Reference

 

Get the Parameter name of the model and delete it

□ Code to get the model's ParameterGets the number of parameters the model has.Gets the parameters name that the model has.Gets the value of the parameters name that the model has.Gets the types of parameters that the model has.  □ Mai

tool-2020.tistory.com

 

□ introduction

  • Select and retrieve the Parameter name from the Cell.
  • The selected parameters will be deleted.
  • Save the model

 

▷ Code to select a cell and get parameter names

Option Explicit
Public selectcellname() As Variant
Public selectcellcount As Integer
Public Sub ShowSelectedCellValue()
    Dim selectedCell As Range
    Dim cell As Range
    Dim i As Integer
    
    Set selectedCell = Selection
    selectcellcount = selectedCell.Count
    
    '// Set array size to fit the number of selected cells
     ReDim selectcellname(1 To selectedCell.Count)


    '// If there are multiple values ??in the selected cell, each is displayed
    If selectedCell.Count > 1 Then
    
         i = 1
        For Each cell In selectedCell
            selectcellname(i) = cell.Value
            i = i + 1
        Next cell

    Else
         '// If the selected cell has only one value
        ReDim selectcellname(1 To 1) '// Set array size to 1
        selectcellname(1) = selectedCell.Value
        
    End If
End Sub

 

cellselete01.bas
0.00MB

 

▷ Main Code

Sub deleteparameter()

    On Error GoTo RunError

    '// Module Name : CreoVBAStart
    Call CreoVBAStart.CreoConnt01
    
    Call cellselete01.ShowSelectedCellValue
    
    Dim ParameterOwner As pfcls.IpfcParameterOwner
    Dim Parameter As IpfcParameter
    
    Dim i As Integer
    
    Set ParameterOwner = model
    
    For i = 1 To selectcellcount
    
              Set Parameter = ParameterOwner.GetParam(selectcellname(i))
              Parameter.Delete
    Next i

    MsgBox "Delete Model Parameter Name", 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
            
               Dim ErrorMessage As String
               ErrorMessage = ErrorHandlerModule.MapErrorToMessage(Err.Number) '// Calling a function from a ErrorHandlerModule  module
        
               MsgBox "Process Failed: " & vbCrLf & _
               "Error No: " & CStr(Err.Number) & vbCrLf & _
               "Description: " & ErrorMessage, vbCritical, "Error"
                       
                If Not conn Is Nothing Then
                    If conn.IsRunning Then
                        conn.Disconnect (2)
                    End If
                End If
            End If

End Sub

 

You can get the parameter name that the model has.
You can remove unnecessary parameter names from the model.
You can create the parameter names you need.
You can import Creo models stored on your hard disk.
You can start and close Creo programs with VBA.
You can read over 100,000 Creo files and clean up unnecessary parameters.

Creo models contain a lot of design information. Design information is represented by parameters, annotations, dimensions, and holes. If the design information is stored accurately, machine learning is possible.

With CAD data in the cloud, machines will learn along with design information and images.