×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Retrieving calculated assembly weight for downstream use

Retrieving calculated assembly weight for downstream use

Retrieving calculated assembly weight for downstream use

(OP)
Greetings all!

Much was said about regrattable shortcoming of not being able to directly refer to the calculated assembly weight. I personally find strange that quite expensive functionality of advanced weight calculation turns out to be virtual dead-end, but let's leave it for now. My question is - what ways can be found to retrieve that weight and put it into the attribute? Can NX Open application or maybe some journal do this? Please help.

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

You can use Measure Body to create an Expression which will give you the weight of an Assembly file. Once that expression is created, the value can be linked to a Attribute. What version of NX are you running?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Retrieving calculated assembly weight for downstream use

(OP)
Hello John!

NX8.5 and 9.0. I know pretty well that measure body calculation can be created. This technique has one great disadvantage - it has to be attended to manually.

What I'm looking for is a way to retrieve assembly weight (and possibly some other parameters like Center of Mass or First moments which I can see in the information window when I run Weight management calculation) and put it into the attribute.

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

The Center-of-Mass is created automatically by the Measure Body function and the X,Y,Z coordinates can be extracted into Expressions as well as the Weight and while it it is true that this has limitations, as long as NO new components are added to the Assembly, the system will update properly if the parent parts of the Components are modified and updated as well as if Components are removed from an Assembly. Only when new Components are added will the Measure Bodies function have to be modified and updated. If these limitations prevent you from doing what you want, then you'll need to apply an NX Open-based solution.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Retrieving calculated assembly weight for downstream use

(OP)
I know pretty well about the measure bodies tool, and in what cases it can and can not be helpful. Let's leave it where it is.

I'm really interested about NX Open/Journal way of retrieving the said values. Has somebody already tried this? Can anybody please help?

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

(OP)
Hi cowski!

The following code from your search result cannot be used:

Option Strict Off
Imports System
Imports NXOpen
imports nxopen.uf

Module NXJournal
Sub Main

Dim nxs As Session = Session.GetSession()
Dim ufs as UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()

dim cur_part_tag as tag = nxs.parts.work.tag
dim weight as ufweight.properties
dim units as ufweight.unitstype

ufs.weight.askprops(cur_part_tag,units,weight)
msgbox(weight.mass)

End Sub
End Module


It returns the value of MassPropMass attribute and therefore zero for assemblies.

Is it possible at all to retrieve weight calculated using the advanced weight management tool? So far I found nothing in the documentation for the NX Open. Please help!

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

Here is an example from NX 6.

HTH, Joe

CODE --> NXopen_(pre-NX8)

void set_weight_attribute()
{
    tag_t part = UF_ASSEM_ask_work_part();
    UF_WEIGHT_exceptions_t exceptions;
    UF_WEIGHT_properties_t properties;

	char value_string[132];
	char units_string[132];
	char expr_string[133];
	UF_ATTR_value_t value;
	UF_ATTR_value_t expr;
	logical expr_exists = FALSE;
	int wp_units;

	value.type = UF_ATTR_string;

    UF_CALL(UF_WEIGHT_set_part_ref_set(part, "MODEL"));

    UF_CALL(UF_WEIGHT_init_exceptions( &exceptions));

	UF_CALL( UF_PART_ask_units(part,&wp_units));
	if (wp_units == UF_PART_METRIC)
	{
	    UF_CALL(UF_WEIGHT_estab_part_props(part, 0.9999, TRUE, UF_WEIGHT_units_km,&properties, &exceptions));
		sprintf_s(units_string,132,"Kg");
	}else{
		UF_CALL(UF_WEIGHT_estab_part_props(part, 0.9999, TRUE, UF_WEIGHT_units_li,&properties, &exceptions));
		sprintf_s(units_string,132,"LB");
	}

	sprintf_s(value_string,132,"%f",properties.mass);
	value.value.string = value_string;

	UF_CALL(UF_ATTR_assign(part, "DB_WEIGHT_VALUE", value));
	value.value.string = units_string;
	UF_CALL(UF_ATTR_assign(part, "DB_WEIGHT_UNIT", value));

	// Set Expression for weight value on save.  
	sprintf_s(value_string,132,"%s=%f","DB_WEIGHT_VALUE",properties.mass);

	UF_CALL(UF_MODL_is_exp_in_part(part,"DB_WEIGHT_VALUE",&expr_exists));
	if(expr_exists)
	{
		UF_CALL(UF_MODL_edit_exp(value_string));
	}

	// Update the model
	UF_CALL(UF_MODL_update());

} /* end of set_weight_Attribute*/ 

