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 parameters

muflaj

New member
How can I change parameter value with excel? I connected
excel with ProE using Proe4.0 VB API and now I am trying to
update parameter value with value from excel cell...
thx in advance
 
You have to use IpfcParameter.SetScaledValue method. You can obtain the parameter by IpfcModel.GetParam method.
 
Thank you for your reply.
I can get parameter value from model, but can't update
it. I am doing this in visual studio 2008 since I can't
get it to work in excel, my guess is because vba does not
have CType function. Still trying to get around that
one. When I run it I don't get any error reports, but
parameter value remains unchanged...
any help is appreciated

Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
Dim mdl As pfcls.IpfcModel
Dim powner As pfcls.IpfcParameterOwner
Dim pro As pfcls.IpfcParameter
Dim pro_v As pfcls.IpfcParamValue
Dim X As String
asynconn =
CreateObject("pfcls.pfcAsyncConnection")
conn = asynconn.Connect("", "", ".", 5)
session = conn.Session
mdl = session.CurrentModel
X = Val(TextBox1.Text)
powner = CType(mdl, pfcls.IpfcParameterOwner)
pro = powner.GetParam("A")
pro_v = CType(pro, pfcls.IpfcBaseParameter).Value
pro.SetScaledValue(pro_v, Nothing)
conn.Disconnect(2)
 
Hi,

having the same issue here.. I wonder if you have found a
replacement function for the 'CType' to use in vba excel.
For assembly operations in ProE wf4.

grtz

Arno
 
Following are lines from working code to modify parameter value.

Code:
Dim param As IpfcParameter
Dim prmVal As IpfcParamValue

  param = model.GetParam("A")
  
  prmVal = (New CMpfcModelItem).CreateDoubleParamValue(5.0)
  CType(param, IpfcBaseParameter).Value = prmVal

HTH
 
that doesn't work in vba excel..


but i've already found correct solution. it's in the genre of


dim solid as ipfcsolid


dim asm as ipfcfeature


set asm = solid





replaces the CType
 
Hi Arno,


I'm a bit of a newbe in Vb programming. Looking for script on how to update a Creo Parameter on part currently in session. In my Example I've created a Creo part called Blokkie.prt and it carries a Paramter called MATERIALNUMBER.


I've written a VB Application in Visual studio whice reteives a Material number in a combobox. I need to program Submit button to update Creo Parameter called "MATERIALNUMBER" in part blokkie.prt. If not tomuch trouble would you be able to post this script for the Submit Button. Need to be able update the "MATERIALNUMBER" Parameter from string variable in my VB UI.


I've been trying to figure this outbut with no luck. You seem to be a good guy to talk to?


Thanks in advance
 
I'm sorry, if you are working in Visual Studio, then you're already less of a newbie then me.


i've just managed to create what i needed (automate a 'add component to assembly' from whithin in Excel vba )


i would check the Manual in de ProE directory ( C:/PTC/ ... vb api / vbug.pdf ) but i use WF4.
 
Cool.





Got an example in the VB API examples installed with Creo that I chaged a bit.It works!Stoked!Started out with Excel VB script and trying to move onto using Visual studio.


For interest sake here is the Submit Button code I use with the Sub Code.I use the createParametersFromStrings and createParametersFromStrings functions(also included):


Private Sub BSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BSubmit.Click





Dim asynconn As New pfcls.CCpfcAsyncConnection


Dim conn As pfcls.IpfcAsyncConnection


Dim session As pfcls.IpfcBaseSession


Dim mdl As pfcls.IpfcModel


Dim powner As pfcls.IpfcParameterOwner


Dim matNum As String


matNum = cbMatNumber.Text





asynconn = CreateObject("pfcls.pfcAsyncConnection")


conn = asynconn.Connect("", "", ".", 5)


session = conn.Session


mdl = session.CurrentModel


powner = CType(mdl, pfcls.IpfcParameterOwner)





createParametersFromStrings(powner, matNum, "MATERIAL")


conn.Disconnect(2)





End Sub


Private Function createParametersFromStrings(ByVal s As String) _


As IpfcParamValue


Try


Return ((New CMpfcModelItem).CreateStringParamValue(s))


Catch ex As Exception


MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)


Return Nothing


End Try


End Function


Public Sub createParametersFromStrings(ByRef pOwner As IpfcParameterOwner, ByVal VBMaterialNumber As String, ByVal CreoParamName As String)


Dim pv As IpfcParamValue


Dim p As IpfcParameter


Try


'=========================================================== ===========


