Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Center of Gravity Calculated with Featurescript
philipp_wehr
Member Posts: 8 EDU
Hi Guys,
I am trying to calculate the Center of Gravity (COG) of a 2D man (Picture).
I worked with Solidworks Api and could figure everything out with the Macro Recorder. Sadly this feautre doesnt exist in Onshape and there are not a lot of Tutorials for Onshape.
What i want to do in Feature Script is to calculate for all 3 Konfigurations the overall COG. Therefore I need the X and Y Coordinates of the COG (Yellow Points) of each body segement.
Then I want to calculate with FeatureScript the overall COG. I have all the masses of the different Body Segments in the different Konfiguration Sizes.
My question would be now:
-How can I get all the X and Y Dimensions for the different Body Segments( Points) and how can I use this values further on to use them in a formula.
-How Can I create different Points for the different Configurations.
-Whats the best way to implement the different Mass Values for the different Configurations into Featurescript
I am thankful for every help,
Greetings from Germany Philipp
I am trying to calculate the Center of Gravity (COG) of a 2D man (Picture).
I worked with Solidworks Api and could figure everything out with the Macro Recorder. Sadly this feautre doesnt exist in Onshape and there are not a lot of Tutorials for Onshape.
What i want to do in Feature Script is to calculate for all 3 Konfigurations the overall COG. Therefore I need the X and Y Coordinates of the COG (Yellow Points) of each body segement.
Then I want to calculate with FeatureScript the overall COG. I have all the masses of the different Body Segments in the different Konfiguration Sizes.
My question would be now:
-How can I get all the X and Y Dimensions for the different Body Segments( Points) and how can I use this values further on to use them in a formula.
-How Can I create different Points for the different Configurations.
-Whats the best way to implement the different Mass Values for the different Configurations into Featurescript
I am thankful for every help,
Greetings from Germany Philipp
Tagged:
0
Comments
Here, I'm setting up an array parameter, in which each entry is an edge and a mass (for simplicity given as a real number, multiplied by kilograms in the code). For each edge I'm getting a centroid, multiplying by its mass, and dividing by the total mass in the end for the total center of mass.
Thanks for the reply.
That was not 100% what i was searching for. I want to select all Points ( not Edges) and then calculate for each Point X and Y Disatance to origin. That would help me out a lot.
Edge midpoint selection can only be "woken up" if both edges and vertices are available selections for your feature.
It is kind of hacky, but if you want this behavior what you could make the following changes:
1. Change the "Filter" of widget.edge from "EnttiyType.EDGE && SketchObject.YES" to "EntityType.EDGE || EntityType.VERTEX".
2. Change the call to "evApproximateCentroid" to a call to "evVertexPoint" ( https://cad.onshape.com/FsDoc/library.html#evVertexPoint-Context-map )
Unfortunately, though, the user will be able to select both edges and vertices, and if they select an edge it will fail. This is because those points you want to select are edge midpoints, not real vertices that are always available in the system. They way they are currently implemented, they are only available when both edges and vertices are selectable.
Is there a reason that you prefer making your user select the edge midpoints manually, instead of having the user select the edges, and having the program figure out their midpoints?
I don't want to select any edges.
I have a single sketch only with points. These Points have a specific position on the Lines, which i already configured (Picture).
What i need now is to X Distance and Y Distance of each Point as a variable to further calculate my overall center of mass.
Thanks for all the help,
In that case it should be easy!
First, alter the original script to have `"Filter" : EntityType.VERTEX && SketchObject.YES` to allow selection of those vertices.
Next, you will probably want to change definition.edges to definition.vertices (this does not have any geometric effect, it is just a variable name), and also widget.edge to widget.vertex.
Finally get rid of the call to evApproximateCentroid in favor of something like: