Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick 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
Dec 16, 2020
42
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)
 
Replies continue below

Recommended for you

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