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

변수 선언 : CREO 활성화된 Window 연결

by ToolBOX01 2024. 4. 10.
반응형

□ 변수 선언과 Creo VBA

  • Dim : 동일 프로시저 또는 모듈 내에서만 사용하는 변수를 선언
  • Private : 동일 모듈 내에서 공용으로 사용 하는 변수를 선언
  • Public : 문서 내 모든 모듈에서 공용으로 사용 하고 싶은 변수를 선언

⊙ 참고 동영상

 

⊙ 참고 블로그

 

[엑셀 VBA] Private, Public 문을 사용하는 변수 사용

VBA초급 시절에는 모든 변수 설정은 Dim으로 하게 되지만 중급~고급으로 넘어가면서 만들어야 하는 Sub가 많아지면서 변수 선언이 많이 겹치게 된다. (특히 i as Integer 같은) 그럴 때 모든 Sub(프로시

separang.tistory.com

 

⊙ VBA 기초 학습 자료

 

[VBA] 객체(Object) 완벽 가이드

이 포스트는 Excel Macro Mastery 사이트의 'VBA Objects - The Ultimate Guide(by Paul Kelly)'의 내용을 다시 정리한 것입니다. 이번 포스트에서는 엑셀 VBA의 객체 대해 다룹니다. Quick Guide Task Examples 객체의 선언

kukuta.tistory.com

 


□ 현재 활성화돤 모델 이름 및 작업 폴더 이름 가져오기

Gets the model name and working folder name of the active window in Creo

 

[In Excel VBA]
[In Creo Parametric]

CreoVbaStart ()

Option Explicit

Sub CreoVbaStart()
     On Error GoTo RunError
     Application.EnableEvents = False
     
     '// Check Creo Connect
     Dim asynconn As New pfcls.CCpfcAsyncConnection
     Dim conn As pfcls.IpfcAsyncConnection
     Dim BaseSession As pfcls.IpfcBaseSession
     Dim Session As IpfcSession
     Dim model As pfcls.IpfcModel
     
     Set conn = asynconn.Connect("", "", ".", 5)
     Set BaseSession = conn.Session
     Set Session = BaseSession
     Set model = BaseSession.CurrentModel
     
     If model Is Nothing Then
        MsgBox "There are No Active Creo Models", vbInformation, "www.idt21c.com"
        Exit Sub
    End If
     
     
     '// Current Model Information
     Cells(2, "D") = BaseSession.GetCurrentDirectory
     Cells(3, "D") = model.Filename
     
     Call Session.UIShowMessageDialog("Message to show inside Creo", Nothing)
     
    
     conn.Disconnect (2)
    
    ' // Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set BaseSession = Nothing
    Set model = Nothing
    
Exit Sub

RunError:
            If Err.Number <> 0 Then
                MsgBox "Process Failed: An error occurred." & vbCrLf & _
                       "Error No: " & CStr(Err.Number) & vbCrLf & _
                       "Error Description: " & Err.Description & vbCrLf & _
                       "Error Source: " & Err.Source, vbCritical, "Error"
                If Not conn Is Nothing Then
                    If conn.IsRunning Then
                        conn.Disconnect (2)
                    End If
                End If
            End If
End Sub

 


Applications

Create two modules. Executes procedures in other modules

CreoVBAStart()

Option Explicit
Public Session As IpfcSession

Sub CreoVBAStart()
     On Error GoTo RunError
     Application.EnableEvents = False
    
    
    .
    .
    .
    .
    .
    .
    .
    MessageDialog
    
    .
    .

MessageDIalig()

MessageDialog()

Option Explicit
Sub MessageDialog()

    Call Session.UIShowMessageDialog("Message to show inside Creo", Nothing)

End Sub

 

good luck !


Inquire  : lionkk@idt21c.com