[Solved] Using win32api in Python

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
kaktus018
Posts: 20
Joined: Mon May 14, 2018 2:51 pm

[Solved] Using win32api in Python

Post by kaktus018 »

Hello everybody,
I understand that the Python interpreter of FreeCAD does not come with pywin32 installed. Still it would be great if I could somehow use the COM-interface to enslave some other programs ;)
This issue has already been discussed some years ago: https://forum.freecadweb.org/viewtopic. ... =4&t=21810
Installation via pip apparently works, but the libraries are broken and cannot be imported (An application has made an attempt to load the C runtime library incorrectly):

Code: Select all

from pip.commands.install import InstallCommand
from pip.status_codes import SUCCESS
cmd = InstallCommand()
result = cmd.main(['pywin32'])
if result != SUCCESS:
  print 'failed'
else:
  print 'success'
Does anybody know a way to get this to work?

Best regards,
Dominik
Last edited by kaktus018 on Fri Oct 12, 2018 10:35 pm, edited 1 time in total.
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Using win32api in Python

Post by sgrogan »

kaktus018 wrote: Tue Oct 09, 2018 5:17 pm Does anybody know a way to get this to work?
What FreeCAD version are you using? Did you compile yourself?
I guess you are using PY2, if so FreeCAD uses VS2013 and provides it's own python built with this compiler, the PyPi package uses VS2008, so when importing pywin32 there is a C runtime conflict.

With more info we can probably get a working combination.
"fight the good fight"
kaktus018
Posts: 20
Joined: Mon May 14, 2018 2:51 pm

Re: Using win32api in Python

Post by kaktus018 »

Thanks for the reply!
I'm using the currently official development build 0.18.14957_x64. I don't want to compile for myself due to maintenance reasons, but I think this would be required to get this to work, right? In that case: I just need a one-way communication so I can always just call e.g. a VBScript from Python that does the communication.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Using win32api in Python

Post by TheMarkster »

kaktus018 wrote: Wed Oct 10, 2018 9:04 am Thanks for the reply!
I'm using the currently official development build 0.18.14957_x64. I don't want to compile for myself due to maintenance reasons, but I think this would be required to get this to work, right? In that case: I just need a one-way communication so I can always just call e.g. a VBScript from Python that does the communication.
One way to do it, but there might be better ways:

Code: Select all

import os
os.system(r"c:\users\username\script.vbs optional_commandline_args")
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Using win32api in Python

Post by sgrogan »

kaktus018 wrote: Wed Oct 10, 2018 9:04 am I'm using the currently official development build 0.18.14957_x64. I don't want to compile for myself due to maintenance reasons, but I think this would be required to get this to work, right?
Not necessarily.
If you use the Conda based PY3 (PY3.6 to be exact) builds from the releases page (This version uses VS2015) you will be able to use the PY3.6 PyPi packages (these packages also use VS2015).
"fight the good fight"
kaktus018
Posts: 20
Joined: Mon May 14, 2018 2:51 pm

Re: Using win32api in Python

Post by kaktus018 »

Thanks for the replies!
I need to stick to PY2 due to all the scripts I use. I now dynamically create a VBS from Python that does what I need and it is working just fine. Good to know the port to PY3 introduces more flexiblity concerning this.
Have a nice weekend!
Post Reply