Community Tip - You can change your system assigned username to something more personal in your community settings. X
I am unable to update a drawing parameter in creo with excel vba. I can retrieve and change a 'BaseParameter.TextValue' according to vba, but the parameter doesn't change on the drawing or in the parameters window. Have also tried updating/saving with no luck. Any suggestions?
Solved! Go to Solution.
Adam, here is my VB.NET code for writing to a model param (i dont have any code for writing to a drawing param, but i guess it should be quite similar)
PDUtils refers to a set of functions (PDUtils.vb) that i copied from the vbparam example included in the Creo installation.
' Get type
Dim type As String = PDUtils.getTypeFromParam(CType(param, IpfcBaseParameter).Value)
' Create value
paramValue = PDUtils.createParamValue(param_value, type)
' Set value
CType(param, IpfcBaseParameter).Value = paramValue
Adam, here is my VB.NET code for writing to a model param (i dont have any code for writing to a drawing param, but i guess it should be quite similar)
PDUtils refers to a set of functions (PDUtils.vb) that i copied from the vbparam example included in the Creo installation.
' Get type
Dim type As String = PDUtils.getTypeFromParam(CType(param, IpfcBaseParameter).Value)
' Create value
paramValue = PDUtils.createParamValue(param_value, type)
' Set value
CType(param, IpfcBaseParameter).Value = paramValue
Hugo, Thank you for your suggestion.
have you ran into an instance where you were trying to update the value of an existing parameter? The parameter I am trying to update is text so I think I can pass it directly as a string. So far the variable updates and the Creo data does not, visibly anyway. I will review the vb.net code for PDUtils, I had it up yesterday.
In Solidworks I was never able to get variables (the Creo version of parameters) to update either; I had to delete and recreate them.
Here is how I update parameters using Excel:
Sub AddValuez()
'TITLE1 is the name of the parameter I am updating
Application.ScreenUpdating = False
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
Dim model1 As IpfcModel
Dim mdlname
Dim paramOwn As IpfcParameterOwner
Dim Moditem As New CMpfcModelItem
Dim ipTITLE1 As IpfcParameter
Dim ipbTITLE1 As IpfcBaseParameter
Dim pnTITLE1 As String
Dim TITLE1nv As IpfcParamValue
pnTITLE1 = "TITLE1"
'Connect
Set conn = asynconn.Connect("", "", ".", 5)
Set session = conn.session
Set model1 = session.CurrentModel
Set solid = model1
Set paramOwn = model1
Set Powner = model1
Set ipTITLE1 = paramOwn.GetParam(pnTITLE1)
Set ipbTITLE1 = ipTITLE1
'Sheets("Parameters").Range("B48").Value is where the value is housed.
Set TITLE1nv = Moditem.CreateStringParamValue(Sheets("Parameters").Range("B48").Value)
ipbTITLE1.Value = TITLE1nv
End Sub