braynpower
New member
Hello all,
I am currently in the process of developing a handy little excel spreadsheet to send to a new colleague, so that he can do his newly assigned job easier. Effectively, this spreadsheet is used to modify a list of parameters that define a part whose geometry always follows a set of particular rules. I have got the utility to work good enough such that almost all the operations are working, but I am stuck at an impasse.
I cannot for the life of me (or my work neighbor who is the VBA guru) work out how to send a Regenerate command to my Session through the API.
At this stage I am only trying to make it work on a single part, I am thinking it would be even more fun at a later date to regenerate all the instances of the component in the family table... But baby steps...
Here is the code (that I gratuitously 'copy pasted' from Creo Automation). I perhaps should mention that I am a newbie to VBA, a newbie to CREO's API, and I am probably doing something wrong (or a whole lot of things wrong... but then I'm a creative designer working with a bunch of engineers, so I think it's my right... hehe).
________________________________________________________________________________________
Sub Button1_Click()
'On Error Resume Next
Dim asyncConnection As IpfcAsyncConnection
Dim cAC As CCpfcAsyncConnection
Dim session As IpfcBaseSession
Dim Model1 As IpfcModel
'Defines N - Number of Convolutes
Dim Nx As IpfcParameterOwner
Dim N01, N02 As String
Dim N1 As IpfcParameter
Dim N2 As IpfcBaseParameter
Dim Mitem As CMpfcModelItem
Dim Nv1 As IpfcParamValue
'Create async connection to CREO
Set cAC = New CCpfcAsyncConnection
Set asyncConnection = cAC.Connect(dbnull, dbnull, dbnull, dbnull)
Set session = asyncConnection.session
Set Model1 = session.GetModel("JBA.PRT", EpfcMDL_PART)
'Runs N - Number of Convolutes parameter modification
N01 = "N"
Range("E3").Select
N02 = ActiveCell.Text
Set Nx = Model1
Set N1 = Nx.GetParam(N01)
Set N2 = N1
Set Mitem = New CMpfcModelItem
Set Nv1 = Mitem.CreateDoubleParamValue(CDbl(N02))
N2.Value = Nv1
asyncConnection.Disconnect (1)
End Sub
---------------------------------------------------------------
Now I want to run a regenerate command after the parameter modification... I figure I should be using IpfcSolid.Regenerate() or somesuch, but wouldn't have the foggiest what I need to define, where it should be defined, and how. (Oh, and by the way, there are a lot of different parameter that are modified, I have just shortened the example for the sake of trying to be concise, which I'm not good at).
I have tried to get the API to run a Mapkey also (just CTRL-G for kicks...) but to no avail. I am sure that I am trying to skip a whole lot of useful training, by just thinking I can farm out my uselessness to the Web in search of a solution, but so much of what I have learnt has been done this way.
The thing is, that other than VBug.PDF I have not been able to find any meaningful documentation, or even a training course that I could follow to use this functionality... which to me looks pretty interesting, As I could implement this kind of 'basic' excel to CREO interface for a few of my colleagues, and probably get a few free coffees along the way (I will say though that my complete lack of knowledge of VBA is not helping me here... Perhaps someone could recommend me some interesting VBA based bedtime reading material...).
Any help anyone can offer me with getting my part to regen, would be massively appreciated! Then I'll have a ham-fisted bash at trying to get it work on a family table...
Cheers!
Bryan.
I am currently in the process of developing a handy little excel spreadsheet to send to a new colleague, so that he can do his newly assigned job easier. Effectively, this spreadsheet is used to modify a list of parameters that define a part whose geometry always follows a set of particular rules. I have got the utility to work good enough such that almost all the operations are working, but I am stuck at an impasse.
I cannot for the life of me (or my work neighbor who is the VBA guru) work out how to send a Regenerate command to my Session through the API.
At this stage I am only trying to make it work on a single part, I am thinking it would be even more fun at a later date to regenerate all the instances of the component in the family table... But baby steps...
Here is the code (that I gratuitously 'copy pasted' from Creo Automation). I perhaps should mention that I am a newbie to VBA, a newbie to CREO's API, and I am probably doing something wrong (or a whole lot of things wrong... but then I'm a creative designer working with a bunch of engineers, so I think it's my right... hehe).
________________________________________________________________________________________
Sub Button1_Click()
'On Error Resume Next
Dim asyncConnection As IpfcAsyncConnection
Dim cAC As CCpfcAsyncConnection
Dim session As IpfcBaseSession
Dim Model1 As IpfcModel
'Defines N - Number of Convolutes
Dim Nx As IpfcParameterOwner
Dim N01, N02 As String
Dim N1 As IpfcParameter
Dim N2 As IpfcBaseParameter
Dim Mitem As CMpfcModelItem
Dim Nv1 As IpfcParamValue
'Create async connection to CREO
Set cAC = New CCpfcAsyncConnection
Set asyncConnection = cAC.Connect(dbnull, dbnull, dbnull, dbnull)
Set session = asyncConnection.session
Set Model1 = session.GetModel("JBA.PRT", EpfcMDL_PART)
'Runs N - Number of Convolutes parameter modification
N01 = "N"
Range("E3").Select
N02 = ActiveCell.Text
Set Nx = Model1
Set N1 = Nx.GetParam(N01)
Set N2 = N1
Set Mitem = New CMpfcModelItem
Set Nv1 = Mitem.CreateDoubleParamValue(CDbl(N02))
N2.Value = Nv1
asyncConnection.Disconnect (1)
End Sub
---------------------------------------------------------------
Now I want to run a regenerate command after the parameter modification... I figure I should be using IpfcSolid.Regenerate() or somesuch, but wouldn't have the foggiest what I need to define, where it should be defined, and how. (Oh, and by the way, there are a lot of different parameter that are modified, I have just shortened the example for the sake of trying to be concise, which I'm not good at).
I have tried to get the API to run a Mapkey also (just CTRL-G for kicks...) but to no avail. I am sure that I am trying to skip a whole lot of useful training, by just thinking I can farm out my uselessness to the Web in search of a solution, but so much of what I have learnt has been done this way.
The thing is, that other than VBug.PDF I have not been able to find any meaningful documentation, or even a training course that I could follow to use this functionality... which to me looks pretty interesting, As I could implement this kind of 'basic' excel to CREO interface for a few of my colleagues, and probably get a few free coffees along the way (I will say though that my complete lack of knowledge of VBA is not helping me here... Perhaps someone could recommend me some interesting VBA based bedtime reading material...).
Any help anyone can offer me with getting my part to regen, would be massively appreciated! Then I'll have a ham-fisted bash at trying to get it work on a family table...
Cheers!
Bryan.