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

4-4 # Parameter : 매개변수 읽고, 쓰기

by ToolBOX01 2020. 12. 10.
반응형

기능 : 매개변수 읽고, 쓰기


1) 재생성  2) SAVE   3) SAVE AS 기능은 없습니다.

 

 

BOX-MODELING.xlsm
0.03MB
prt0002.prt.3
0.09MB

새로 고침 버튼 클릭

 

Sub box_model()

    Dim asynconn As New pfcls.CCpfcAsyncConnection
    Dim conn As pfcls.IpfcAsyncConnection
    Dim session As pfcls.IpfcBaseSession
    Dim Model As pfcls.IpfcModel

    Set conn = asynconn.Connect("", "", ".", 5)
    Set session = conn.session
    Set Model = session.CurrentModel
    Range("H5").Value = Model.Filename

    Dim Powner As pfcls.IpfcParameterOwner
    Dim param As IpfcBaseParameter
    Dim ParamValue As IpfcParamValue
    Dim WIDTH As Double, HEIGHT As Double, LENGTH As Double
    Dim WIDTH_value As Double, height_value As Double, length_value As Double

    Set Powner = Model

   'Read Parameter WIDTH value
   Set param = Powner.GetParam("WIDTH")
   Set ParamValue = param.Value
   WIDTH_value = ParamValue.DoubleValue
   Cells(7, 8) = WIDTH_value

   'Read Parameter HEIGHT value
   Set param = Powner.GetParam("HEIGHT")
   Set ParamValue = param.Value
   height_value = ParamValue.DoubleValue
   Cells(10, 8) = height_value

   'Read Parameter LENGTH value
   Set param = Powner.GetParam("LENGTH")
   Set ParamValue = param.Value
   length_value = ParamValue.DoubleValue
   Cells(13, 8) = length_value

   'Disconnect with Creo
   conn.Disconnect (2)

  'Cleanup
  Set asynconn = Nothing
  Set conn = Nothing
  Set session = Nothing
  Set Model = Nothing
End Sub


가로 버튼 Source

Sub input_width()

   Dim asynconn As New pfcls.CCpfcAsyncConnection
   Dim conn As pfcls.IpfcAsyncConnection
   Dim session As pfcls.IpfcBaseSession
   Dim Model As pfcls.IpfcModel
   Dim WIDTH_filename As String

   Set conn = asynconn.Connect("", "", ".", 5)
   Set session = conn.session
   Set Model = session.CurrentModel

   Dim paramOwner As pfcls.IpfcParameterOwner
   Dim WidthParam As pfcls.IpfcBaseParameter
   Dim p1 As IpfcParameter
   Dim ParamObject As New CMpfcModelItem
   Dim ParamValue As pfcls.IpfcParamValue
   Dim WIDTH_value As Double
   Dim p2 As String

   p2 = "width"
   Range("H7").Select
   WIDTH_value = ActiveCell.Value

   Set paramOwner = Model
   Set p1 = paramOwner.GetParam(p2)
   Set WidthParam = p1
   Set ParamValue = ParamObject.CreateDoubleParamValue(CDbl(WIDTH_value))
   WidthParam.Value = ParamValue

'Disconnect with Creo
conn.Disconnect (2)

'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set session = Nothing
Set Model = Nothing

End Sub