Cancel
Showing results for 
Search instead for 
Did you mean: 

knowledge fusion, centroid from CSYS to expressions

Experimenter
Experimenter

Hello Everyone,

I'm writing a function on knowledge fusion to get the centroid of an object and put it in the expression.

Then if the object changes, the expression values updates.

Now I need some help, I'm trying to modified the function to use a selected CSYS to measure the Centroid.
if I then update the CSYS or the body, the values should update in the expressions.

What I need help on is:
- How to make the selection Filter for CSYS
- how to use it for the centroid

Here is what I have so far:

 

DefClass: centroid (%nx_application %ui_comp);

(Boolean) %on_solid?: false; # this feature will create an independent solid
(String Parameter) %ask_name: "Centroid"; # feature name
(string) %icon_name: "section_inertia";	# icon in MNT
(Integer) %edit_dialog: ug_invokeClassDialog(self:); # edit feature allowed
(List Uncached) %onObjectHighlight:	Centroid:;
(Boolean) %atTimeStamp?: false;

###### Create the interface for user selection ######

### main group of user interface ###
(child) UI_group:{
class,	%ui_comp_group;
title, "Body Centroid";
Members, {UI_Select:,UI_Label:,UI_SelectDatum:};
Column,	0;
Group, True;
};

#select solid or a surface body, only 1 item per selection #
(child) UI_Select: {
class, %ui_comp_selection;
Many, False;
Label,	"Solid or Surface to Analyse";
Tooltip, "Select the Solid or Surface to analyse";
FilterTriple,	{{ 70, 0, 35 },{ 70, 0, 36 }};
};

#user text box for expression names#
(child) UI_Label:{
class, %ui_comp_string;
Value, "";
PresentationStyle,	1;

#select CSYS #
(child) UI_SelectDatum: {
class, %ui_comp_selection;
Many, False;
Label,	"Coordinate System";
Tooltip, "Select the Coordinate System";
FilterTriple,	{{ 70, 0, 35 },{ 70, 0, 36 }};
};

# make the selected object into the string #
(Instance) object: ug_adoptObject(nth(1,UI_Select:SelectedObjects:));
(Instance) datum: ug_adoptObject(nth(1,UI_SelectDatum:SelectedObjects:));

# Create the expressions with reference to the centroids of X, Y, Z of the solid or sheet selected
# the 'child uncached' allows expressions to be recalculated automatically when geometry changes

(child uncached) x: {
Class, ug_expression;
Name,	UI_Label:Value: + "_x";
Value,	localX(object:centroid:);
};
(child uncached) y: {
Class, ug_expression;
Name,	UI_Label:Value: + "_y";
Value,	localY(object:centroid:);
};
(child uncached) z: {
Class, ug_expression;
Name,	UI_Label:Value: + "_z";
Value,	localZ(object:centroid:);
};

# Creates a Point at the object Centroid
(child) centre_de_gravite_point: {
Class,	ug_point;
position, object:centroid:;
};
1 REPLY

Re: knowledge fusion, centroid from CSYS to expression

Experimenter
Experimenter

I have made some more progress, but still not enought.

 

Now I can select a new CSYS but I can't find how to use it.

 

it will have to be in the line 

localX(object:centroid:);

for sure I have to change localX by something relating to the new CSYS.

 

and I think the line:

(Instance) datum: ug_adoptObject(nth(1,UI_SelectDatum:CSYS:));:));

is also the wrong way to add the selected CSYS to a string to call it later.

 

here is the new code

 

DefClass: centroid (%nx_application %ui_comp);

(Boolean) %on_solid?: false; # this feature will create an independent solid
(String Parameter) %ask_name: "Centroid"; # feature name
(string) %icon_name: "section_inertia";	# icon in MNT
(Integer) %edit_dialog: ug_invokeClassDialog(self:); # edit feature allowed
(List Uncached) %onObjectHighlight:	Centroid:;
(Boolean) %atTimeStamp?: false;

###### Create the interface for user selection ######

### main group of user interface ###
(child) UI_group:{
class,	%ui_comp_group;
title, "Body Centroid";
Members, {UI_Select:,UI_Label:,UI_SelectDatum:};
Column,	0;
Group, True;
};

#select solid or a surface body, only 1 item per selection #
(child) UI_Select: {
class, %ui_comp_selection;
Many, False;
Label,	"Solid or Surface to Analyse";
Tooltip, "Select the Solid or Surface to analyse";
FilterTriple,	{{ 70, 0, 35 },{ 70, 0, 36 }};
};

#user text box for expression names#
(child) UI_Label:{
class, %ui_comp_string;
Value, "";
PresentationStyle,	1;

#select CSYS #
(child) UI_SelectDatum: 	{
		class, 		%ui_comp_CSYS;
}; 

# make the selected object into the string #
(Instance) object: ug_adoptObject(nth(1,UI_Select:SelectedObjects:));
(Instance) datum: ug_adoptObject(nth(1,UI_SelectDatum:CSYS:));:));

# Create the expressions with reference to the centroids of X, Y, Z of the solid or sheet selected
# the 'child uncached' allows expressions to be recalculated automatically when geometry changes

(child uncached) x: {
Class, ug_expression;
Name,	UI_Label:Value: + "_x";
Value,	localX(object:centroid:);
};
(child uncached) y: {
Class, ug_expression;
Name,	UI_Label:Value: + "_y";
Value,	localY(object:centroid:);
};
(child uncached) z: {
Class, ug_expression;
Name,	UI_Label:Value: + "_z";
Value,	localZ(object:centroid:);
};

# Creates a Point at the object Centroid
(child) centre_de_gravite_point: {
Class,	ug_point;
position, object:centroid:;
};

 Hope someone can crack these one.

Cheers