Define Assembly Axis coincident with Center Of Mass

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 208
Contact:

Define Assembly Axis coincident with Center Of Mass

Unread post 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.
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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
User avatar
Glenn Schroeder
Posts: 1518
Joined: Mon Mar 08, 2021 11:43 am
Answers: 23
Location: southeast Texas
x 1754
x 2126

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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.
"On the days when I keep my gratitude higher than my expectations, well, I have really good days."

Ray Wylie Hubbard in his song "Mother Blues"
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 208
Contact:

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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 2821 times
GrahamK
Posts: 6
Joined: Mon Jun 14, 2021 12:36 pm
Answers: 0
x 1
x 3

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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.
User avatar
SPerman
Posts: 2035
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2207
x 1860
Contact:

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 208
Contact:

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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
colt
Posts: 56
Joined: Tue Mar 30, 2021 5:43 pm
Answers: 0
x 14
x 22

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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
Attachments
Assem1.SLDASM
(211.47 KiB) Downloaded 75 times
User avatar
DanPihlaja
Posts: 839
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 804
x 973

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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?
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 208
Contact:

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 208
Contact:

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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!
Alin
Posts: 313
Joined: Sun Mar 14, 2021 9:46 am
Answers: 3
x 265
x 391

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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).
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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).
Alin
Posts: 313
Joined: Sun Mar 14, 2021 9:46 am
Answers: 3
x 265
x 391

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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/
Alin
Posts: 313
Joined: Sun Mar 14, 2021 9:46 am
Answers: 3
x 265
x 391

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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
User avatar
DanPihlaja
Posts: 839
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 804
x 973

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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.
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
KevinC
Posts: 90
Joined: Fri Mar 12, 2021 10:14 am
Answers: 1
x 16
x 66

Re: Define Assembly Axis coincident with Center Of Mass

Unread post 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
Post Reply