def test_centre_of_gravity(): with CATIADocHandler(cat_part_measurable) as handler: catia = handler.catia document = handler.document spa_workbench = create_spa_workbench(document.document) part = document.part() bodies = part.get_bodies() body = bodies[0] reference = part.create_reference(body) measurable = create_measurable(spa_workbench, reference) catia_measurable = CATIAMeasurable(measurable) gx = 86.065202 gy = 81.364587 gz = 10.000000 centre_of_gravity = catia_measurable.get_cog(catia) assert (gx, gy, gz) == (round(centre_of_gravity[0], 6), round(centre_of_gravity[1], 6), round(centre_of_gravity[2], 6))
document = catia.document() part = document.part() spa_workbench = create_spa_workbench(document.document) bodies = part.get_bodies() body_names = part.get_bodies_names() # body_names = ['PartBody', 'EmptyPartBody'] # gets first body in bodies list. body = bodies[0] # or get the body by name body_by_name = part.get_body_by_name('PartBody') # equivalent to VB CreateReferenceFromObject() reference = part.create_reference(body) # equivalent to VB GetMeasurable() measurable = create_measurable(spa_workbench, reference) # the measurable object catia_measurable = CATIAMeasurable(measurable) # run the VB function Measurable.GetCOG() center_of_gravity = catia_measurable.get_cog(catia) # center_of_gravity = (86.06520158074527, 81.36458658122612, 10.0) print(center_of_gravity)