Получить координаты точки с помощью PyCatiaPython

Программы на Python
Anonymous
Получить координаты точки с помощью PyCatia

Сообщение Anonymous »

Попытка получить координаты определенной точки внутри геометрии эскиза 1 PartBody в детали Catia V5.

Код: Выделить всё

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()

При этом возникают ошибки. Во-первых, я не знаю, как получить доступ к координатам точки, поэтому пытаюсь использовать point.X, но возникает ошибка: Point.122 найден, но координаты не могут быть получены: Элемент.X . Также пытаюсь использовать метод GetCoordinates(), но это вызывает ошибку (-2147352567, 'Ocurrió una excepción.', (0, 'CATIAPoint2D', 'Ошибка метода GetCoordinates', None, 0, -2147467259), None) < /code>.
Есть какие-нибудь предложения? Спасибо!

Подробнее здесь: https://stackoverflow.com/questions/788 ... ng-pycatia

Вернуться в «Python»