Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

How to Get Center of Gravity of a Surface

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
235
0
0
US

How do I get the COG of a surface?
I have tried the code below a few different ways and I couldn't get it to work.

It fails on the last line with:
"The Method GetCOGPosition Failed"

I believe this code is for Solids and Not Surfaces, but I cant find one for Surfaces.

Any direction would be greatly appreciated.

Code:
     Dim oSPAWorkbench As SPAWorkbench
     Dim oMeasureable As Measurable
     Dim oInertias As Inertias
     Dim oInertia 'As Inertia
     Dim COGArray(2)

     Set oSPAWorkbench = oPartDocument.GetWorkbench("SPAWorkbench")
     Set oInertias = oSPAWorkbench.Inertias

     oInertias.Add oBodySelectRef
     Set oInertia = oInertias.Item(1)
     oInertia.GetCOGPosition COGArray
 
Replies continue below

Recommended for you

Maybe I am doing it wrong, but I get a Compile Error. "Function or Interface Marked as Restricted" on the .GetCOG line.

Code:
            Dim COGArray
     
            Dim oSPAWorkbench As SPAWorkbench
            Set oSPAWorkbench = oPartDocument.GetWorkbench("SPAWorkbench")
            
            oSPAWorkbench.GetMeasurable(oPart.CreateReferenceFromObject(oBodySelectRef)).GetCOG COGArray
            
            Debug.Print "COG: " & COGArray(0), COGArray(1), COGArray(2)


I did find this link, that states you cant measure Inertia of a Surface, only a GeoSet.
Would that be the reason I am unable to get the COG to work?
 
"Function or Interface Marked as Restricted" is one of the most common errors in CATIA VBA, there are tons of replies about how to fix it.

Code:
Dim oSPAWorkbench As SPAWorkbench
Set oSPAWorkbench = oPartDocument.GetWorkbench("SPAWorkbench")

Dim meas ' as Measurable - must use Variant instead of typed variable
set meas = oSPAWorkbench.GetMeasurable(oPart.CreateReferenceFromObject(oBodySelectRef))

ReDim COGArray(2) ' x, y, z
meas.GetCOG COGArray
 
Status
Not open for further replies.
Back
Top