Jim:

The thing about the Femap API is that its class methods use tons of ByRef arguments to return data to the caller. This is not something Python really supports. PythonCOM gets around it by turning the output arguments in to return values, but I find that only works if I enforce early binding. Here's what I recommend:
  1. Run makepy on the "femap.tlb" and have it save the output to a file. I always call that file PyFemap.py.
  2. In your Python code, import this file along with all your other import statements: import PyFemap. If you look in PyFemap.py, you'll see that it imports all the win32com stuff it needs, so you don't have to do that yourself. Also, all the Femap stuff is now accessible by "early binding", and that is essential when dealing with those pesky return values.
  3. Access the femap model object like this: zFemap = PyFemap.model()
  4. Get the active view ID like this: iRet, iViewId = zFemap.feAppGetActiveView()
Item 4 shows how an output argument in VB or C++ becomes a return value in Python. That happens with every method in the API that uses output arguments. The standard return code is always first in the list, followed by the output arguments in the order they appear in the VB argument list. See, for example, the output vector method "GetOutputList" which retrieves all the data in the output vector. In Python, the call looks like this:
iRet, nVals, liIds, lrData = zOutVec.GetOutputList().

The key thing in all this is to import that PyFemap file. When you do that, it's infinitely easier to use the Femap API in Python than it is in VB or C++. If you don't do it, you'll just never get it to work.

- 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

greg.an...@ata-e.com
858-480-2072  (Phone)
858-792-8932  (Fax)

Jim Ragsdale wrote, On 12/2/2010 6:59 AM:
I am trying to access the femap API, and having a bit of trouble. Here
is a simple example:

from win32com.client import Dispatch
femap = Dispatch("femap.model")
rc = femap.feAppGetActiveView(viewID)

This method, according to the documentation, is supposed to return a
long integer in viewID. If I do not define viewID, python returns the
error:

NameError: name 'viewID' is not defined

if I define viewID=0, python returns:

com_error: (-2147352571, 'Type mismatch.', None, 1)

I ran makepy and it generates a file, but I don't know if it is using
it or not. In the file, I can find the definition for the method:

def feAppGetActiveView(self, nViewID=pythoncom.Missing):
    return self._ApplyTypes_(20376, 1, (3, 0), ((16387, 2),),
u'feAppGetActiveView', None,nViewID
			)

To me it looks like win32 is not getting the information about the
variable types from com. Is there any way to get around this or am I
out of luck?

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

Reply via email to