RE: Retrieving calculated assembly weight for downstream use

(OP)
Hi, jpetach!

Thank you! I'm only have very limited knowledge of NX Open at the moment, and this example is quite complex for me. Could you please explain it a little? Does it really retrieve the assembly mass which is calculated using the advanced weight management? What line exactly does that? Thanks in advance!

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

PrintScaffold,

Yes, this does use the advanced assembly weight management capability. I had seen in your post that you have the ability (license) to do that so I felt my example would be appropriate for your situation.

The line of code that uses weight management for the assembly uses the function
UF_WEIGHT_estab_part_props

The wrapper function UF_CALL is optional - it just outputs the error message if the NXopen function that it wrapped fails. It is in many of the NXopen examples on the GTAC site. Or, you can simply this example by removing "UF_CALL(" and the closing ")" from each line it occurs on.

The example function set_weight_attribute() can be invoked by the desired NXopen entry point(s). This is how to have the function execute when file-save occurs (ufput). To experiment with the program it might be better to start by using the ufsta entry point that is triggered by explicit activation of the program by "File->Execute->NXopen->yourprogramname.dll"

CODE --> NXopen

extern DllExport void ufput( char *param, int *returnCode, int rlen )
{
	/* Initialize the API environment */
	if( UF_CALL(UF_initialize()) ) 
	{
		/* Failed to initialize */
		return;
	}
	set_weight_attribute();
	*returnCode=0;
	/* Terminate the API environment */
	UF_CALL(UF_terminate());
} 

Then, once it is working add the additional entry points where this should occur. (ufput (file save), ufsvas (save-as) etc.)

The program is very basic.
  • Set the "stuff to analyze" as everything in the model reference set (all the components)
  • Initialize the data structure for assembly weight management
  • Determine if this is an inch or metric part
  • Get the advanced assembly weight data for the correct part units.
  • Assign the mass value to the part attribute DB_WEIGHT_VALUE
  • Assign the weight units to the part attribute DB_WEIGHT_UNITS
  • Assign the mass value to the expression DB_WEIGHT_VALUE if the expression exists
  • Update (the expression)
Here is an example of a program that contains that function invoke from the File->execute-> NXopen dialog.

CODE --> NXopen_C

/* Include files */
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_attr.h>

#include <uf_assem.h>
#include <uf_attr.h>
#include <uf_weight.h>
#include <uf_modl.h>
#include <uf_part.h>
#include <uf_obj.h>
#include <uf_dirpath.h>
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))

