Notifications
Clear all

[Closed] Python and PyQt in 3dsMax

How do I get BlurLib installed? After successfull installation, the blur64 folder in Windows\System32\ is empty! :banghead:

I’m on Vista Business x64

1 Reply
(@solitude)
Joined: 11 months ago

Posts: 0

Well that’s the problem right there… a few posts back: Ehulser: “also right now we aren’t supporting Vista64 – we don’t have it here and haven’t tested with it yet. I run Vista32 at home, and it seems to work ok, but Vista64, I don’t know about yet.”

Good catch – apologies about that:

If you install x32 bit, the DLLs go in c:/blur/common
If you install x64 bit, the DLLs go in c:/windows/system32/blur64

We’re looking into the wiping of the PATH – that most definitely should not be happening, also right now we aren’t supporting Vista64 – we don’t have it here and haven’t tested with it yet. I run Vista32 at home, and it seems to work ok, but Vista64, I don’t know about yet.

@ypuech

Cool upgrade! We have it setup like that because we actually use that wingui package to run in many places (not just max)…so we have it more abstract on purpose, but if you want to host that somewhere for people using it for straight 3dsMax that’d be really cool.

(To that end, we’ll prolly be coming out with PyQt for Softimage very shortly using the blur.wingui package – need docs and testing first)

@ eek

How does pyQT compare with C# winForms? GDI+ stuff? Is it just a method to build interfaces or can we do drawing stuff with it? more advanced stuff?

I personally haven’t used C# and have limited experience with .net, but Qt is very, very robust. I’ve built custom widgets for all sorts of things, their QGraphicsView and QGraphicsScene is very powerful, on top of being able to just subclass any widget and define how it interacts is pretty simple. Look into QPainter for some of that.

As far as scripted controllers and attributes, I haven’t done anything with those yet. So feel free to test, play and contribute knowledge!

I need to try this!

Thanks

Well, looks like I’m out of the fun! 🙁

"BlurPython has not been loaded."

Do you get the DLL missing error or something alike ? I had to manually fix my path variable to make all the needed DLLs load as well as adjust my Python_Path variable to include the correct site-packages folder (as i already had a different python version installed).

BTW. Before there is double work done. Is there a simple way to use an external editor similar to the rez8 extension ? Or even using this extension ? It seems all one has to do is call maxscript call


python.exec "import blur.wingui;blur.wingui.runScript()"

and provide the scriptname instead of running it parameterless (at least according to what i saw in the wingui sources).

While the included editor is a nice touch for serious development external editors would ease dev a lot. Not to mention my fav advantage of external editors: if max crashes, the editor doesnt

Regards,
Thorsten

1 Reply
(@loocas)
Joined: 11 months ago

Posts: 0

If it was a reply to me, then yes, I have all the paths properly set and I don’t get any DLL load errors or anything. I simply only get this message in the MAXScript Listener:

"BlurPython has not been loaded."

Cool upgrade! We have it setup like that because we actually use that wingui package to run in many places (not just max)…so we have it more abstract on purpose, but if you want to host that somewhere for people using it for straight 3dsMax that’d be really cool.

(To that end, we’ll prolly be coming out with PyQt for Softimage very shortly using the blur.wingui package – need docs and testing first)

In fact we could rename applyMaxIcon with applyCoreAppParentIcon(), because it tries to get the core application parent icon with its handle. So this would work for all applications:

def applyCoreAppParentIcon(widget):
   dialogHandle = FindWindow( None, str(widget.windowTitle()) )
   
   maxIcon = SendMessage( core.parentWindow(), WM_GETICON, 0, 0 )
   if maxIcon == 0:
	  maxIcon = SendMessage( core.parentWindow(), WM_GETICON, 1, 0 )
   if maxIcon == 0:
	  maxIcon = GetClassLong( core.parentWindow(), GCL_HICONSM )
   if maxIcon == 0:
	  maxIcon = GetClassLong( core.parentWindow(), GCL_HICON )
   
   if maxIcon != 0:
	  iconInfo = GetIconInfo(maxIcon)
	  pixmap = QPixmap.fromWinHBITMAP( iconInfo[4], QPixmap.NoAlpha )
	  pixmap.setMask( QBitmap( QPixmap.fromWinHBITMAP( iconInfo[3], QPixmap.NoAlpha ) ) )
	  widget.setWindowIcon( QIcon( pixmap ) )

In Dialog.py and Window.py, replace applyMaxIcon() with applyCoreAppParentIcon().

1 Reply
(@loocas)
Joined: 11 months ago

Posts: 0

Unfortunately, this modification throws me the following error when I launch Max (2009 x64):

