0

I'm trying to do some design automation in CATIA. I'm using python, I then record macros in CATIA and translates the code there to python code. Now I have stumbled upon a problem.

Below is the Macro from CATIA that i want to translate into pyhton code.

Language="VBSCRIPT"

Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument

Set product1 = productDocument1.Product

Set product1 = product1.ReferenceProduct

Set constraints1 = product1.Connections("CATIAConstraints")

Set reference1 = product1.CreateReferenceFromName("ContainerSchiff/Container1/!yz plane")

Set reference2 = product1.CreateReferenceFromName("ContainerSchiff/Container0/!Geometrical Set.1/Point.2")

----Here is the problem ----   Set constraint1 = constraints1.AddBiEltCst(catCstTypeDistance, reference1, reference2)

Set length1 = constraint1.Dimension

length1.Value = 300.000000

product1.Update 

End Sub

When translating this i have no idea what to do with catCstTypeDistance

If I leave it as is, then python will obviously complain about the name not being defined. If I pass it as a string complains as well. Below is the part of the python

else:
    add_container_skeleton(product1,i)
    product1.ReferenceProduct
    constraints1=product1.Connections("CATIAConstraints")
    Name1="ContainerSchiff/Container" + str(i-1) + "/!Container1/yz plane" 
    Name2="ContainerSchiff/Container" + str(i) + "/!Geometrical Set.1/Point.2"

    reference1= product1.CreateReferenceFromName(Name1)
    reference2 = product1.CreateReferenceFromName(Name2)

    constraint1 = constraints1.AddBiEltCst('catCstTypeDistance', reference1, reference2)

    length1 = constraint1.Dimension
    length1.Value = 300.000000

and the two different error messages that I get.

File "C:\Users\Mange\Documents\LIU\Catia part 2\first_draft.py", line 179, in place_containers
    constraint1 = constraints1.AddBiEltCst('catCstTypeDistance', reference1, reference2)
  File "<COMObject Connections>", line 3, in AddBiEltCst
ValueError: invalid literal for int() with base 10: 'catCstTypeDistance'
File "C:\Users\Mange\Documents\LIU\Catia part 2\first_draft.py", line 179, in place_containers
    constraint1 = constraints1.AddBiEltCst(catCstTypeDistance(), reference1, reference2)
NameError: name 'catCstTypeDistance' is not defined

How can I "access" this thing/object(?) from python?

Mange_Man
  • 41
  • 1
  • 6
  • This is a good question to have here. The title could be better targeted for searching, as "assessing the CATIA object" has a specific meaning in CATIA automation - it refers to getting the CATIA application object. A better title might be "Creating annotations in CATIA using Python" or "Catia enumeration values when using Python" – C R Johnson Apr 15 '19 at 16:21

2 Answers2

0

Solved it.

When not in CATIA itself catCstTypeDistance must be replaced with an integer corresponding to the constraint type. Which number corresponds to which constraint type can be found here http://catiadoc.free.fr/online/interfaces/enum_CatConstraintType.htm

Mange_Man
  • 41
  • 1
  • 6
0

The best way IMO, and not to use integers (and spend time translating them) is to use makepy to early bind the COM object. After that, you'll have constants listed in the relative .py files generated from the Type Libraries. After that, by importing:

from win32com.client import constants as CATEnum

and only after having obtained the Application object:

CATIA = Dispatch('CATIA.Application')

you will be able to access them:

CATEnum.catCstTypeDistance
Dewydd
  • 81
  • 5