'CATIA V5 Automation with Python Script

I'm a Python beginner and am attempting to do some automation in CATIA (Dassault Systemes CAD pacakge) with it, but I've run into an issue that I've been unable to solve despite searching extensively for a solution.

I'm trying to mimic the behavior of this VBA macro that was written within CATIAs native editor interface:

Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = drawingDocument1.Selection

selection1.Search "CATDrwSearch.DrwDimension,all"

For i = 1 To selection1.Count

Dim Dimension1 As DrawingDimension
Set Dimension1 = selection1.Item(i).Value

Dim DimDimValue As DrawingDimValue
Set DimDimValue = Dimension1.GetValue

DimDimValue.SetFormatPrecision 1, 0.001

Next

selection1.Clear

End Sub

To do so I wrote this Python script:

import win32com.client

CATIA = win32com.client.Dispatch('CATIA.Application')

ad = CATIA.ActiveDocument
sel = ad.Selection
sel.Search("CATDrwSearch.DrwDimension,all")

for i in range(1, sel.Count2+1):
    aDim = sel.Item2(i).Value
    aDimValue = aDim.GetValue
    aDimValue.SetFormatPrecision(1,0.001)

sel.Clear

Everything works except for the last operation within the for loop which returns the error:

Traceback (most recent call last):
<bound method DrawingDimension.GetValue of <win32com.gen_py.CATIA V5 
DraftingInterfaces Object Library.DrawingDimension instance at 0x67582896>>
File "C:/...", line 15, in <module>
aDimValue.SetFormatPrecision(1,0.001)
AttributeError: 'function' object has no attribute 'SetFormatPrecision'

Note that I used makepy to early bind the COM object otherwise Python doesn't recognize it (returns COMObject [unknown]), but from what I understand that shouldn't impact the script behavior.

I haven't been able to troubleshoot the error successfully because everything I can find suggests the object should have the attribute SetFormatPrecision. I've tried a bunch of other attributes that it should have as well, and none of them work. Because I'm trying to operate on a COM object, I'm not aware of a way to get a comprehensive list of legal attributes, or a way to get any information on the type of object I have stored in aDimValue

I inspected the makepy output file and it does include a function definition for SetFormatPrecision so my guess is I have a syntax issue, but I'm at a loss for what it is.

I know it's a narrowly focused question, but I'm hoping somebody with knowledge of CATIA Object Libraries sees this. And although I don't expect it, if somebody wants to go the extra mile, there's documentation on CATIAs Object Libraries here:

http://catiadoc.free.fr/online/CAAScdBase/CAAScdAutomationHome.htm

Drafting > Drafting Reference > DrawingDimValue

to get to the specific object I think I'm working with in aDimValue

Any help is appreciated. Thanks.



Solution 1:[1]

aDim.GetValue returns the function object, rather than calling the function. Use aDim.GetValue(). Same with sel.Clear() on the last line.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jared