Hi, folks.

There's a question at the end, but first some necessary information.

To recap:  I run makepy on a type library called femap.tlb, and ask it to write its results to a file called PyFemap.py so I can just import that file into my code.  When I try to call a method from this TLB that uses an output argument (a call by reference), I always get some kind of error about the output argument.

I have discovered the immediate problem, which is that only one class defined in PyFemap is actually used.  This is the 'gateway' class, called Imodel.  Everything else in PyFemap is just ignored.

I have also discovered the immediate cause of this problem.  You have to start with an Imodel object to get any other object in the TLB.  Thus, when I want access to Femap's screen-picking Selector, I use Imodel's 'feSelector' attribute.  Here's where the problem occurs.

The 'feSelector' is supposed to be implemented by the ISelector class:
class ISelector(DispatchBaseClass):
    CLSID = IID('{8A3498F7-A383-419E-8117-86A0305175FF}')


But, in Imodel, the 'feSelector' attribute is defined as follows:
"feSelector": (10349, 2, (9, 0), (), "feSelector", None)

That 'None' at the end is the "resultCLSID" entry, and apparently that's how 'feSelector' is supposed to be connected to 'ISelector'.  I edited PyFemap.py and manually replaced that 'None' with the CLSID from the ISelector definition shown above:
"feSelector": (10349, 2, (9, 0), (), "feSelector", '{8A3498F7-A383-419E-8117-86A0305175FF}')

Problem solved!  The code starts using the ISelector class, and I can get my output argument!

Swell.  Imodel has 315 (three hundred and fifteen) such entries, and there are hundreds more on dozens of other objects, so manual editing to correct all of them is not feasible. 

Question:  can something be done to makepy to fix this, or this an inherent and hopeless flaw in the TLB?


Thanks,
Greg Antal

Gregory W. Antal
Senior Technical Advisor
ATA Engineering, Inc.
11995 El Camino Real, Suite 200	
San Diego, CA  92130
www.ata-e.com

[EMAIL PROTECTED]
858-480-2072  (Phone)
858-792-8932  (Fax)

----------------------------------
Greg Antal wrote:
Hi everybody.

It's been nearly 2 weeks since I posted this, and nobody has responded.  If anybody has any ideas, I'd be glad to hear them.  I'll provide more info on anything anybody thinks is relevant.

Thanks,
Greg Antal

Greg Antal wrote:
Mark:

Thanks for getting back to me.  I'm afraid it still doesn't work.  With the method definition set to
    def count(self, entityTYPE=defaultNamedNotOptArg, nSelected=pythoncom.Empty):
        return self._ApplyTypes_(20002, 1, (3, 0), ((3, 1), (16387, 2)), 'count', None,entityTYPE
            , nSelected)


I still get
Traceback (most recent call last):
  File "[snip]\playFemap4me.py", line 80, in <module>
    nSelected = zSelect.count(eFemTyps.FT_ELEM)
  File "<COMObject feSelector>", line 2, in count
pywintypes.com_error: (-2147352561, 'Parameter not optional.', None, None)


I'll mention that I ran makepy.py with the command line argument "-o PyFemap.py".  In my code, I just import PyFemap, rather than importing gencache and running gencache.EnsureModule(etc.).  I've tried it both ways and it doesn't seem to make much difference.  Is something perhaps not getting imported properly by PyFemap?  Here's the top of that file, in case it helps:

# -*- coding: mbcs -*-
# Created by makepy.py version 0.4.95
# By python version 2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit (Intel)]
# From type library 'femap.tlb'
# On Fri Sep 26 16:28:32 2008

"""Femap v9.31 Type Library"""
makepy_version = '0.4.95'
python_version = 0x20502f0

import win32com.client.CLSIDToClass, pythoncom
import win32com.client.util
from pywintypes import IID
from win32com.client import Dispatch

# The following 3 lines may need tweaking for the particular server
# Candidates are pythoncom.Missing, .Empty and .ArgNotFound

defaultNamedOptArg=pythoncom.Empty
defaultNamedNotOptArg=pythoncom.Empty
defaultUnnamedArg=pythoncom.Empty



Thanks again for your help.

- Greg Antal


Mark Hammond wrote:

Try passing pythoncom.Empty for the out param - that will provide a VT_EMPTY param to the object, which it will hopefully accept and fill with the result.

 

Mark

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Greg Antal
Sent: Tuesday, 7 October 2008 4:10 AM
To: python-win32@python.org
Subject: Re: [python-win32] ByRef params not working with PythonCOM

 

Greetings all.

I posted this a week ago and had no response, so I'll try again.  Any information would be helpful, even if it's just "that all looks right, no idea why it doesn't work."  I'll gladly provide more info if needed, or try a different statement of the problem if it isn't clear.

Thanks,
Greg Antal

---------------------

Greg Antal wrote:

Gentlemen:

I need to work with a TLB for a finite element pre/post processor called Femap.  Its API was built for Visual Basic, and it uses output arguments in many of its functions/methods.  Methods with only input arguments and return values work great, but I can't get anywhere with those that have output arguments.

Here's the documentation for a method 'Count' of the class 'feSelector':
Count ( entityType, nSelected )
Description:
  This method returns the number of entities of a given type that are currently selected
Input:
    INT4 entityType
        The entity type to query (node, element, etc)
Output:
    INT4 nSelected
        The number of "entityType" entities that are currently selected.
Return Code:  None


Here's the code makepy.py generated for this method:
    def count(self, entityTYPE=defaultNamedNotOptArg, nSelected=pythoncom.Missing):
        return self._ApplyTypes_(20002, 1, (3, 0), ((3, 1), (16387, 2)), 'count', None,entityTYPE
            , nSelected)


>From all the documentation I've been able to find (including the archives of this mailing list back to September 2005), my Python call should look like this:
nSel = zSelect.count(eFemTyps.FT_NODE)

When I try that, I get:
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "<COMObject feSelector>", line 2, in count
com_error: (-2147352561, 'Parameter not optional.', None, None)


I've tried supplying the extra parameter, but that results in a 'type mismatch' error, which probably doesn't surprise anyone.  Can someone help?

Thanks,
Greg Antal

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to