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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Vb API selection

T_F
16-Pearl
16-Pearl

Vb API selection

Hello,

 

I'm trying to make a selection, using the example in instalation folder. I'm connected with the running session in CREO, but I'm unable to make the selection.

There is an messagebox appearing the follwing message.

 

T_F_0-1575884251214.png

Any help?

ACCEPTED SOLUTION

Accepted Solutions
YaroslavSin
17-Peridot
(To:T_F)

What about the parameter? Does it exist in the model?

 

In your code you get a parameter DESCRICAO_PAR, read the value of this parameter. Then write this value back to parameter. If the model don't have this parameter, then you will get an error.

 

Dim paramOwner As IpfcParameterOwner
Set paramOwner = session.CurrentModel

Dim parameter As IpfcParameter
Set parameter = paramOwner.GetParam("DESCRICAO_PAR")

Dim modelItem As CMpfcModelItem
Set modelItem = New CMpfcModelItem

Dim paramValue As IpfcParamValue
Set paramValue = modelItem.CreateStringParamValue("TEST")

parameter.SetScaledValue paramValue, Nothing

 

View solution in original post

16 REPLIES 16
YaroslavSin
17-Peridot
(To:T_F)

Hello,

show a piece of your code from Form1.vb near line 54

I've found the problem.

 

The code at the moment like this:

 


selopt = (New CCpfcSelectionOptions).Create("part")


selopt.MaxNumSels = 1

sel = session.Select(selopt, Nothing)


pobj = sel.Item(0).SelModel

 

At the moment is working. Now I'me strugling with parameters. I'm trying to fill a string parameter in CREO, by VB. And I can't do it... I've the way to do for a real number parameter, but not that easy to a string parameter.

YaroslavSin
17-Peridot
(To:T_F)

Something like this

Dim pv As IpfcParamValue
Dim p As IpfcParameter
Dim s As String

pv = (New CMpfcModelItem).CreateStringParamValue(s))
p = pOwner.GetParam("PARAM_NAME")
If p Is Nothing Then
 pOwner.CreateParam("PARAM_NAME", pv)
Else                            
 CType(p, IpfcBaseParameter).Value = pv
End If

Take a look at ...\Common Files\vbapi\vbapi_examples\pfcDimensionAndParameterExamples.vb

Thanks by help.

 

is returning the following error.

 

T_F_0-1576063146610.png

 

YaroslavSin
17-Peridot
(To:T_F)

1. Is there "DESCRICAO_PAR" parameter is exist in your model?

2. You can try method IpfcParameter.SetScaledValue()

Still the same error.

 

T_F_0-1576141225723.png

 

T_F
16-Pearl
16-Pearl
(To:T_F)

The funny thing, is that a real number parameter, i'm able to do it. The string parameter don't...

YaroslavSin
17-Peridot
(To:T_F)

What about the parameter? Does it exist in the model?

 

In your code you get a parameter DESCRICAO_PAR, read the value of this parameter. Then write this value back to parameter. If the model don't have this parameter, then you will get an error.

 

Dim paramOwner As IpfcParameterOwner
Set paramOwner = session.CurrentModel

Dim parameter As IpfcParameter
Set parameter = paramOwner.GetParam("DESCRICAO_PAR")

Dim modelItem As CMpfcModelItem
Set modelItem = New CMpfcModelItem

Dim paramValue As IpfcParamValue
Set paramValue = modelItem.CreateStringParamValue("TEST")

parameter.SetScaledValue paramValue, Nothing

 

Yes it exists:

 

T_F_0-1576145773279.png

 

YaroslavSin
17-Peridot
(To:T_F)

Access = Limited

Try change to Full

same error...

 

T_F_0-1576146360354.png

 

YaroslavSin
17-Peridot
(To:T_F)

Another problem, that the parameter is Restricted. Then not all values are acceptably.

Try to set value, for example, to "CUSTO_STD"

It worked!!!!

 

T_F_0-1576147019839.png

 

Can you explain me the difference?

T_F
16-Pearl
16-Pearl
(To:T_F)

Found the problem... What a stupid guy I am.... I had restricted values applied for this parameter... And "TEST" wasn't one of the values...

 

Thank you very much for your very usefull help.

T_F
16-Pearl
16-Pearl
(To:T_F)

After all of the usefull help, I created this app for CREO.

 

https://www.youtube.com/watch?v=S_Qeh26Jz1Y

 

Thanks by your help

Announcements


Top Tags