Page 1 of 1

Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 8:07 am
by Rob
I'm looking to create a pivot point at exactly the Assembly COM.

So far I have achieved this by creating a COM feature in the assembly and then creating an assembly sketch with a single sketch point that I drag coincident to the COM point then using this point and a Plane to define the Axis.

This works but the sketch point does not update when the COM moves.

To get an update I have to delete the sketch point coincident relation and reapply it, which is insanely tedious.

Is there a nicer way to do this? Seems like there should be.

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 8:29 am
by mattpeneguy
Rob wrote: Thu Oct 28, 2021 8:07 am I'm looking to create a pivot point at exactly the Assembly COM.

So far I have achieved this by creating a COM feature in the assembly and then creating an assembly sketch with a single sketch point that I drag coincident to the COM point then using this point and a Plane to define the Axis.

This works but the sketch point does not update when the COM moves.

To get an update I have to delete the sketch point coincident relation and reapply it, which is insanely tedious.

Is there a nicer way to do this? Seems like there should be.
I just put a center of mass in an assembly yesterday. I hardly ever use it, but what you are asking should work.
Just tried selecting the COM and a sketch point and yep, I can't make a relation. I get it this may be intentional, as I can see some horrible circular reference scenarios, but when's that ever stopped SW? SW's motto should be "always giving the users enough rope to hang themselves".
Hey @gupta9665, it appears the COM is accessible in the API, but I'm guessing it won't update and any macro you made assigning the axis to the COM via macro would require re-running the macro? Maybe this could be handled by a Macro feature that would update with each rebuild?
http://help.solidworks.com/2012/English ... ple_vb.htm

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 8:53 am
by Glenn Schroeder
mattpeneguy wrote: Thu Oct 28, 2021 8:29 am I just put a center of mass in an assembly yesterday. I hardly ever use it, but what you are asking should work.
Just tried selecting the COM and a sketch point and yep, I can't make a relation.
I get it this may be intentional, as I can see some horrible circular reference scenarios, but when's that ever stopped SW? SW's motto should be "always giving the users enough rope to hang themselves".
Hey @gupta9665, it appears the COM is accessible in the API, but I'm guessing it won't update and any macro you made assigning the axis to the COM via macro would require re-running the macro? Maybe this could be handled by a Macro feature that would update with each rebuild?
http://help.solidworks.com/2012/English ... ple_vb.htm
I tried it. It wouldn't let me apply a relation by Ctrl+ selecting the sketch point (or end point of a line) and the CoM, but it would let me drag it to the CoM and apply a relation that way. I moved a component, which of course caused the CoM to move. The sketch point did not move with it, even after a Ctrl+Q rebuild. I opened the sketch, and it showed the Coincident relation, but it still didn't update.

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 9:28 am
by Rob
mattpeneguy wrote: Thu Oct 28, 2021 8:29 am I just put a center of mass in an assembly yesterday. I hardly ever use it, but what you are asking should work.
Just tried selecting the COM and a sketch point and yep, I can't make a relation. I get it this may be intentional, as I can see some horrible circular reference scenarios, but when's that ever stopped SW? SW's motto should be "always giving the users enough rope to hang themselves".
Hey @gupta9665, it appears the COM is accessible in the API, but I'm guessing it won't update and any macro you made assigning the axis to the COM via macro would require re-running the macro? Maybe this could be handled by a Macro feature that would update with each rebuild?
http://help.solidworks.com/2012/English ... ple_vb.htm
Thanks Matt :D

I was hunting the correct API calls unsuccessfully but you showed me the way..

I ended up creating two planes to define the axis and then update the plane offsets based on the current COM.

It's a hack for sure but its working..
image.png

Code: Select all

Option Explicit

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks
    
    Dim swModel As SldWorks.ModelDoc2
    Set swModel = swApp.ActiveDoc
    
    Dim swMassProperty As SldWorks.MassProperty
    Set swMassProperty = swModel.Extension.CreateMassProperty
    
    Dim vComPts As Variant
    vComPts = swMassProperty.CenterOfMass
    
    Debug.Print vComPts(0), vComPts(1), vComPts(2)
    
    Dim swDimension As SldWorks.Dimension
    
    Set swDimension = swModel.Parameter("D1@COMPlaneXZ")
    
    swDimension.SystemValue = Abs(vComPts(1))
    
    Set swDimension = swModel.Parameter("D1@COMPlaneYZ")
    
    swDimension.SystemValue = Abs(vComPts(0))
    
    swModel.EditRebuild3

End Sub

[edit] I added the macro to the design binder so it's pretty convenient now
image.png
image.png (4.91 KiB) Viewed 2832 times

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 10:02 am
by GrahamK
I could be clever and say Catia as this will do exactly what you want :)

What you can try is:

Create COM
Then create 3 global variables which you can assign the values in XYZ of COM (make sure you set to automatically rebuild)
Create 3 planes paralel to Front, top, Right and link to the 3 global variables.
Create point of intersection of these 3 planes.

