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!

Read point coordinates in CATIA using python

Status
Not open for further replies.

Jegsaran

Automotive
Joined
Dec 16, 2020
Messages
42
Location
IN
I have a VBA code which gets the centerpoint coordinate of an edge. I want that to be done in python.

Code:
Dim partDocument1 As Document
    Set partDocument1 = CATIA.ActiveDocument
    
    Dim part1 As Part
    Set part1 = partDocument1.Part

    Dim ref As Reference
    Dim SPA As Workbench
    Dim Measurable
    Dim csCoords(2)
    Dim Sel As Selection

    Set Sel = CATIA.ActiveDocument.Selection
    Set ref = Sel.Item(1).Reference
    Set SPA = partDocument1.GetWorkbench("SPAWorkbench")
    Set Measurable = SPA.GetMeasurable(ref)
    Measurable.GetCenter csCoords
    Sel.Clear

I tried various methods mentioned below using win32com & pycatia but nothing worked.

Python:
# Pycatia
coordinates = measurable.get_point()

#win32com.client
coordinates = [0.0, 0.0, 0.0]
measurable.GetPoint(coordinates)

coordinates = pythoncom.CreateSafeArray(pythoncom.VT_VARIANT, 3)
measurable.GetPoint(coordinates)
 
documentation of pycatia seems to be a bit incomplete...
this works on my side...

from pycatia import catia
catia_app = catia()
documents=catia_app.documents
print(documents)
part = documents.item(1).part
spa_workbench = documents.item(1).spa_workbench()

hybrid_bodies = part.hybrid_bodies
hybrid_body = hybrid_bodies.get_item_by_name('construction_points')
shapes = hybrid_body.hybrid_shapes.items()

for point in shapes:
reference = part.create_reference_from_object(point)
measurable = spa_workbench.get_measurable(reference)
coordinates = measurable.get_point()
print(f'{point.name}: {coordinates}')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top