Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hello everyone,
If you want the long version read on, else see the question in bold below.
This is a tricky one to explain, but here goes. I am in the midst of developing a system that uses a PHP based website to send a shed load of parameter values to a remote computer, who then sends back geometry that is created on the fly... As the design of each part is largely procedural, defining a parameter set and sending it allows anyone without CAD skills to design a unique part and the tooling to make it (all done automatically ;0). I use excel on the remote computer to do some calculations that are not validation specific (that is done in PHP) and then I use the VB API to get creo to work it's magic...
So far so good, everything works nicely. The first system is up and running. My colleagues are happy, and non designers can make their tooling cad. This could leave me put my feet up, however as luck would have it, I have decided to go further down the rabbit hole.
The problem arises because the best (and maybe only) way to make my new target geometry is to use a pattern table. Not a family table. The reason for this is that I have a part that has 198 potential positional references, and 3 potential geometry modifications at each of these references. A pattern table is really cool because I can just create the table with the right geometry info at the right places, and this can be done by my aformentioned colleagues via the interweb... If I did this with a family table i would need to physically model every possible geometry modification, and then use pro/program to turn on/off instances using parameters passed via a family table. Way too much work, and this should be possible to do programmatically.
Would anyone know how to force an update of the table (.ptb file) in a pattern table via the VB API?
I have not seen a method that allows for choosing a particular .ptb file via the API. I did wonder about a Mapkey, but it seems like a risky option. I am open to suggestions or if someone has a differnet method to achieve a similar result, I'm all ears.
Solved! Go to Solution.
well,
if anyone is interested, I have taken a brute force approach to this and I have done as follows....
First, record a Mapkey... then I have made a subroutine for the API:
'---------------------------------------------------------------------------------------------------------------------------------------------------
Sub JJJ()
Dim JJ As String 'this is the stripped down info that can be used in the API , you can find this in your mapkey...
JJ = "~ Select `main_dlg_cur` `PHTLeft.AssyTree` 1 `node2`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ RButtonArm `main_dlg_cur` `PHTLeft.AssyTree` `node2`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ PopupOver `main_dlg_cur` `PM_PHTLeft.AssyTree` 1 `PHTLeft.AssyTree`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Open `main_dlg_cur` `PM_PHTLeft.AssyTree`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Close `main_dlg_cur` `PM_PHTLeft.AssyTree`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Command `ProCmdRedefine@PopupMenuTree` ;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Activate `main_dlg_cur` `maindashInst0.ui_pat_table_quick_edit`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Activate `main_dlg_cur` `dashInst0.stdbtn_1`;"
MsgBox JJ 'in case you want to check some formatting
session.RunMacro (JJ)
End Sub
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------
that bit basically does the edit table info...
then comes the fun. I have set the config option part_table_editor to editor
and the config option pro_editor_command to run a VBS script instead of excel or anything else...
The VBS script works as follows:
'--------------------------------------------------------------------------------
on error resume next
filenamesent = WScript.Arguments.Item(0) '---- this captures the name of whatever CREO is appending to cmd/notepad etc.. to edit
dim filesys
Dim fso
dim del_file
set filesys = CreateObject("Scripting.FileSystemObject")
set fso = CreateObject("Scripting.FileSystemObject")
dim fullpath
fullpath = fso.getabsolutepathname(filenamesent) '---------- this lets us specifiy using the file CREO sent if we want to
msgbox (fullpath)
strPathFile="C:\Users\uq2253\Desktop\ADA\leader_tmp.ptb" '--------------the temp file created by creo when you specifiy a differnet editor (leader is my table name)
strPathfile2="C:\Users\uq2253\Desktop\ADA\spoof.ptb" '-------------this is the table i create in excel before launching this madness
MsgBox (filenamesent)
if filenamesent = "leader_tmp.ptb" then '------------------ If this file is the argument, here is where the fun starts!!!
set del_file = filesys.GetFile(strPathFile)
del_file.Delete '---------------- I delete that temp file CREO created
MsgBox ("check if deleted leader_tmp.ptb")
filesys.CopyFile strPathfile2, strPathFile '------------------ I create a new version of that file by renaming the table I created in excel
MsgBox ("check if leader_tmp.ptb created")
MsgBox (filenamesent)
MsgBox ("end when parament equals leader_tmp.ptb")
else '------------------------ So if I am not editing a table, or debugging or whatever else, this bit makes sure I can still edit Pro/Program or another
'---------------------- table
MsgBox ("leader_tmp.ptb was not passed as parameter")
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
dim runner
runner = "notepad++.exe" & " " & fullpath 'call notepad with the filenamesent
oShell.run runner
Set oShell = Nothing
end if
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
And Voila.... I can now automate a pattern table regeneration... which basically beats all other methods of pattern generation around the ears with a wet fish, as I can just create instances of my pattern by creating idx lines in the table...(which reduces the amount of work I need to do... which is my main mission in life). Would be worth mentioning that I needed to get a little bit of help from my IT dude for the VBS, and the PHP is not all me either, but I fully assume the role of evil genius who has dreamed this dream...
the reason for having to step into VBS is that I cannot access the table data in VBA/Excel, as CREO wont relinquish control until the CMD prompt that opened the file is closed... This is why the VBS script is so cool... mouhahaha It is a pity though that you cannot access this info via the API, and it does seem somewhat of an oversight.... but meh.
if this helps someone else out there do some cool things awesome. If I am the only person who needs this info, then I have earned a friday afternoon beer!
well,
if anyone is interested, I have taken a brute force approach to this and I have done as follows....
First, record a Mapkey... then I have made a subroutine for the API:
'---------------------------------------------------------------------------------------------------------------------------------------------------
Sub JJJ()
Dim JJ As String 'this is the stripped down info that can be used in the API , you can find this in your mapkey...
JJ = "~ Select `main_dlg_cur` `PHTLeft.AssyTree` 1 `node2`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ RButtonArm `main_dlg_cur` `PHTLeft.AssyTree` `node2`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ PopupOver `main_dlg_cur` `PM_PHTLeft.AssyTree` 1 `PHTLeft.AssyTree`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Open `main_dlg_cur` `PM_PHTLeft.AssyTree`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Close `main_dlg_cur` `PM_PHTLeft.AssyTree`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Command `ProCmdRedefine@PopupMenuTree` ;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Activate `main_dlg_cur` `maindashInst0.ui_pat_table_quick_edit`;\"
JJ = JJ & vbCrLf
JJ = JJ & "~ Activate `main_dlg_cur` `dashInst0.stdbtn_1`;"
MsgBox JJ 'in case you want to check some formatting
session.RunMacro (JJ)
End Sub
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------
that bit basically does the edit table info...
then comes the fun. I have set the config option part_table_editor to editor
and the config option pro_editor_command to run a VBS script instead of excel or anything else...
The VBS script works as follows:
'--------------------------------------------------------------------------------
on error resume next
filenamesent = WScript.Arguments.Item(0) '---- this captures the name of whatever CREO is appending to cmd/notepad etc.. to edit
dim filesys
Dim fso
dim del_file
set filesys = CreateObject("Scripting.FileSystemObject")
set fso = CreateObject("Scripting.FileSystemObject")
dim fullpath
fullpath = fso.getabsolutepathname(filenamesent) '---------- this lets us specifiy using the file CREO sent if we want to
msgbox (fullpath)
strPathFile="C:\Users\uq2253\Desktop\ADA\leader_tmp.ptb" '--------------the temp file created by creo when you specifiy a differnet editor (leader is my table name)
strPathfile2="C:\Users\uq2253\Desktop\ADA\spoof.ptb" '-------------this is the table i create in excel before launching this madness
MsgBox (filenamesent)
if filenamesent = "leader_tmp.ptb" then '------------------ If this file is the argument, here is where the fun starts!!!
set del_file = filesys.GetFile(strPathFile)
del_file.Delete '---------------- I delete that temp file CREO created
MsgBox ("check if deleted leader_tmp.ptb")
filesys.CopyFile strPathfile2, strPathFile '------------------ I create a new version of that file by renaming the table I created in excel
MsgBox ("check if leader_tmp.ptb created")
MsgBox (filenamesent)
MsgBox ("end when parament equals leader_tmp.ptb")
else '------------------------ So if I am not editing a table, or debugging or whatever else, this bit makes sure I can still edit Pro/Program or another
'---------------------- table
MsgBox ("leader_tmp.ptb was not passed as parameter")
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
dim runner
runner = "notepad++.exe" & " " & fullpath 'call notepad with the filenamesent
oShell.run runner
Set oShell = Nothing
end if
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
And Voila.... I can now automate a pattern table regeneration... which basically beats all other methods of pattern generation around the ears with a wet fish, as I can just create instances of my pattern by creating idx lines in the table...(which reduces the amount of work I need to do... which is my main mission in life). Would be worth mentioning that I needed to get a little bit of help from my IT dude for the VBS, and the PHP is not all me either, but I fully assume the role of evil genius who has dreamed this dream...
the reason for having to step into VBS is that I cannot access the table data in VBA/Excel, as CREO wont relinquish control until the CMD prompt that opened the file is closed... This is why the VBS script is so cool... mouhahaha It is a pity though that you cannot access this info via the API, and it does seem somewhat of an oversight.... but meh.
if this helps someone else out there do some cool things awesome. If I am the only person who needs this info, then I have earned a friday afternoon beer!
Hi @BryanMorris,
Fast forward 2 years into the future...
I am using a similar approach, where I create a new ptb from Excel, then use run a mapkey in Creo to replace the existing table pattern with the new table pattern from Excel.
I do run into a weird problem, where the table pattern is not showing the correct family instances (the "Model" column). The table pattern has the correct info, but the pattern itself is not showing those family instances.
Have you seen this problem?