Closed CesarAero closed 8 months ago
You need to read the source code / documentation to see what objects a class method requires.
For example add_new_project requires a reference object, not a sketch object.
Take a look at the examples for creating references as it's a common requirement. This is not a pycatia thing but a CATIA COM interface thing.
Thank you evereux for your message,
I managed to fix the problem of the reference to the XY plane by using the Reference class and I don’t need anymore to duplicate the plane.
However the problem with projecting the sketch persists. I have also tried to pass the curve inside the sketch to the add_new_project
function through the interface functions edge and shape from pycatia.mec_mod_interfaces as:
from pycatia.mec_mod_interfaces.shape import Shape
sketch_curve = sketch_1.GeometricElements.item("circle_to_project")
proj_sketch = hsf.add_new_project(Shape(sketch_curve), plane_proj)
proj_sketch.name = "proj_sketch"
aux_bodies.append_hybrid_shape(proj_sketch)
But this operation is not possible:
I have checked some forums about programing in CATIA and this operation in VB is simply:
Set reference1 = part.CreateReferenceFromObject(sketch_1)
Set reference2 = part.CreateReferenceFromObject(plane_proj)
Set hybridShapeProject = hybridShapeFactory.AddNewProject(reference1, reference2)
There is no need to convert the sketches because I guess that the VB interface takes all this into account.
I couldn't find helpful information about how to use a sketch in hybrid operations using pycatia. Could you give me some advice about how to face this issue? I could in exchange prepare an example script for this specific problem and give it to you so you can post is as example for this particular operation. Then future users can go directly and learn from this script.
Be careful with how you're using pycatia here. You're calling the COM interface methods directly and not the pycatia based ones so you could get unexpected behavior. I don't know if that is the issue here.
eg:
sketch_curve = sketch_1.GeometricElements.item("circle_to_project")
See the GeometricElements
? pycatia uses pythons naming conventions standards so you won't see capitalized class method names. See sketch.geometric_elements
I couldn't find helpful information about how to use a sketch in hybrid operations using pycatia.
I get this type of question a lot but the reality is, if you can do it VBA, it's pretty much the same in pycatia, just a different language.
Anyways, this works for me (note the class method names are all lower_case). I've a geometrical set called ConstructionGeometry that contains a sketch Sketch.1
and a plane Plane.1
.
from pycatia import catia
from pycatia.mec_mod_interfaces.part_document import PartDocument
caa = catia()
application = caa.application
document: PartDocument = application.active_document
part = document.part
hybrid_bodies = part.hybrid_bodies
construction_geometry = hybrid_bodies.item("ConstructionGeometry")
hybrid_shapes = construction_geometry.hybrid_shapes
sketches = construction_geometry.hybrid_sketches
sketch = sketches.get_item_by_name("Sketch.1")
plane = hybrid_shapes.item("Plane.1")
ref_sketch = part.create_reference_from_object(sketch)
ref_plane = part.create_reference_from_object(plane)
hsf = part.hybrid_shape_factory
projection = hsf.add_new_project(ref_sketch, ref_plane)
construction_geometry.append_hybrid_shape(projection)
part.update()
Looking at your small sample above it looks like you still haven't created a reference from the sketch.
There is no need to convert the sketches because I guess that the VB interface takes all this into account.
I don't know what you mean here?
I found my errors. As you mentioned, I was using the COM interface methods directly and not the pycatia based ones. Now my script works perfectly and does the job. I will pay more attention to this in the future...
I leave here the fixed code in case you want to use it somehow as example or if someone else runs into the same problem: problem_reproducer.txt
Glad you got it fixed. 👍
Closing as issue seems to be now resolved.
Dear pycatia community,
I am facing a difficulty with pycatia and I couldn't find the right place to ask it. I hope that you could provide me some support as I couldn't find the right answer in the pycatia documentation, the CATIA macro recorder or asking ChatGPT...
My problem is linked with the usage of iObjects for hybrid shape operations (Generative Shape Design workbench tools). It is quite simple to use the GUI to project a sketch or to select a plane and make hybrid operations but accessing to the right elements via pycatia is quite challenging. I have created a reproducer of my problem where a simple tasks needs to be achieved: to project a sketch into another plane. Here you can download the pycatia code that I've coded to show my problem (I changed the extension to .txt because I couldn't send .py codes)
problem_reproducer.txt
I am facing 2 main problems in this reproducer :
I am aware that working with sketches and hybrid bodies is challending even in CATIA VB due to the differences in the used workbenches. Which would be the right way to address to the part bodies and use them in hybrid operations? Or should I convert them always into iObjects?
Thank you in advance!