-2

The command AddNewDirectionByCoord(0.000000, 0.000000, 1.000000) got the job done. –

Decode of The command AddNewDirectionByCoord(0.000000, 0.000000, 1.000000) got the job done. –

An error occurred: <unknown>.HybridShapes
An error occurred: <unknown>.HybridShapes
Traceback (most recent call last):
  File "C:\Users\lenovo\PycharmProjects\pythonProject\venv\Trail_10.py", line 97, in <module>
    hybridShapeLineExplicit1 = hybridShapes1.Item("Z Axis")
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<COMObject <unknown>>", line 2, in Item
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'CATIAHybridShapes', 'The method Item failed', None, 0, -2147352573), None)

Process finished with exit code 1
import win32com.client as win32

def main():
    try:
        catia = win32.Dispatch("CATIA.Application")
        documents = catia.Documents
        part_document = documents.Add("Part")
        part = part_document.Part

        # Access the HybridShapes collection
        hybrid_shapes = part.HybridShapes

        # Create a point hybrid shape
        point = hybrid_shapes.AddNewPointCoord(0, 0, 0)
        point.Name = "MyPoint"  # Set a name for the point

        # Access the hybrid shape by name using .Item
        retrieved_point = hybrid_shapes.Item("MyPoint")

        print("Retrieved point hybrid shape:", retrieved_point.Name)

    except Exception as e:
        print("An error occurred:", str(e))

if __name__ == "__main__":
    main()
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • It might be helpful to get more information on what the error is like (shown here)[https://stackoverflow.com/a/36080159/10924296]. The traceback is making me think there is no .Item method, but I am not familiar with COM scripting for CATIA – Reedinationer Aug 24 '23 at 20:28
  • _HybridShapes_ belong to a hybridbody and not to the part object (you may have a look on the documentation) – Shrotter Aug 24 '23 at 21:08
  • Assuming that this is CATIA V5-6: You can't add fetaures to a HybridShapes collection. It has no Add method. HybridShapes are created by the HybridShapeFactory - the method AddNewPointCoord belongs to this factory. If the newly created feature should be stored with the Part, you need to create a Geometrical Set (HybridBody) as well. The HybridBody has a method AppendHybridShape. – gdir Aug 25 '23 at 14:35
  • Traceback (most recent call last): File "C:\Users\lenovo\PycharmProjects\pythonProject\shaft.py", line 39, in point = hybrid_shapes1.AddNewPointCoord(0, 0, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\lenovo\PycharmProjects\pythonProject\venv\Lib\site-packages\win32com\client\dynamic.py", line 638, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: .AddNewPointCoord Process finished with exit code 1 Still not worked can you suggest one mote way – Shyam Teja Aug 25 '23 at 21:27
  • 1
    Have you modified your code according the hints in the comments (so please edit your question)? I guess you still don't use the HybridShapeFactory for the AddNewPointCoord method – Shrotter Aug 26 '23 at 07:24
  • Sir, can you correct the code 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 – Shyam Teja Aug 26 '23 at 16:51
  • Sir can you please rewrite the correct code – Shyam Teja Aug 26 '23 at 17:14
  • 1
    Please, don't post code in the comments. Edit your question instead. Also include a description of your problem (and not only an error message) – Shrotter Aug 26 '23 at 17:29

0 Answers0