Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Center of Gravity of a selected Surface

Status
Not open for further replies.

Aviatorbarath

New member
Joined
Dec 27, 2012
Messages
35
Location
US
How to get the center of gravity coordinates for the selected surface. What function can be used for it ?

I tried with the below code. but its not giving correct values..i selected a surface with dimention 8x2 rectangle. and the below code gives the values as 10, 0 , 5.08

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory

Set objNetwork = CreateObject("Wscript.Network")
Set hb1=CATIA.ActiveDocument.Part.InWorkObject
Set hsf=CATIA.ActiveDocument.Part.HybridShapeFactory
Set prt=CATIA.ActiveDocument.Part
Set sel=CATIA.ActiveDocument.Selection
Set SPAWorkBench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set planeZX = CATIA.ActiveDocument.Part.OriginElements.PlaneZX

Dim inpt1(0)
Dim inpt2(0)
Dim inpt3(0)
inpt1(0) = "Face"
inpt2(0) = "Plane"
inpt3(0) = "Point"

MsgBox "Select a Surface"
Status = Sel.SelectElement2(inpt1, "Select a Surface", False)
Dim selectedElement1
'Set selectedElement1 = Sel.Item(1)
Set selectedElement1 = Sel.Item(1).Value
Dim m
m = selectedElement1.Name
MsgBox m


Dim reference1
Set reference1 = Part1.CreateReferenceFromName(m)

Dim CurrWorkbench
Set CurrWorkbench = partDocument1.GetWorkbench("SPAWorkbench")

Dim Measure
Set Measure = CurrWorkbench.GetMeasurable(reference1)

Dim originCoord(2)

Measure.GetCOG originCoord

MsgBox (originCoord(0)) & " " & (originCoord(1)) & " " & (originCoord(2))

End Sub

Can someone tell me hat went wrong in the above code

Thanks & Regards
Barath
 
Have you tried simply using Measure Item or Measure Intertia?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top