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

Using ProSelect

Highlighted
Newbie

Using ProSelect

Good morning TK users,

I am trying to write a small app that will save user-selected components
in an assembly. It does not work for multiple selections (but does for a
single selection). I think it has to do with my array allocation. Can
anyone please point me in the right direction? TIA Here's what I have:

int SaveSelected()
{
ProError tkerr;
ProMdl ModelHandle;
ProModelitem ModelItem;
ProSelection *sel;
int n_sel;
int i;

ProSelectionAlloc(NULL, NULL, &sel);
ProSelect("part", -1, NULL, NULL, NULL, NULL, &sel, &n_sel);

for(i=0; i<=n_sel; i++)
{
ProSelectionModelitemGet(sel[i], &ModelItem);
ProModelitemMdlGet(&ModelItem, &ModelHandle);
ProMdlSave(ModelHandle);
}

tkerr = ProSelectionFree(&sel);

return 0;
}
2 REPLIES 2

Re: Using ProSelect

Dave,

Remove the ProSelectionAlloc() statement. The documentation says the
function allocates this memory and it is reused on the next call.

Bob

--
Robert A. Monat
Jerand Technical Services, Inc.
http://www.jerand.com
Phone: 317-875-6087 FAX: 317-875-6612 Tollfree(US)888-4JERAND


David Schmitz wrote:

>Good morning TK users,
>
>I am trying to write a small app that will save user-selected components
>in an assembly. It does not work for multiple selections (but does for a
>single selection). I think it has to do with my array allocation. Can
>anyone please point me in the right direction? TIA Here's what I have:
>
>int SaveSelected()
>{
> ProError tkerr;
> ProMdl ModelHandle;
> ProModelitem ModelItem;
> ProSelection *sel;
> int n_sel;
> int i;
>
> ProSelectionAlloc(NULL, NULL, &sel);
> ProSelect("part", -1, NULL, NULL, NULL, NULL, &sel, &n_sel);
>
> for(i=0; i<=n_sel; i++)
> {
> ProSelectionModelitemGet(sel[i], &ModelItem);
> ProModelitemMdlGet(&ModelItem, &ModelHandle);
> ProMdlSave(ModelHandle);
> }
>
> tkerr = ProSelectionFree(&sel);
>
> return 0;
>}
>
>---
>
>You are currently subscribed to toolkits.
>To unsubscribe send a blank e-mail to -.
>
>Don't miss the PTC/USER World Event 2005, June 5-8, in Orlando, Florida. Visit www.ptcuser.org/2005 for details.
>
>For assistance, email us at - or find other contacts at www.ptcuser.org/org/contacts.html.
>
>PTC/USER and the PTC/USER logo are registered trademarks of PTC/USER, Inc.
>Pro/ENGINEER is a registered trademark of PTC.
>
>Message authors are solely responsible for the content of their posts.
>
>
>

Re: Using ProSelect

The app works now when I changed the following line from:
for(i=0; i<=n_sel; i++)
to:
for(i=0; i<=n_sel-1; i++)

It was just a stupid programming error. If n_sel is "3" I would want to
query selection items "0" to "2".

Thanks to all who replied!

> Good morning TK users,

I am trying to write a small app that will save user-selected components
in an assembly. It does not work for multiple selections (but does for a
single selection). I think it has to do with my array allocation. Can
anyone please point me in the right direction? TIA Here's what I have:

int SaveSelected()
{
ProError tkerr;
ProMdl ModelHandle;
ProModelitem ModelItem;
ProSelection *sel;
int n_sel;
int i;

ProSelectionAlloc(NULL, NULL, &sel);
ProSelect("part", -1, NULL, NULL, NULL, NULL, &sel, &n_sel);

for(i=0; i<=n_sel; i++)
{
ProSelectionModelitemGet(sel[i], &ModelItem);
ProModelitemMdlGet(&ModelItem, &ModelHandle);
ProMdlSave(ModelHandle);
}

tkerr = ProSelectionFree(&sel);

return 0;
}
Announcements