업무 자동화/VBA, VB.NET For Creo
Creo VBA : 서피스 분석 - 실린더 면적 계산
ToolBOX01
2025. 11. 18. 14:32
반응형
◎ 실린더 면적 계산(Calculating cylinder area)
구멍의 실린더 면적 (곡면 면적 또는 전체 표면적)을 계산하는 프로그램을 만들기. 이를 위해 객체의 지오메트리적 속성을 얻는 데 사용되는 pfcSurface 인터페이스와 그 메서드를 활용해야 합니다
Create a program that calculates the cylindrical area (or surface area) of a hole. To do this, you must utilize the pfcSurface interface and its methods, which are used to obtain geometric properties of an object.
💻 Sample code
' //----------------------------------------------------------------------
' Creo Parametric VBA API를 사용하여 활성 모델 내 모든 실린더 면(구멍 면 포함)의
' 표면적을 자동으로 계산합니다.
'
' 필수 설정:
' Connect.CreoConnect 함수는 세션 연결을 위한 사용자 정의 모듈이라고 가정합니다.
'---------------------------------------------------------------------- //'
Sub CalculateCylinderSurfaceArea()
'// 에러 발생 시 ErrorHandler 레이블로 이동 //'
On Error GoTo ErrorHandler
'// Creo 세션에 연결 (사용자 정의 함수라고 가정) //'
Call Connect.CreoConnect
'// Interface IpfcModel (활성 모델 가져오기) //'
Dim CurrentModel As pfcModel
Set CurrentModel = BaseSession.CurrentModel
If CurrentModel Is Nothing Then
MsgBox "Creo Parametric에서 활성화된 모델이 없습니다.", vbCritical, "오류"
Exit Sub
End If
'// Interface IpfcModelItemOwner (아이템 소유자로 캐스팅) //'
Dim ItemOwner As pfcModelItemOwner
Set ItemOwner = CurrentModel
'// 서피스 아이템 목록 가져오기 //'
'// EpfcITEM_SURFACE를 사용하여 모델 내 모든 서피스 아이템을 가져옵니다.//'
Dim SurfaceList As pfcModelItems
Set SurfaceList = ItemOwner.ListItems(pfcModelItemType.EpfcITEM_SURFACE)
Dim SurfaceItem As pfcModelItem
Dim SurfaceObject As pfcSurface '// Interface IpfcSurface //'
Dim Report As String
Dim ItemName As String
Dim SurfaceArea As Double
Report = "--- 실린더 서피스 면적 보고서 ---" & vbCrLf
Report = Report & "모델 이름: " & CurrentModel.FileName & vbCrLf & vbCrLf
Dim FoundCount As Integer
FoundCount = 0
'// Interface IpfcModelItem (목록 반복) //'
For Each SurfaceItem In SurfaceList
'// 서피스 이름을 가져옵니다. (Creo에서 자동 생성된 이름일 수 있음) //'
ItemName = SurfaceItem.Name
'// Interface IpfcSurface (서피스 객체로 캐스팅) //'
If TypeOf SurfaceItem Is pfcSurface Then
Set SurfaceObject = SurfaceItem
'// 서피스 타입이 실린더(CYLINDER)인지 확인합니다. (구멍 면을 찾기 위해) //'
If SurfaceObject.SurfaceType = pfcSurfaceType.EpfcSURFACE_CYLINDER Then
'// 실린더 서피스의 면적을 계산합니다. //'
' pfcSurface 인터페이스의 EvalArea() 메서드를 사용합니다.
' 이 메서드는 서피스의 표면적을 반환합니다.
SurfaceArea = SurfaceObject.EvalArea
'// 결과 문자열에 추가합니다. //'
Report = Report & "이름: " & ItemName & " | " & "면적: " & Format(SurfaceArea, "0.000") & vbCrLf
FoundCount = FoundCount + 1
End If
End If
Next SurfaceItem
Report = Report & vbCrLf & "총 발견된 실린더 면 개수: " & FoundCount & vbCrLf
If FoundCount = 0 Then
Report = Report & "이 모델에서 실린더 서피스(EpfcSURFACE_CYLINDER)를 찾지 못했습니다."
End If
' 결과 출력
MsgBox Report, vbInformation, "실린더 면적 계산 결과"
Exit Sub
ErrorHandler:
' 연결 또는 API 호출 중 오류 발생 시 처리
MsgBox "VBA 실행 중 오류가 발생했습니다: " & Err.Description, vbCritical, "API 오류"
End Sub
Module name CreoConnect Code (module name : Connect)
Creo 자동 프로그램 만들기 #2 - beginner
◎ Creating a VBA moduleCreating a VBA module to connect to Creo Parametric. Procedures within a module can be called directly from anywhere in the project, such as Module1.MyProcedure (if declared Public). ✨ Module name CreoConnect Code (module name :
tool-2020.tistory.com
by korealionkk@gmail.com

반응형