cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Translate the entire conversation x

Is it possible to update Parameters of an Assembly/Parts using VB APIs?

BK_8649137
6-Contributor

Is it possible to update Parameters of an Assembly/Parts using VB APIs?

In Creo 10.0.5.0, the requirement is to code which  iterates through models, and finds a specific component based on its file name. It then updates or creates a specified parameter within that component with a given value of any data type - using VB Apis, although I am using :
_parOwner.GetParam(paramName).SetScaledValue(valuePar, Nothing)
I am still unsuccessful.

ACCEPTED SOLUTION

Accepted Solutions
msteffke
14-Alexandrite
(To:BK_8649137)

I use the Pro/Toolkit API using C, and have many programs that create/modify parameters.  While I dont use the VB and cannot help with your code, I do have some information that may be useful.   There is currently a behaviour change in Creo 10 that is not allowing parameters to be changed by the API, unless you have manually attempted it first, or the part is checked out..   See SPR 15124431  at ptc.com.      If you have the items checked out in your workspace this is not your issue.   PTC has acknowleged this informed me (case 17798862)  that Creo 12 will have updated API that will allow modifications without checkout.   So we are having to hold out until Creo12 with fingers crossed. 

View solution in original post

4 REPLIES 4
jack15
12-Amethyst
(To:BK_8649137)

I am assuming that valuePar is the IpfcParamValue? if it is not that is your problem.

You say you are unsuccessful, but how? If there is an exception that additional context would be helpful. It would also be helpful to know what _parOwner is, is it a ComponentFeat? is it a Model?

It is also worth noting that GetParam method will not create the parameter if it doesn't exist.

BK_8649137
6-Contributor
(To:jack15)

I was able to update parameter for the model using:

' Connect to Creo (if not already connected)
Dim asyncConnection As pfcls.IpfcAsyncConnection = Nothing
Try
asyncConnection = (New CCpfcAsyncConnection).GetActiveConnection()
Catch ex As Exception
asyncConnection = (New CCpfcAsyncConnection).Connect("", "", "", 15)
End Try

Dim session As pfcls.IpfcBaseSession = asyncConnection.Session
session.CurrentWindow.Activate()

' Get current model
Dim model As pfcls.IpfcModel = session.CurrentModel
If model Is Nothing Then
MsgBox("No model is currently loaded in Creo.")
Return
End If

' Cast to Parameter Owner
Dim paramOwner As pfcls.IpfcParameterOwner = CType(model, pfcls.IpfcParameterOwner)

' Create string value for parameter
Dim modelItemUtil As New pfcls.CMpfcModelItem
Dim paramValue As pfcls.IpfcParamValue = modelItemUtil.CreateDoubleParamValue(100.0)

' Try to get the parameter
Dim parameter As pfcls.IpfcParameter = Nothing
Try
parameter = paramOwner.GetParam("ABC123")
parameter.SetScaledValue(paramValue, Nothing)
Console.WriteLine("Parameter 'ABC123' updated successfully.")
Catch ex As Exception
' If parameter not found, create it
paramOwner.CreateParam("ABC123", paramValue)
Console.WriteLine("Parameter 'ABC123' created with value '100.0'.")
End Try

Hello @BK_8649137

 

It looks like you have some responses from our community members. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Vivek N.
Community Moderation Team.

msteffke
14-Alexandrite
(To:BK_8649137)

I use the Pro/Toolkit API using C, and have many programs that create/modify parameters.  While I dont use the VB and cannot help with your code, I do have some information that may be useful.   There is currently a behaviour change in Creo 10 that is not allowing parameters to be changed by the API, unless you have manually attempted it first, or the part is checked out..   See SPR 15124431  at ptc.com.      If you have the items checked out in your workspace this is not your issue.   PTC has acknowleged this informed me (case 17798862)  that Creo 12 will have updated API that will allow modifications without checkout.   So we are having to hold out until Creo12 with fingers crossed. 

Announcements


Top Tags