美文网首页
Creo open prt

Creo open prt

作者: 锦囊喵 | 来源:发表于2020-05-11 09:54 被阅读0次

https://community.ptc.com/t5/Assembly-Design/ProE-VBA-API-examples/td-p/44157

This example connects to an open Pro/ENGINEER session and retrieves part PRT0001 and access its Family table instances and displays their names.


Sub Main2()
'
' This routine will open a Pro/E file from your WorkingDirectory in a new window:
'
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
Dim oModel As pfcls.IpfcModel

'Make an asynchronous connection with Pro/ENGINEER
Set conn = asynconn.Connect("", "", ".", 5)

'Get the current session
Set session = conn.session

'Show the current Working Directory
MsgBox "This is the current Working Directory: " & vbCrLf & session.GetCurrentDirectory

'Create a modeldescriptor to the Pro/E Model
Dim oModelDescriptorCreate As New CCpfcModelDescriptor
Dim oModelDescriptor As IpfcModelDescriptor
Set oModelDescriptor = oModelDescriptorCreate.Create(EpfcMDL_PART, "PRT0001.PRT", Null)

'Retrieve the model into the oModel handle
Set oModel = session.RetrieveModel(oModelDescriptor)


'Create a new window which displays the Pro/E Model
Dim oWindow As pfcls.IpfcWindow
Set oWindow = session.OpenFile(oModelDescriptor)

'Activate the new window
oWindow.Activate


'Show the name of the Pro/E Model in a messagebox
MsgBox "Model name = " & oModel.Filename
'
Dim A As IpfcBaseParameter
Dim Av As IpfcParamValue
Dim newA As IpfcParamValue
Dim A_value As Double
Dim generic As IpfcFamilyMember
Dim rows As IpfcFamilyTableRows
Dim row As IpfcFamilyTableRow
Dim InstName As String

'Declare (make) the Model as a IpfcFamilyMember type object
Set generic = oModel
' list the ROws of family table. If the part is not a generoc, there will be 0 rows
Set rows = generic.ListRows()

' Now, get each row and print the instance name. Once each instance is obtained, do rewquired operations
For Each row In rows
InstName = row.InstanceName
MsgBox "Fam Instance Name: " & InstName
Next

'Disconnect with Pro/ENGINEER
conn.Disconnect (2)

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

End Sub

相关文章

网友评论

      本文标题:Creo open prt

      本文链接:https://www.haomeiwen.com/subject/opmynhtx.html