<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Jim:<br>
    <br>
    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:<br>
    <ol>
      <li>Run makepy on the "femap.tlb" and have it save the output to a
        file. I always call that file PyFemap.py.</li>
      <li>In your Python code, import this file along with all your
        other import statements: <b>import PyFemap</b>. 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.</li>
      <li>Access the femap model object like this: <b>zFemap =
          PyFemap.model()</b></li>
      <li>Get the active view ID like this: <b>iRet, iViewId = zFemap.feAppGetActiveView()</b><br>
      </li>
    </ol>
    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:<br>
    <b>iRet, nVals, liIds, lrData = zOutVec.GetOutputList()</b>.<br>
    <br>
    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.<br>
    <br>
    - Greg Antal<br>
    <pre class="moz-signature" cols="72">Gregory W. Antal
Senior Technical Advisor
ATA Engineering, Inc.
11995 El Camino Real, Suite 200        
San Diego, CA  92130
<a class="moz-txt-link-abbreviated" href="http://www.ata-e.com">www.ata-e.com</a>

<a class="moz-txt-link-abbreviated" href="mailto:greg.antal@ata-e.com">greg.antal@ata-e.com</a>
858-480-2072  (Phone)
858-792-8932  (Fax)</pre>
    <br>
    Jim Ragsdale wrote, On 12/2/2010 6:59 AM:
    <blockquote
      cite="mid:AANLkTinWiwh_HaiPX7S8Ae7KR5-Y=QL-kzTOR_kfKXC7@mail.gmail.com"
      type="cite">
      <pre wrap="">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
<a class="moz-txt-link-abbreviated" href="mailto:python-win32@python.org">python-win32@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/python-win32">http://mail.python.org/mailman/listinfo/python-win32</a>
</pre>
    </blockquote>
  </body>
</html>