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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

ProMdlUnitsCollect example

JohnMattson
1-Newbie

ProMdlUnitsCollect example

I'm trying to use the function ProMdlUnitsCollect to ultimately retrieve
whether the mass units are LB or KG. My code compiles, but the function
keeps failing. I suspect because of he 3rd parameter. This is what I
have.



ProMdl model;

ProUnitType unit_type = 1;

ProUnititem *unit_items;



status = ProMdlUnitsCollect(model, unit_type, unit_items);



Does anyone have any help or examples for using this function?



Thanks, John








Function ProMdlUnitsCollect





Retrieves the units available to the model.

Synopsis





#include <promdlunits.h<br/><file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\promdlunits_h.html=">
>

ProError
<file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\protoolkiterrors_h.h<br="/>tml#ProError>

ProMdlUnitsCollect

(



ProMdl
<file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\proobjects_h.html#pr<br="/>oMdl> mdl





/* (In)



The model handle.



*/



ProUnitType
<file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\promdlunits_h.html#p<br="/>roUnitType> type





/* (In)



The type of unit to retrieve.



*/



ProUnititem
<file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\promdlunits_h.html#p<br="/>roUnititem> ** units





/* (Out)



ProArray
<file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\proarray_h.html#proa<br="/>rray> of units. Free this array using ProArrayFree
<file: c:\ptc\wf4\prom100\protoolkit\protkdoc\api\105.html="> ().



*/

)

This electronic message including any attachments ("Message") may contain information that is privileged, confidential and/or exempt from disclosure under trade secret and other applicable law. If you are not the intended recipient, notify the sender immediately, permanently delete all copies of this Message, and be aware that examination, use, dissemination, duplication or disclosure of this Message is strictly prohibited.

This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
5 REPLIES 5

You should be passing address of unit_items.

status = ProMdlUnitsCollect(model, unit_type, &unit_items);

Hope this works.

Regards,

Vinay


2009/12/15 John Mattson <->

>
>
> I’m trying to use the function ProMdlUnitsCollect to ultimately retrieve
> whether the mass units are LB or KG. My code compiles, but the function
> keeps failing. I suspect because of he 3rd parameter. This is what I
> have.
>
>
>
> ProMdl model;
>
> ProUnitType unit_type = 1;
>
> ProUnititem *unit_items;
>
>
>
> status = ProMdlUnitsCollect(model, unit_type, unit_items);
>
>
>
> Does anyone have any help or examples for using this function?
>
>
>
> Thanks, John
>
>
>
>
>
>
> *Function ProMdlUnitsCollect*
>
>
>
>
>
> Retrieves the units available to the model.
>
> *Synopsis*
>
>
>
>
>
> #include <promdlunits.h>
>
> ProError
>
> *ProMdlUnitsCollect*
>
> (
>
>
>
> ProMdl *mdl*
>
>
>
>
>
> /* (In)
>
>
>
> The model handle.
>
>
>
> */
>
>
>
> ProUnitType *type*
>
>
>
>
>
> /* (In)
>
>
>
> The type of unit to retrieve.
>
>
>
> */
>
>
>
> ProUnititem** *units*
>
>
>
>
>
> /* (Out)
>
>
>
> ProArray of units. Free this array using ProArrayFree().
>
>
>
> */
>
> )
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> This electronic message including any attachments ("Message") may contain
> information that is privileged, confidential and/or exempt from disclosure
> under trade secret and other applicable law. If you are not the intended
> recipient, notify the sender immediately, permanently delete all copies of
> this Message, and be aware that examination, use, dissemination, duplication
> or disclosure of this Message is strictly prohibited.
>
>
>

John,
You are correct that the 3rd parameter is incorrect. You need to be passing a pointer pointer (**) for the third parameter. You have correctly declared the unit_items as a ProUnititem * but you need to pass the address of unit_items to the function. Try the following:

status = ProMdlUnitsCollect(model, unit_type, &unit_items);

Patrick Williams

Patrick,

Thanks that did the trick. What I'm ultimately trying to do is report
back whether the mass is LB or KG. So if I set the unit_type=1 (which
is PRO_UNITTYPE_MASS), should unit_types then contain the LB or KG
information I'm looking for? The following code keeps print 3LBM even
if I change the units to KG.



ProUnitType unit_type = 1;

ProUnititem *unit_items;

ProCharName unit_name;



status = ProMdlUnitsCollect(model, unit_type, unit_items);

ProWstringToString(unit_name, unit_items);

sprintf(logbuff, "Unit name is: %s\n", unit_name);



Thanks, John




John,
You are missing what the function ProMdlUnitsCollect is actually doing. Follow these steps:


1. Call ProMdlUnitsCollect to retrieve an ARRAY of ProUnititems.

2. Loop through each ProUnititem.

3. Print out the ProUnititem[i].name.

4. Free the ARRAY of ProUnititems by calling ProArrayFree or else you will leak memory.

Patrick Williams | Engineering Systems | Sr. Applications Engineer | Steelcase Inc. | 616.698.4078

[cid:image001.jpg@01CA7FCF.2F960880]

Hello,

Function ProMdlUnitsCollect() returns all the units available to a model.
To get unit assigned to model, functions ProMdlPrincipalunitsystemGet() and ProUnitsystemUnitGet() can be used.

E.g.

ProMdl model;
ProUnititem *mass_unit_items;
int iMassUnits = 0;
ProUnitsystem model_unit_system;
ProUnititem model_mass_unit;
ProCharName cMassUnitName;

// Get current model
ProMdlCurrentGet(&model);

// Collect all units avaliable to model for mass
ProMdlUnitsCollect(model, PRO_UNITTYPE_MASS, &mass_unit_items);
// Display information
ProArraySizeGet(mass_unit_items, &iMassUnits);
ProMessageDisplay(L"umsg.txt", "USER %0s", "Mass units available to model: ");
ProMessageClear();
for(int i=0; i<imassunits; i++)<br="/>{
ProWstringToString(cMassUnitName, mass_unit_items[i].name);
ProMessageDisplay(L"umsg.txt", "USER %0s", cMassUnitName);
ProMessageClear();
}
// Free allocated memory
ProArrayFree((ProArray *)&mass_unit_items);

// Get principal system of units currently assigned to the model
ProMdlPrincipalunitsystemGet(model, &model_unit_system);
// Get mass unit from principle system of units
ProUnitsystemUnitGet(&model_unit_system, PRO_UNITTYPE_MASS, &model_mass_unit);
ProWstringToString(cMassUnitName, model_mass_unit.name);
ProMessageDisplay(L"umsg.txt", "USER %0s", "Mass unit assigned to model: ");
ProMessageClear();
ProMessageDisplay(L"umsg.txt", "USER %0s", cMassUnitName);
ProMessageClear();

Output:
Mass units available to model:
lbm
kg
g
mg
tonne
ounce-m
slug
ton-m
IPS_mass_unit

Mass unit assigned to model:
lbm

Regards,

Amar Junankar
Sr. Application Engineer
Imagecom, Inc.
www.aspire3d.com

Top Tags