Trying to get the coordinates of a specific point inside Geometry of the Sketch1 of a PartBody in Catia V5 Part.
import win32com.client
from pycatia import catia
# Open the CATIA document
caa = catia()
# Open the CATIA document
documents = win32com.client.Dispatch('CATIA.Application').Documents
file_name = './Part.CATPart'
part_document = documents.Open(file_name)
part = part_document.Part
bodies = part.Bodies
body = bodies.Item('PartBody')
# Access the Sketch
sketches = body.Sketches
sketch = sketches.Item('Sketch.1')
# Open the sketch for edition
factory2D = sketch.OpenEdition()
# Access the geometric elements in the sketch
geometric_elements = sketch.GeometricElements
# Find the specific point by name
point_name = 'Point.22'
point = None
for i in range(1, geometric_elements.Count + 1):
element = geometric_elements.Item(i)
if element.Name == point_name:
point = element
break
# Check if the point was found and retrieve its coordinates
if point is not None:
try:
# Assuming the point has X, Y properties directly accessible
x = point.X
y = point.Y
print(f"Coordinates of {point_name}: X={x}, Y={y}")
except AttributeError as e:
print(f"{point_name} found but coordinates could not be retrieved: {e}")
try:
coord = point.GetCoordinates()
except Exception as e:
print(e)
else:
print(f"{point_name} not found in the sketch.")
# Close the sketch edition
sketch.CloseEdition()
This raises errors, first one I don't know how to access point coordinates so I am trying point.X, but this raises: Point.122 found but coordinates could not be retrieved: Item.X . Also trying the method GetCoordinates() but this raises (-2147352567, 'Ocurrió una excepción.', (0, 'CATIAPoint2D', 'The method GetCoordinates failed', None, 0, -2147467259), None) .
Any sugestion?
GetCoordinatesyou need to hand over an array to this routine. It is not a function which returns values. So maybe it is the same in python.