static int report_error( char *file, int line, char *call, int irc)
{
	if (irc)
	{
		char err[133],
			msg[133];
		sprintf_s(msg,133, "*** ERROR code %d at line %d in %s:\n+++ ",
			irc, line, file);
		UF_get_fail_message(irc, err);
		UF_print_syslog(msg, FALSE);
		UF_print_syslog(err, FALSE);
		UF_print_syslog("\n", FALSE);
		UF_print_syslog(call, FALSE);
		UF_print_syslog(";\n", FALSE);
		if (!UF_UI_open_listing_window())
		{
			UF_UI_write_listing_window(msg);
			UF_UI_write_listing_window(err);
			UF_UI_write_listing_window("\n");
			UF_UI_write_listing_window(call);
			UF_UI_write_listing_window(";\n");
		}
	}
	return(irc);
}
void set_weight_attribute()
{
    tag_t part = UF_ASSEM_ask_work_part();
    UF_WEIGHT_exceptions_t exceptions;
    UF_WEIGHT_properties_t properties;

	char value_string[132];
	char units_string[132];
	char expr_string[133];
	UF_ATTR_value_t value;
	UF_ATTR_value_t expr;
	logical expr_exists = FALSE;
	int wp_units;

	value.type = UF_ATTR_string;

    UF_CALL(UF_WEIGHT_set_part_ref_set(part, "MODEL"));

    UF_CALL(UF_WEIGHT_init_exceptions( &exceptions));

	UF_CALL( UF_PART_ask_units(part,&wp_units));
	if (wp_units == UF_PART_METRIC)
	{
	    UF_CALL(UF_WEIGHT_estab_part_props(part, 0.9999, TRUE, UF_WEIGHT_units_km,&properties, &exceptions));
		sprintf_s(units_string,132,"Kg");
	}else{
		UF_CALL(UF_WEIGHT_estab_part_props(part, 0.9999, TRUE, UF_WEIGHT_units_li,&properties, &exceptions));
		sprintf_s(units_string,132,"LB");
	}

	sprintf_s(value_string,132,"%f",properties.mass);
	value.value.string = value_string;

	UF_CALL(UF_ATTR_assign(part, "DB_WEIGHT_VALUE", value));
	value.value.string = units_string;
	UF_CALL(UF_ATTR_assign(part, "DB_WEIGHT_UNIT", value));

	// Set Expression for weight value on save.  
	sprintf_s(value_string,132,"%s=%f","DB_WEIGHT_VALUE",properties.mass);

	UF_CALL(UF_MODL_is_exp_in_part(part,"DB_WEIGHT_VALUE",&expr_exists));
	if(expr_exists)
	{
		UF_CALL(UF_MODL_edit_exp(value_string));
	}else{
		UF_CALL(UF_MODL_create_exp(value_string));
	}
	// Update the model
	UF_CALL(UF_MODL_update());

} /* end of set_weight_Attribute*/ 
/*****************************************************************************
**  Activation Methods
*****************************************************************************/
extern DllExport void ufsta( char *param, int *returnCode, int rlen )
{
	/* Initialize the API environment */
	if( UF_CALL(UF_initialize()) ) 
	{
		/* Failed to initialize */
		return;
	}
	set_weight_attribute();
	*returnCode=0;
	/* Terminate the API environment */
	UF_CALL(UF_terminate());
/*****************************************************************************
**  Utilities
*****************************************************************************/

/* Unload Handler
**     This function specifies when to unload your application from Unigraphics.
**     If your application registers a callback (from a MenuScript item or a
**     User Defined Object for example), this function MUST return
**     "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void )
{
	return( UF_UNLOAD_UG_TERMINATE );
} 
HTH,

Joe

RE: Retrieving calculated assembly weight for downstream use

(OP)
Wow! Thank you very much!

Could you please explain a little further this point: "Set the "stuff to analyze" as everything in the model reference set (all the components)"? If we analyse the assembly, we should establish also the components group, not only the reference set. Can this be done? Also, can we use reference set and component group that is currently assigned for the weight calculation in the advanced weight management, not hard-coding it? They can differ for different parts and assemblies.

One more question: can this functionality be run as a journal, or is it only for NX Open?

UF_WEIGHT_estab_part_props - is this an out of the box command of NX Open? I didn't find info on it, alghough I have API section of NX help installed. Where this kind of info can be found?

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

PrintScaffold,

Yes, instead of using a reference set a component group can be specified as the collection to weigh.

CODE --> NXopen_c

UF_CALL(UF_WEIGHT_set_part_cset(part, "MyCompGroupName")); 

Yes, instead of hard-coding the ref set name to use the current part can be queried for the existing weight ref set name using UF_WEIGHT_ask_part_ref_set to get the ref set name.

Yes, UF_WEIGHT_estab_part_props is an out of the box command of NX Open. In the NX API docs go to "NXOpen -> Open for C/C++ -> Open C Reference -> UF_WEIGHT"

Yes, there is .Net support. The MassPropertiesBuilder class is the UF_WEIGHT equivalent. The easiest way to to get an example is to create a journal and use "ANAV, MB3, Properties, Weight, Update Now".

HTH,

Joe

RE: Retrieving calculated assembly weight for downstream use

(OP)
Thank you very much, Joe!

I will now try to sort it out myself. I'll write here if I have more questions.

Once again, huge thanks!

Industry creates wealth!

RE: Retrieving calculated assembly weight for downstream use

Hi Joe, and without the advanced weight management, it's possible to retrieve the assembly weight indicated in the assembly navigator ?

Thank you...

Using NX 8 and PDM RuleDesigner

RE: Retrieving calculated assembly weight for downstream use

Cubalibre00,

No, at this time (NX 9.0.x), without a license for Advanced Assembly Weight Management successfully using these API calls would either be piracy or flaws in the license checking. winky smile

Regards, Joe

RE: Retrieving calculated assembly weight for downstream use

Hi,
which is the difference between ask_mass_props_3d and MeasureManager.NewMassProperties ?
I want to know the weight off all body present in the reference set model and write on an specific attribute.

Joe has put an example to retrieve assembly weight.
I've found Sample Open C API program : report weight of current assembly that doesn't need extra license.
Attached the example.

Thank you...

Using NX 8 and PDM RuleDesigner

RE: Retrieving calculated assembly weight for downstream use

Hi Jpetach,

I have large assembly licence and I am interested to your code but I don't have licence to compile NXOpen.

Could you send me the .dll or a journal file ?

Thanks in advance

Regards
Didier Psaltopoulos
http://www.psi-cad.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources