Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

VB API Regenerate Solid

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 think your question here is , where to put session regenerate call?
You can put it once you are done with all your modifications. Do you have any other requirement than this?
 
My question was not so much as to where to put it, naturally I want it to be after the modifications. The problem seems to be around the fact that I need to fiddle with the config.pro settings and enable resolve mode in order to allow the API to make the regenerate call.... (maybe i should have read, then re-read the manual, then followed it, and then re followed it...). I'm learning as I go along, and it's kind of fun, although I fear it may bring about a premature greying of my hair.

I have managed to make the part regen now, However now I am getting a toolkit error saying I need to Regenerate again.... I think I will need to force regeneration of all instances. Its getting a bit complicated, as I have a fair few logic steps in the Pro/Program module that can pretty much make or break the system, This could be the issue... not sure though.

I appended the instructions as such, but I have a whole host of other changes, and as I mentioned, this brings up the Regeneration repeat error... (I don't think it will be reproduce-able with such a simplified macro, but I figure that this stuff might come in handy for someone someday... perhaps not...).
---------------------------------------------------------

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("TEST.PRT", EpfcMDL_PART)


'Runs N - Number of Convolutes parameter modification

N01 = "N"
Range("B2").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

Dim solid As pfcls.IpfcSolid
If session.CurrentModel.Type = EpfcModelType.EpfcMDL_PART Then
Set solid = session.CurrentModel
solid.Regenerate (zero)
End If

asyncConnection.Disconnect (1)

End Sub
 

Sponsor

Articles From 3DCAD World

Back
Top