반응형
모델에 String 타입의 매개변수 값을 입력 합니다.
■ 소스 코드
Parameter는 IpfcParameterOwner 부터 시작 하여 코드를 작성 합니다. IpfcBaseParameters는 Parameter와 Dimension 값을 가져옵니다.
Option Explicit
Sub part_parameter()
On Error GoTo RunError
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim oBaseSession As pfcls.IpfcBaseSession
Dim oModel As pfcls.IpfcModel
Set conn = asynconn.Connect("", "", ".", 5)
Set oBaseSession = conn.session
Set oModel = oBaseSession.CurrentModel
'엑셀파일에 있는 Parameter List Count
Dim oColumnscount As Long: oColumnscount = Cells(6, Columns.Count).End(xlToLeft).Column
'Parameter
Dim oParameterOwner As IpfcParameterOwner
Dim oBaseParameter As IpfcBaseParameter
Dim oParamValue As IpfcParamValue
Dim oParameter As IpfcParameter
Dim oCMModelItem As New CMpfcModelItem
Dim oModelItem As IpfcModelItem
Dim i As Long
Dim oCellsParameterName As String
For i = 0 To oColumnscount - 1
Set oParameterOwner = oModel
oCellsParameterName = Cells(6, i + 1).Value
Set oParameter = oParameterOwner.GetParam(oCellsParameterName)
Set oBaseParameter = oParameter
Set oParamValue = oCMModelItem.CreateStringParamValue(Cells(7, i + 1))
oBaseParameter.Value = oParamValue
Next i
oModel.save
'Disconnect with Creo
conn.Disconnect (2)
Exit Sub
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
part parameter v01.xlsm
0.02MB
모델에 Parameter를 만들고, 엑셀에 입력한 값을 모델에 저장 합니다.
■ 소스 코드
Sub CreateParameter()
On Error GoTo RunError
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim oBaseSession As pfcls.IpfcBaseSession
Dim oModel As pfcls.IpfcModel
Set conn = asynconn.Connect("", "", ".", 5)
Set oBaseSession = conn.session
Set oModel = oBaseSession.CurrentModel
Dim oBaseParameter As IpfcBaseParameter
Dim oParameterOwner As IpfcParameterOwner
Dim oParameter As IpfcParameter
Dim oParamValue As IpfcParamValue
Dim oCMModelItem As New CMpfcModelItem
Set oParameterOwner = oModel
'Parameter Create
Set oParamValue = oCMModelItem.CreateStringParamValue(Cells(5, "I"))
Set oBaseParameter = oParameterOwner.CreateParam(Cells(4, "I"), oParamValue)
'Disconnect with Creo
conn.Disconnect (2)
Exit Sub
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
'VBA, VB.NET For Creo' 카테고리의 다른 글
ToolBOX PartList 베타 (0) | 2022.10.27 |
---|---|
모델의 Parameter 이름 및 타입, 값 과 엑셀 내용과 비교 (0) | 2022.10.25 |
작업 폴더에 있는 Drawing 파일 인쇄 ver 0.1 - PCF (0) | 2022.10.13 |
작업 폴더에 있는 Drawing 파일 인쇄 ver0.1 - PDF 변환 (0) | 2022.10.11 |
Creo Drawing 파일 PDF 변환 하기 (0) | 2022.10.11 |