본문 바로가기
  • 환영 합니다 ! Welcome!
VBA For Creo

#7 IpfcBaseSession.Select() : Feature 선택 하기

by ToolBOX01 2022. 10. 2.
반응형

모델에서 Feature를 선택 하고, 선택된 Feature의 타입을 표시 합니다.

 

필터 기능을 통해 선택하고자 하는 타입을 선택 합니다.

Set oSelectionOptions = oSelectionOptionsCreate.Create("feature")

 

Creo 선택 메뉴에서 여러개를 선택 할수 있도록 "-1" 값을 입력 합니다.

 

Sub FeatureSlectBox()

    Dim asynconn As New pfcls.CCpfcAsyncConnection
    Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
    Dim oSession As IpfcBaseSession: Set oSession = conn.Session
    Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
    Dim oSolid As IpfcSolid: Set oSolid = oModel
    
    ' Select Filter
    Dim oSelectionOptionsCreate As New CCpfcSelectionOptions
    Dim oSelectionOptions As IpfcSelectionOptions
        Set oSelectionOptions = oSelectionOptionsCreate.Create("feature")
    
    'The maximum number of selections allowed. If this is a negative number, 
    'there is an unlimited number of selections.
    oSelectionOptions.MaxNumSels = -1
      
    '마우스로 Feature를 선택
    Dim oSelections As CpfcSelections
    Set oSelections = oSession.Select(oSelectionOptions, Nothing)
    Dim oSelection As IpfcSelection
    Dim oFeature As IpfcFeature
    Dim i As Long
    
    For i = 0 To oSelections.Count - 1
    
        Set oSelection = oSelections.Item(i)
        Set oFeature = oSelection.SelItem
    
        MsgBox oFeature.FeatTypeName
        
    Next i
    

            
    'Disconnect with Creo
    conn.Disconnect (2)
    
End Sub

프로그램을 실행 하면  아래와 같이 선택 메뉴 창이 실행 됩니자

 

취소 버튼을 클릭하면. VBA 스크립트 오류가 발생 합니다. 취소 버튼 기능은 코딩 하지 않았습니다.

 

By lionkk@idt21c.com