What's new

Center of Mass

KeithH

Senior Member
Hello KeithH,

that's what the CoG_Scriptdoes for you automatically. In big EE lists (usually in big assemblies ot very complex parts) it is "slow", but should work in the end.
In medium sized assemblies it works well. May you would take a look at it. It saves typing and reduces transfer errors...

Regards
Stefan
hi idsk,

I haven't tried the script stuff yet. I'm still learning. But definetly will as I learn more
 

Hunter

Senior Member
Hello colleagues,



to speed the script up, you can comment out the last two lines of the script:
from this:
View attachment 33181
to this:
View attachment 33179

I've tested this not a lot (300 parts from a lot of minutes to ~5s). Maybe you have to do a manual Regenerate after running the script.
View attachment 33182

Regards
Stefan
Stefan,

Can you not perhaps add an option to your script to add a sphere to the location where the point is generated? I use your script a lot, it is very useful!
 

idslk

Alibre Super User
Hello Hunter,

thanks for the flowers :)
i am a little short of time now...
I'll try to make it for assemblies only - if i would put a ball in a single part, the ball would consist of the part material an would change the part weight...
I hope that i can create a zero density material for the ball for the assembly variant...
Maybe next week...

Regards
Stefan
 

idslk

Alibre Super User
Can you not perhaps add an option to your script to add a sphere to the location where the point is generated?
Hello Hunter,
i've added a CoG_Ball to the script with version 0.4 for assemblies.
There is a problem as so often - not everything is accessible trought the API...
The next is, a geometry with visible faces (point vs ball) needs regenerating...so using the automatic ball will cost time...

Due to the limited API , i'm not able to create a material with no density...
It is no problem running the script for the first time , but every further time, specially when adding parts or changing position of parts in the assembly,
the CoG changes and the CoG_Ball, which has his own mass, has an influence to the system.
I've made a workaround:
Before running the script, create a Material in your custom library with a densitiy of 0. 000 000 000 1 (only one 0 ist not "enough"...)and name it "no_density" (don't forget to save).

upload_2021-4-5_21-54-7.png

The script will try to set the material of the ball, so that the ball will have no weight and no influence...
If the script won't find this material you will get a printed warning in the console of AlibreScript...

upload_2021-4-5_22-17-31.png

Demo assembly before running the script:
upload_2021-4-5_21-59-56.png
first message:
upload_2021-4-5_22-0-27.png

ask for ball size:
upload_2021-4-5_22-1-6.png
if you press cancel, the script will run witout creating the ball. This is quicker but creates only the 3D-Point...

Message after chosing the ball size:
upload_2021-4-5_22-1-54.png

console output:
upload_2021-4-5_22-3-16.png

console output script run a second time:
upload_2021-4-5_22-4-38.png

Demo assembly after script run:
upload_2021-4-5_22-6-22.png

Attention, the CoG_Ball part will be saved with your assembly if you don't delete it before saving.
It will be newly created if you run the script after deleting it...

This is some kind of BETA...please test with files you "don't need"

If there are wishes for improvements... they are wellcome

Regards
Stefan
 

Attachments

  • CoG_to_EE_forum_V04.py
    7.6 KB · Views: 10

Hunter

Senior Member
Thanks, Stefan, I'll give it a try.

One could make the CoG sphere a surface by deleting one of its faces (probably not trivial to do via script), or use a predefined surface (imported?) so that it doesn't have any mass. Anyway, I'm not trying to give you more work, I appreciate the effort.
 

NateLiqGrav

Alibre Super User
@idslk Stefan, FYI this and a few other of your scripts I used recently (Length of 2d/3d Sketch) have this line too low in the script:
Code:
win = Windows()

Must be before these function calls:
Code:
scriptversion(made_with)
alibreversion(made_with_Alibreversion)
 

NateLiqGrav

Alibre Super User
Thanks, Stefan, I'll give it a try.

One could make the CoG sphere a surface by deleting one of its faces (probably not trivial to do via script), or use a predefined surface (imported?) so that it doesn't have any mass. Anyway, I'm not trying to give you more work, I appreciate the effort.
Surfaces are considered Reference Geometry and are not shown in the assembly unless you right click the part and "Show Reference Geometry". Additionally and more importantly I can't find any way to get surfaces to show at all in the drawing.
 

jhiker

Alibre Super User
I'm afraid the script didn't work for me - here's the output. Not sure what I did wrong, if anything. The script is in the script library and I created the 'no_density' material.

Alibre Script build 343305
IronPython 2.7.10.0 Interactive Console
For documentation visit http://docs.python.org/2.7
The complete standard library is available

Console commands available:
history : Prints history of entered commands
cls : Clears the screen
help : Shows the list of console commands
run : Executes the current script
run arg1 arg2 : Executes the current script, pass arguments
run "scriptname" : Executes a specific script
run "scriptname" arg1 arg2 : Executes a specific script, pass arguments

>>>
Traceback (most recent call last):
File "<string>", line 66, in <module>
File "<string>", line 40, in scriptversion
NameError: name 'win' is not defined
>>>
Traceback (most recent call last):
File "<string>", line 66, in <module>
File "<string>", line 40, in scriptversion
NameError: name 'win' is not defined
>>>
Traceback (most recent call last):
File "<string>", line 66, in <module>
File "<string>", line 40, in scriptversion
NameError: name 'win' is not defined
>>>
Traceback (most recent call last):
File "<string>", line 66, in <module>
File "<string>", line 40, in scriptversion
NameError: name 'win' is not defined
>>>
 

jhiker

Alibre Super User
Just for fun I ran the 'old' CofG script on a simple assembly.
Unless I am misreading this the 'Y' value in the script is a decimal point out compared with the built-in' Alibre calculation.
CofG.png
 

NateLiqGrav

Alibre Super User
Traceback (most recent call last):
File "<string>", line 66, in <module>
File "<string>", line 40, in scriptversion
NameError: name 'win' is not defined
See my post two above your about moving up win = Windows()
Also the old script was probably only using CM
 
Top