Aviatorbarath
New member
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
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