'Use a stream reader to read the properties file


'=========================================================== ===========


'file = New IO.StreamReader(propertiesFile)


'=========================================================== ===========


'Read and parse line into key - value pairs. These are separated by


'":". Any line starting with # is ignored as comments


'=========================================================== ===========


'=========================================================== ===


'Invalid key - value pairs are ignored


'=========================================================== ===


pv = createParamValueFromString(VBMaterialNumber)


p = pOwner.GetParam(CreoParamName)


If p Is Nothing Then


pOwner.CreateParam(CreoParamName, pv)


Else


CType(p, IpfcBaseParameter).Value = pv


End If


Catch ex As Exception


MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)


Finally


End Try


End Sub


End Class
 
Hi muflaj,Arno


Need to get parameter value of parameter called 'Material' out of ProE or Creo as string. My Code fails at :


pro = powner.IpfcModel.GetParam("Material")



This is my code:



Dim asynconn As New pfcls.CCpfcAsyncConnection


Dim connector


Dim session As pfcls.IpfcBaseSession


Dim mdl As pfcls.IpfcModel


Dim powner As pfcls.IpfcParameterOwner


Dim pro As pfcls.IpfcParameter


Dim pro_v As pfcls.IpfcParamValue





asynconn = CreateObject("pfcls.pfcAsyncConnection")


connector = asynconn.Connect("", "", ".", 5)


session = connector.session


mdl = session.CurrentModel


powner = CType(mdl, pfcls.IpfcParameterOwner)


pro = powner.IpfcModel.GetParam("Material")


pro_v = CType(pro, pfcls.IpfcBaseParameter).Value


pro.SetScaledValue(pro_v, Nothing)





lblMatQTY.Text = pro_v


Would you be able to help me understand why its failing?Thanks
 
Hi thanks for the Reply. I sorted ut my issue. IT was to do with the issue of converting the parameter value to a string. I did not understand why the parameter value was not transeferable to textbox.text. I needed to convert the parameter value to string by using aclass on the vb api examples called PDUtils


Basically this is how I had to covert value to string:


lblMatQTY.Text = PDUtils.getValueFromParam(pro_v).ToString


PDUtils can be foud in the vb API example called PrameterAnd Dimension
 
Hi Guys, I struggled for a while with this. Here's some code that some of the ptc tech's provided. I altered it for my purpose. It works in both excel VBA or visual studio. Basically it will look at what current model is in session and then read a parameter value and then write back a new value to it. I hope this helps!

Sub Main2()

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

'Retrieve the currently open model into the oModel handle
Set oModel = session.CurrentModel

'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 A_value As Double
Dim A_value_new As Double
Dim new_paramowner As pfcls.IpfcParameterOwner


'Read Parameter EZ value
Set new_paramowner = oModel
Set A = new_paramowner.GetParam("EZ")
Set Av = A.Value
A_value = Av.DoubleValue

'Show the original value of the parameter
MsgBox "EZ = " & A_value

'Set new value to Parameter EZ
Av.DoubleValue = 20
A.Value = Av
oModel.Save

'Show the final value of the parameter
MsgBox "EZ = " & A.Value.DoubleValue

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

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

End Sub




Edited by: ezaidi
 
I know but I figured someone else could benefit from it. I tried all other solutions in this forum and nothing worked for me. I guess it always better to have alternate solutions available on the net for others to try.
 
Hi all,


been a while :) , and Ezaidi , I have indeed benefitted from the code to retrieve parametervalues. I now try to do go a little deeper in the vb api for proe, but it can be hard.


You wouldn't happen to know the code to perform the exact same action, but then to retrieve Dimension Values...


tried to change it to work, but it doesn't


Thx in Advance
 
You'll never see it different, but I found it right aftermy post here (always after a day of searching and finaly posting the question on a forum ^^)


I knew BaseDimensions were childclass of Baseparameters, so thoughtthey would also have ParameterOwner. but they have a ModelItemOwner.


As Info:


Dim dimo As IpfcBaseDimension


Dim res As Double


Dim owner As IpfcModelItemOwner


owner = solid 'previously defined


dimo = owner.GetItemByName(EpfcModelItemType.EpfcITEM_DIMENSION, "NOSE_RADIUS")


res = dimo.DimValue


MsgBox("DIM = " & res.ToString)
 
Great work Arno! I'm sure this will be useful for us as well in our automation. I did not yet get to the point of driving dimensions but I know that we will need it in the future.Thank you for your good work!
 

Sponsor

Articles From 3DCAD World

Back
Top