모델이 가지고 있는 치수 값을 불러오고, 사용자는 엑셀에서 치수 값을 변경 합니다.
■ "치수 값 불러오기" 버튼
- 모델에서 치수 값을 불러옵니다
■ "치수 변경" 버튼
- 엑셀에 입력한 치수 값을 모델에 반영 합니다.
>> 치수 변경 코드
Option Explicit
Sub Main()
Application.EnableEvents = False
On Error GoTo RunError
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As pfcls.IpfcBaseSession: Set oSession = conn.Session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
Dim oSolid As IpfcSolid: Set oSolid = oModel
'// 활성화된 모델의 폴더 이름과 모델 이름을 표시
'// Cells(1, "B") = oSession.GetCurrentDirectory
'// Cells(2, "B") = oModel.Filename
'// 엑셀에 정의 되어 있는 치수 이름의 값을 가지고 오기
Dim Modelowner As IpfcModelItemOwner: Set Modelowner = oSolid
Dim oBaseDimension As IpfcBaseDimension
Dim oDimName As String
Dim i As Integer
Dim oDimNameCount As Integer
oDimNameCount = Cells(4, Columns.Count).End(xlToLeft).Column
'// SET Regenerate
Dim RegenInstructions As New CCpfcRegenInstructions
Dim oInstrs As IpfcRegenInstructions
Set oInstrs = RegenInstructions.Create(False, False, Nothing)
For i = 0 To oDimNameCount - 1
oDimName = Cells(4, i + 1)
Set oBaseDimension = Modelowner.GetItemByName(EpfcModelItemType.EpfcITEM_DIMENSION, oDimName)
oBaseDimension.DimValue = Cells(5, i + 1)
'// Regenerate 실행
Call oSolid.Regenerate(oInstrs)
Next i
'// Window Repaint
Dim oWindow As pfcls.IpfcWindow
Set oWindow = oSession.CurrentWindow
oWindow.Repaint
MsgBox "모델을 변경 하였습니다.!", vbInformation, "www.idt21c.com"
conn.Disconnect (2)
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set oSession = Nothing
Set oModel = Nothing
RunError:
If Err.Number <> 0 Then
MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
"Error No: " + CStr(Err.Number) + Chr(13) + _
"Error: " + Err.Description, vbCritical, "Error"
If Not conn Is Nothing Then
If conn.IsRunning Then
conn.Disconnect (2)
End If
End If
End If
End Sub
모델의 치수 이름은 추가 될수 있습니다. 아래 코드를 이용하여 "4 열"에 치수 이름을 추가 할수 있습니다
아래 코드는 4열의 치수 이름 개수를 반환 받는 코드 입니다
Dim oDimNameCount As Integer
oDimNameCount = Cells(4, Columns.Count).End(xlToLeft).Column
엑셀 VBA 마지막 행과 열의 수 찾기
■ 행의 개수 알아보는 방법 Sub colrownum() Dim lastRow As Long lastRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row MsgBox "1번행의 개수: " & lastRow End Sub ■ 열의 개수 알아보는 방법 Sub colrownum2() Dim lastColumn As Long lastC
morphys.tistory.com
VBA는 Cell로 시작해서 Cell로 끝납니다. 그만큰 중요합니다.
cell에 입력된 값을 모델에 전달 합니다
oDimName = Cells(4, i + 1)
Set oBaseDimension = Modelowner.GetItemByName(EpfcModelItemType.EpfcITEM_DIMENSION, oDimName)
oBaseDimension.DimValue = Cells(5, i + 1)
모델의 치수 값을 반영 합니다 (모델을 변경 합니다 - Regenerate)
'// SET Regenerate
Dim RegenInstructions As New CCpfcRegenInstructions
Dim oInstrs As IpfcRegenInstructions
Set oInstrs = RegenInstructions.Create(False, False, Nothing)
'// Regenerate 실행
Call oSolid.Regenerate(oInstrs)
Creo 화면을 업데이트 합니다'// Window Repaint
Dim oWindow As pfcls.IpfcWindow
Set oWindow = oSession.CurrentWindow
oWindow.Repaint
위 기능을 활용하여 Template 모델을 만들어 보십시요. 또한 Form 기능을 이용하여, 입력을 편리하게 할 수 있습니다.
[VBA] Userform 만들기
Userform 이 글에서는 Excel VBA Userform을 어떻게 생성하는지를 보여드립니다. 여기서는 아래와 같은 userform을 만들어 보겠습니다. .. Add the Controls Userform에 control들을 추가하려면 아래와 같이 하세요.
coronasdk.tistory.com
>> Template 모델 개발 화면 예시
>> Reference
Template 프로그램 #1
■ 소개 VBA 프로그램을 사용하여 자동으로 Creo 프로그램을 실행 할수 있습니다. 또한 Creo part 파일을 자동으로 open 할수 있습니다. 입력한 치수값을 모델에 대입하고, 새로운 Creo 파일 (3D, 2D)를 생
tool-2020.tistory.com
Template 프로그램 #2
■ 새로운 파일 이름으로 저장 하기 1. Backup 코드 Template 파일은 3D 이름과 동일한 2D 파일로 구성 되어야 하고, Search_parth로 정의되어 있어야 합니다. 또한 설계자가 입력한 Work Folder에 저장 합니다
tool-2020.tistory.com
'VBA, VB.NET For Creo' 카테고리의 다른 글
IpfcViewOwner (0) | 2023.01.16 |
---|---|
IpfcWindow (0) | 2023.01.16 |
모델이 가지고 있는 치수 값을 가지고 오기 (0) | 2023.01.14 |
Creo VBA 시작 코드 (0) | 2023.01.14 |
Coordinate Systems and Transformations (0) | 2023.01.13 |