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

Get the parameter value in the feature

by ToolBOX01 2023. 2. 8.
반응형

■ "IpfcModelItem"를 이용 하여, 모델이 가지고 있는 요소들을 가져 올수 있습니다.

The possible types of model item are as follows:

  • ITEM_FEATURE
  • ITEM_SURFACE
  • ITEM_EDGE
  • ITEM_COORD_SYS
  • ITEM_AXIS
  • ITEM_POINT
  • ITEM_QUILT
  • ITEM_CURVE
  • ITEM_LAYER
  • ITEM_NOTE
  • ITEM_DIMENSION
  • ITEM_REF_DIMENSION

아래 코드는 모델이 가지고 있는  Featrue의 총 수량은 몇개인가 알아보는 것 입니다

Dim oModelowner As IpfcModelItemOwner
Set oModelowner = oModel
 
Dim oModelitems As IpfcModelItems
Set oModelitems = oModelowner.ListItems(EpfcModelItemType.EpfcITEM_FEATURE)
 
MsgBox oModelitems.count

 

 "IpfcModelItemOwner"은 모델안에 있는 연결된 개체의 기본 클래스입니다.

1) IpfcModelItemOwner.GetItemById (Type as IpfcModelItemType, Id as Long)
- 식별자와 유형이 지정된 지정된 모델 항목을 반환합니다.
   set IpfcModelItem = pfcModelItemOwner.GetItemById(EpfcModelItemType.EpfcITEM_FEATURE, 3001)
   Msgbox  IpfcModelItem.GetName

2) IpfcModelItemOwner.GetItemByName (Type as IpfcModelItemType, Name as String)
- 문자열 이름과 유형이 있는 경우 모델 항목을 반환합니다.

3) IpfcModelItemOwner.ListItems
- 지정된 유형의 모델 항목 목록을 제공합니다.
- EpfcModelItemType (Solid models, 2D models)을 가져 올수 있습니다.

EpfcITEM_FEATURE (Feature
EpfcITEM_SURFACE (Surface
EpfcITEM_EDGE (Edge
EpfcITEM_COORD_SYS (Coordinate system
EpfcITEM_AXIS (Axis
EpfcITEM_POINT (Point
EpfcITEM_QUILT (Quilt
EpfcITEM_CURVE (Curve
EpfcITEM_LAYER (Layer
EpfcITEM_NOTE (A solid model note
EpfcITEM_DIMENSION (Dimension
EpfcITEM_REF_DIMENSION (Reference dimension
EpfcITEM_SIMPREP (Simplified representation
EpfcITEM_SOLID_GEOMETRY (A solid geometry layer item.
EpfcITEM_TABLE (A drawing table
EpfcITEM_DTL_ENTITY (A detail entity
EpfcITEM_DTL_NOTE (A detail note
EpfcITEM_DTL_GROUP (A detail draft group
EpfcITEM_DTL_SYM_DEFINITION (A symbol definition
EpfcITEM_DTL_SYM_INSTANCE (A symbol instance
EpfcITEM_DTL_OLE_OBJECT (A drawing-embedded OLE object
EpfcITEM_EXPLODED_STATE (An exploded state
EpfcITEM_EDGE_START  
EpfcITEM_LOG_EDGE
EpfcITEM_EDGE_END
EpfcITEM_XSEC (Cross Section
EpfcITEM_LAYER_STATE (Layer state
EpfcITEM_COMBINED_STATE (Combined state
EpfcITEM_STYLE_STATE (Style state
EpfcITEM_RP_MATERIAL (Material Item
EpfcITEM_VIEW (View
EpfcITEM_SURF_FIN
EpfcITEM_ANNOT_PLANE
EpfcITEM_ANNOTATION_ELEM
EpfcITEM_SET_DATUM_TAG
EpfcITEM_GTOL
EpfcITEM_BODY (Solid body
EpfcITEM_CRV_START (Datum Curve Start
EpfcITEM_CRV_END (Datum Curve End
EpfcModelItemType_nil (Use this enumerated value to represent "null" passed to optional properties or method arguments.


 모델의 feature가 가지고 있는 Parameter 값을 표시 합니다.

Feature안에 Parameter를 넣을수 있습니다. 측정 Feature를 만들면 측정된 결과는 자동으로 Parameter가 만들러지고. 값을 저장 합니다. 모델 트리에서 측정 Feature를 "Footer"에 놓아도 측정을 할수 있습니다.

[ 거리 측정 Feature ]

Extrude 1 feature MEASURE_DISTANCE_1

 

■ Part 파일의 Feature Parameter를 가져오는 Code 입니다.

Sub FeatureParam()

    Call Creo_Connect
    
    '// Creo Parameter variable
    
    Dim oModelowner As IpfcModelItemOwner
    Set oModelowner = oModel
    Dim oModelitems As IpfcModelItems
    Set oModelitems = oModelowner.ListItems(EpfcModelItemType.EpfcITEM_FEATURE)
    
    Dim oParameterOwner As IpfcParameterOwner
    Dim oBaseParameter As IpfcBaseParameter
    Dim oParamValue As IpfcParamValue
    Dim oParameter As IpfcParameter
    Dim oCMModelItem As New CMpfcModelItem
    Dim oModelItem As IpfcModelItem
    
    Dim oCellsParameterName As String
    
    Dim oParameters As IpfcParameters
    
    
    Dim i As Integer, j As Integer
    
    
    For i = 0 To oModelitems.Count - 1
    
        Set oParameterOwner = oModelitems(i)
        
        Set oParameters = oParameterOwner.ListParams
        
        If oParameters.Count > 0 Then
        
            For j = 0 To oParameters.Count - 1
            
                Set oBaseParameter = oParameters.Item(j)
                
                Set oParamValue = oBaseParameter.Value
                
                If oParamValue.discr = 0 Then  '// If parameter is string
                
                    MsgBox oParamValue.StringValue
                    
                ElseIf oParamValue.discr = 3 Then '// if parameter is real value
                
                    MsgBox oParamValue.DoubleValue
                    
                
                End If
            
             Next j
        
          End If
        
    Next i
    

End Sub

 

■ Creo와 연결 하는 코드 입니다 (Call Creo_Connect)

Option Explicit
Public asynconn As New pfcls.CCpfcAsyncConnection
Public conn As pfcls.IpfcAsyncConnection
Public oSession As pfcls.IpfcBaseSession
Public oModel As IpfcModel
Public oSolid As IpfcSolid
Public Sub Creo_Connect()

    Application.EnableEvents = False
    
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    '// Creo Connect Check
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    On Error Resume Next
    Set conn = asynconn.Connect("", "", ".", 5)
    
        If conn Is Nothing Then
        
           MsgBox "Error occurred while starting new Creo Parametric Session!", vbInformation, "www.idt21c.com"
           Exit Sub
           
        End If
     '//////////////////////////////////////////////////////////////////////////////////////////////////////
    
    Set oSession = conn.Session
    
    '// Current Model
    Set oModel = oSession.CurrentModel
    Set oSolid = oModel


End Sub

 

Until the day ChatGPT automatically creates codes

By lionkk@idt21c.com