try: import win32com.client except: print "Ooops Pywin32 needed !" app=win32com.client.Dispatch('CATIA.Application') doc=app.ActiveDocument.Product a=doc.Analyze.Volume print "The Volume is: ", a
Automation of Applications with Python for Windows – The Script Collection
try: import win32com.client except: print "Ooops Pywin32 needed !" app=win32com.client.Dispatch('CATIA.Application') doc=app.ActiveDocument.Product a=doc.Analyze.Volume print "The Volume is: ", a
Hi,
I’m trying to get the center of gravity for a product by using this:
a = doc.Analyze.GetGravityCenter
But I only get the method of the object itself instead of the resulting x,y,z.
Do you know how to make this work?
Best regards
Marcus
I`m not sure, but perhaps GetGravityCenter is a Method? I would try:
a = doc.Analyze.GetGravityCenter()
Then I would expect the value of “a” as a tuple. Something like (100, 22.32, 98.12).
Yeah, it’s a method and I agree with you that the expected value of “a” would be a tuple.
I think the problem is that the method GetGravityCenter() in Catia needs an array variant as an argument (CATSafeArrayVariant oGravityCenterCoordinatesArray) to store the CoG values. I have run makepy in win32com and it generates the following function:
def GetGravityCenter(self, oGravityCenterCoordinatesArray=defaultNamedNotOptArg):
return self._ApplyTypes_(1610940419, 1, (24, 0), ((8204, 3),), ‘GetGravityCenter’, None,oGravityCenterCoordinatesArray)
From what I have read the (24, 0) means the function returns “void” and (8204, 3) means the parameter is an IN/OUT parameter that is an array of variants.
However, when trying to include anything (list, string, etc.) as a parameter to the method in Python it only returns the inputed argument…
Any suggestion to get around this?
Hi Marcus,
long time ago I had a similar problem in CATIA with array variants. Marc commented it on https://sourceforge.net/p/pywin32/bugs/350/. But I couldn`t solve it for my use case. Sorry.
Mustafa
Hi Mustafa,
do you have any information on the state of the issue above? I’m running into the same problem described by Marcus, and it’s pretty much a deal-breaker for me if reading coordinates of CATIA objects become impossible. I could not find a working solution anywhere, very unfortunate :/.
Cheers!
Hi Andreas,
sorry, unfortunately not. But you could try comtypes, which is another Python module for MS COM. It works similar to pywin32. Perhaps you have luck…
Mustafa