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

Feature Delete - V2

by ToolBOX01 2021. 2. 9.
반응형

Feature Delete - V1이 어려워 프로그램 안에서 선택한 Feature를 삭제하는 프로그램 입니다.

 

 


Sub feature_delete()

    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
    
    Dim oFeatures As IpfcFeatures
    Set oFeatures = oSolid.ListFeaturesByType(False, EpfcFeatureType.EpfcFeatureType_nil)
    Dim oFeature As IpfcFeature
    Set oFeature = oFeatures.Item(9)

    Dim featureOperations As New CpfcFeatureOperations
    Dim oDeleteOperation As IpfcDeleteOperation
    Set oDeleteOperation = oFeature.CreateDeleteOp
    oDeleteOperation.Clip = True
    
    Dim oRegenInstructionsCreate As New CCpfcRegenInstructions
    Dim regenInstructions As IpfcRegenInstructions
    Set regenInstructions = oRegenInstructionsCreate.Create(True, True, Nothing)
    regenInstructions.UpdateInstances = False
    
    Call featureOperations.Append(oDeleteOperation)
    Call oSolid.ExecuteFeatureOps(featureOperations, regenInstructions)
    Call oSession.CurrentWindow.Refresh
    
    'Disconnect with Creo
    conn.Disconnect (2)
    
End Sub

 


▶ Creo 모델에서 Feature들을 모두 가져오는 코팅 입니다

Set oFeatures = oSolid.ListFeaturesByType(False, EpfcFeatureType.EpfcFeatureType_nil)

 

9번째 Feature를 선택 합니다

Set oFeature = oFeatures.Item(9)

 

선택된 Feature를 삭제 하는 코딩 입니다.

Call oSolid.ExecuteFeatureOps(featureOperations, regenInstructions)

 

* 주의 사항 :  Feaure를 삭제 하면 참조 관계가 있는 자식 Feature가 있습니다. 강제적으로 삭제하도록 코딩 했습니다. 

oDeleteOperation.Clip = True

 

또한 Feature 삭제 함수에서 regen 명령을 수행 합니다.  config.pro 에서 regen_failure_handing 값을
resolve_mode를 사용 해야 합니다.

 

FEATURE DELETE v3.xlsm
0.02MB

 

korea.prt.1
0.17MB

 

비즈니스 문의 lionkk@idt21c.com