If the COM changes this will update the global variables which in turn updates the planes and then the point.

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 10:07 am
by SPerman
Rob wrote: Thu Oct 28, 2021 9:28 am
It's a hack for sure but its working..

That should be SW motto.

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 10:46 am
by Rob
GrahamK wrote: Thu Oct 28, 2021 10:02 am I could be clever and say Catia as this will do exactly what you want :)

What you can try is:

Create COM
Then create 3 global variables which you can assign the values in XYZ of COM (make sure you set to automatically rebuild)
Create 3 planes paralel to Front, top, Right and link to the 3 global variables.
Create point of intersection of these 3 planes.

If the COM changes this will update the global variables which in turn updates the planes and then the point.
Perfect Graham!!

This is basically what my macro did but via equations!
SW warns about a potential circular ref, but that's fair enough
image.png

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 10:54 am
by colt
Another way is to create massless part that you can mate to the cg. Then you can mate to that object. It seems to follow the cg accurately on rebuild.
Capture.PNG

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 10:55 am
by DanPihlaja
GrahamK wrote: Thu Oct 28, 2021 10:02 am I could be clever and say Catia as this will do exactly what you want :)

What you can try is:

Create COM
Then create 3 global variables which you can assign the values in XYZ of COM (make sure you set to automatically rebuild)
Create 3 planes paralel to Front, top, Right and link to the 3 global variables.
Create point of intersection of these 3 planes.

If the COM changes this will update the global variables which in turn updates the planes and then the point.
That is a great idea.

The only issue that I see is when/if one of the distances goes into the negative or becomes 0. How do you determine positive/negative direction?

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 11:19 am
by Rob
dpihlaja wrote: Thu Oct 28, 2021 10:55 am That is a great idea.

The only issue that I see is when/if one of the distances goes into the negative or becomes 0. How do you determine positive/negative direction?
I had the same concern, so I mated so that the assembly origin was at an extreme corner

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 11:22 am
by Rob
colt wrote: Thu Oct 28, 2021 10:54 am Another way is to create massless part that you can mate to the cg. Then you can mate to that object. It seems to follow the cg accurately on rebuild.

Capture.PNG
Up there for thinking, down there for dancing!

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 4:45 pm
by Alin
Rob wrote: Thu Oct 28, 2021 8:07 am I'm looking to create a pivot point at exactly the Assembly COM.

So far I have achieved this by creating a COM feature in the assembly and then creating an assembly sketch with a single sketch point that I drag coincident to the COM point then using this point and a Plane to define the Axis.

This works but the sketch point does not update when the COM moves.

To get an update I have to delete the sketch point coincident relation and reapply it, which is insanely tedious.

Is there a nicer way to do this? Seems like there should be.
In SW2022, you just need to define the Coordinate System. Its origin, planes and axes are now selectable and usable for many downstream operations (including sketching, mates and more).

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 5:24 pm
by mattpeneguy
Alin wrote: Thu Oct 28, 2021 4:45 pm In SW2022, you just need to define the Coordinate System. Its origin, planes and axes are now selectable and usable for many downstream operations (including sketching, mates and more).
Hmm. That works and should be a robust solution!

BTW, who championed adding those planes and axes to the coordinate systems? I'd like to thank them. I'd be testing this out in the Beta if we weren't stuck on Windows 7 (can't upgrade past 2020).

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 6:42 pm
by Alin
mattpeneguy wrote: Thu Oct 28, 2021 5:24 pm Hmm. That works and should be a robust solution!
Yes, the new functionality is pretty crazy. We can even achieve freedom from the ORIGIN!!!
I stress-test the enhancements and reported the results here:

https://www.engineersrule.com/coordinat ... -and-axes/

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Oct 28, 2021 6:52 pm
by Alin
mattpeneguy wrote: Thu Oct 28, 2021 5:24 pm BTW, who championed adding those planes and axes to the coordinate systems? I'd like to thank them.
I asked the same question here:
https://r1132100503382-eu1-3dswym.3dexp ... NJjqu20FVg

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Fri Oct 29, 2021 8:22 am
by DanPihlaja
mattpeneguy wrote: Thu Oct 28, 2021 5:24 pm Hmm. That works and should be a robust solution!

BTW, who championed adding those planes and axes to the coordinate systems? I'd like to thank them. I'd be testing this out in the Beta if we weren't stuck on Windows 7 (can't upgrade past 2020).
Its been in the top ten every single time I have ever participated in it.

Re: Define Assembly Axis coincident with Center Of Mass

Posted: Thu Nov 11, 2021 1:31 pm
by KevinC
colt wrote: Thu Oct 28, 2021 10:54 am Another way is to create massless part that you can mate to the cg. Then you can mate to that object. It seems to follow the cg accurately on rebuild.

Capture.PNG
Along the lines of colt's post, if you use a surface instead of a solid body, then you needn't worry about any effects the CG ball has on the CG calcs as it is massless and its material selection is..immaterial.
image.png
EDIT:
And apply the black/while tile texture to the surface ball to give it a CG look:
image.png