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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to get parameter values by API

bschmidt-2
1-Newbie

How to get parameter values by API

Hi everybody,

I am using the VB.NET API for gathering informations about the current model. Especially the Creo parameters (see picture below).

CreoParams.JPG

You can get the parameters by

IpfcParameterOwner owner = (IpfcParameterOwner)currentModel;

foreach (IpfcParameter param in owner.ListParams())

...

So I can gather the values (e.g. "A.1") but I couldn´t get the parameter name (e.g. "PTC_WM_VERSION"). In the PDF-help they say, that the name can be retrieved by the IpfcModelItem. But how to come from IpfcParameter to IpfcModelItem (typecast is not possible).

Any suggestions how to get the needed information?

Best regards,

Benjamin

Nachricht geändert durch Benjamin Schmidt

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Benjamin,

    Try below method,


Public AConnection As IpfcAsyncConnection

Public CConnection As New CCpfcAsyncConnection

Public ParamOwner As IpfcParameterOwner

Public Parameter As IpfcParameter

Public BSession As IpfcBaseSession

Public Model As IpfcModel

Public Async Function CreoConnect() As Task

Try

            If Not AConnection Is Nothing Then

              AConnection = CConnection.GetActiveConnection

            Else

AConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, Nothing)

            End If

              BSession = AConnection.Session

Model = BSession.CurrentModel

ParamOwner = CType(Model, IpfcParameterOwner)   ' CONVERSION OF MODEL ITEM INTO PARAMETER OWNER

Parameter = ParamOwner.GetParam("WEIGHT")       ' GET YOUR PARAMETER (USE YOUR PARAMETER NAME INSTEAD WEIGHT)


If Not Parameter Is Nothing Then

Dim Weight As Double = ParamOwner.GetParam("WEIGHT").GetScaledValue.DoubleValue ' MENTION DOUBLE/STRING VALUE

MsgBox(Weight.ToString)

              Else

              MsgBox ("Parameter Not Found")

End If

Catch ex As Exception

            MsgBox(ex.ToString)

End Try

End Function

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"

View solution in original post

5 REPLIES 5

Hi Benjamin,

    Try below method,


Public AConnection As IpfcAsyncConnection

Public CConnection As New CCpfcAsyncConnection

Public ParamOwner As IpfcParameterOwner

Public Parameter As IpfcParameter

Public BSession As IpfcBaseSession

Public Model As IpfcModel

Public Async Function CreoConnect() As Task

Try

            If Not AConnection Is Nothing Then

              AConnection = CConnection.GetActiveConnection

            Else

AConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, Nothing)

            End If

              BSession = AConnection.Session

Model = BSession.CurrentModel

ParamOwner = CType(Model, IpfcParameterOwner)   ' CONVERSION OF MODEL ITEM INTO PARAMETER OWNER

Parameter = ParamOwner.GetParam("WEIGHT")       ' GET YOUR PARAMETER (USE YOUR PARAMETER NAME INSTEAD WEIGHT)


If Not Parameter Is Nothing Then

Dim Weight As Double = ParamOwner.GetParam("WEIGHT").GetScaledValue.DoubleValue ' MENTION DOUBLE/STRING VALUE

MsgBox(Weight.ToString)

              Else

              MsgBox ("Parameter Not Found")

End If

Catch ex As Exception

            MsgBox(ex.ToString)

End Try

End Function

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"

Hi Parthiban,

that would be a nice solution, if I know the name of the parameter.

But that´s not always the case, so I need to gather all parameters (not knowing their name).

Meanwhile I have found the solution. With IpfcNamedModelItem you can access the parameter name:

IpfcParameter param = ...

IpfcNamedModelItem modItem = (IpfcNamedModelItem)param;

=> modItem.Name // parameter name

Thank you.

Best regards,

Benjamin

sdb_creo
6-Contributor
(To:bschmidt-2)

Hi Benjamin.

I am looking for a similar script which can help to extract the parameters from a CAD file. Would you mind sharing the complete script to extract the whole list of parameters from a Model .PRT or .DRW file.

 

thank you.

Can you give mail contact for I have doubt in creo in parameters extraction,

If you will to share your mail to kravimohan59@gmail.com

Hi Benjamin,

I have the similar problem. I have given the parameter name and i need to get the value of this parameter using VB API.
Can you help me out with this similar problem? Maybe you can send me an example script.

Thank You.

 

Best regards,

Fritz

Top Tags