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

How to get parameter values by API

SOLVED
Highlighted
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
Highlighted

Re: How to get parameter values by API

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

View solution in original post

3 REPLIES 3
Highlighted

Re: How to get parameter values by API

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

View solution in original post

Highlighted

Re: How to get parameter values by API

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

Highlighted

Re: How to get parameter values by API

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.

Announcements