1 year ago

#290919

test-img

Charles

Python and Catia V5 Defining axis for volumic operations

I am trying to do Catia V5 automation using python. I managed to create my baseline sketch without any problem however, I am unable to set axis for volumic operations. Here is a simple example that (should) create a round ball by revolving around the global Z axis :

import os
from win32com.client import Dispatch
CATIA = Dispatch('CATIA.Application')
CATIA.Visible = True
from pathlib import Path


# Creating the part and the sketch 

partDocument1 = CATIA.Documents.Add("Part")
part1 = partDocument1.Part
bodies1 = part1.Bodies
body1 = bodies1.Item("PartBody")
sketches1 = body1.Sketches
originElements1 = part1.OriginElements
reference1 = originElements1.PlaneYZ
sketch1 = sketches1.Add(reference1)


# Creating the baseline sketch 

sketch1.OpenEdition()
geometricElements1 = sketch1.GeometricElements
axis2D1 = geometricElements1.Item("AbsoluteAxis")
circle2D1 = sketch1.Factory2D.CreateCircle(0.000000, 0.000000, 100, 1.570796, 4.712389)

# Volumic operation

shapeFactory1 = part1.ShapeFactory
reference8 = part1.CreateReferenceFromName("")
shaft1 = shapeFactory1.AddNewShaftFromRef(reference8)
reference9 = part1.CreateReferenceFromObject(sketch1)
shaft1.SetProfileElement(reference9)
hybridShapes1 = body1.HybridShapes
hybridShapeLineExplicit1 = hybridShapes1.Item("Z Axis")
reference10 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)
shaft1.RevoluteAxis = reference10

part1.UpdateObject(shaft1)
part1.Update()

And here is the traceback :

hybridShapeLineExplicit1 = hybridShapes1.Item("Z Axis")

  File "<COMObject <unknown>>", line 2, in Item

I think my problem comes from the fact that this axis is located "outside" the sketch used for the shaft. I dont know how to define an axis in this python "vba-like" code.

Could you help me ?

Thank you very much !

python

vba

catia

0 Answers

Your Answer

Accepted video resources