Traceback (most recent call last):
  File "C:\Program Files\Autodesk\3ds Max 2009\scripts\python/__startup__.py", line 15, in <module>
    blur.wingui.connectPlugin( Py3dsMax.GetPluginInstance(), Py3dsMax.GetWindowHandle() )
  File "C:\Python26\lib\site-packages\blur\wingui\__init__.py", line 49, in connectPlugin
    logger	= LoggerWindow()
  File "C:\Python26\lib\site-packages\blur\wingui\windows\LoggerWindow.py", line 283, in __init__
    Window.__init__( self )
  File "C:\Python26\lib\site-packages\blur\wingui\Window.py", line 25, in __init__
    blur.wingui.applyCoreAppParentIcon(self)
  File "C:\Python26\lib\site-packages\blur\wingui\__init__.py", line 127, in applyCoreAppParentIcon
    maxIcon = SendMessage( core.parentWindow(), WM_GETICON, 0, 0 )
NameError: global name 'SendMessage' is not defined

It worsk without the modification though.

I’m on Windows Vista Business x64, Max 2009 x64 if it makes any difference.

I assume you got the plugs in the right places ? did you check that the plugin is really loaded in the plugin manager ? as if i am not mistaken that error alone is an error message of the startup scripts that are checking if the plugin is present at all.

Regarding remote execution i basically know how to do it (and even with py itself rather than an extra exe so keepin it all pythonic). I cant find the right way to actually execute a python script via maxscript. The mentioned methods i took from the macroscripts dont seem to work (they just do nothing and return OK once i have the syntax right). Any pointers ?

Regards,
Thorsten

1 Reply
(@loocas)
Joined: 11 months ago

Posts: 0

:banghead:

Ah, yes! That was really lame of me! Sorry, I forgot I’m executing several versions of Max with different plugin.inis and the one I was running now didn’t have the path to the blur plugin included.

So, again, sorry for this. As a TD, I should crawl to a dark corner and cry…

Thanks man!

Yay…got external editor -> max execution to work

Here’s a quick how-to:

  1. You need to get pywin32 to get com functionality. The version matching the 64 bit version is here:
    http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win-amd64-py2.6.exe/download

  2. Next we need a maxscript function to execute our script. It needs to be available via com hence we need to register it. Here is mine:


fn exec_py script = (
  	if ( python != undefined ) then ( python.run( script ))
	else ( print "ERROR: BlurPython DLL is not loaded." )
)
registerOLEInterface #(exec_py)

place it in a .ms file and place this in your scripts/startup folder so it gets registered on max startup.

  1. We need to connect to max from the outside world and trigger the function. Cause this is all about python i decided to do that in python too as a command line script See below the code for notes

import win32com.client
import sys
       
#Create a connection to Max
conn = win32com.client.Dispatch("MAX.Application.2008")
       
#Flag as a Method otherwise python or win32com will most likely treat it as attribute.
conn._FlagAsMethod("exec_py")
     
conn.exec_py(sys.argv[1])

You need to tweak “MAX.Application.2008” to match your version. What it does is connect to a running max instance or start a new one if none is available and call the ole function we registered before with the first commandline argument as a function argument.

To test this you can run it from the commandline:


python execute.py "scriptpath_and_filename"

If all went well max should run your python script triggered by the commandline. Neato

Now i went to my editor (for testing i used komodo edit) and added a custom run commando that looks like this:


c:\python26_64\python c:\blur\execute.py %F

%F is the placeholder for the currently edited script. So hitting the shortcut for that one executes the script in max. Now why do we do that ? Cause i dig the additional editing functions (esp things like intellisense and autocomplete…and yay…they work with the blur modules as far as i can tell)

Hope this helps someone,
Thorsten

P.S. Erik it might be worth considering adding this to the wiki for reference.

Loocas – I have a laptop with 64bit vista on it… I’ll get that going as a test bed soon…

Very cool stuff there, guys… just so you know, you can execute any python script with

python.run(filename) 

internally from max, so you can create macros and such that point to your file (or in our case, since I’m currently at blur, by using the new treegrunt) and still edit in whatever app you want. Telling max what to do from external apps has a lot more potential now… could get some really cool inter-package scripts or just any sort of external python controlling max.

1 Reply
(@loocas)
Joined: 11 months ago

Posts: 0

Thanks, but I’m fine already I’ve managed to install the libs via a 64bit XP virtual machine and then I just forgot to add the path to the plugin in the custom inis I have here.

It’s all working just fine now, fantastic work guys, really! :buttrock:

I’m now trying to execute the scripts from an external editor, but I’m having some trouble with the OLE objects etc… hopefully I’ll get to the root of the problem soon.

Edit: GOT IT! Stupid typo… :rolleyes:

Thanks Ian. That was what i was doing wrong before (using python.exec instead of run :shrug: )

Any chance we will also see the old tools beeing released again ? Like treegrunt and it’s contents I only see the file structure not the actual tools.

Regards,
Thorsten

Page 5 / 17