Jump to content

Immediate feedback while developing plugins in Python


twk

Recommended Posts

Hello again

Quick question, how do you get immediate feedback while developing plugins in Python.

eg

I have a plugin object which I'm writing in Aptana.

This is the code in the PIO's main script window.

from TestPlugin import MainGuy #these are setup in the env paths

MainGuy()

the MainGuy.py has this code

global LineLength
   objectName, objectHand, recordHand, wallHand = 0, 0, 0, 0
   LineLength = vs.PLineLength

   ok, objectName, objectHand, recordHand, wallHand = vs.GetCustomObjectInfo( objectName, objectHand, recordHand, wallHand )
   if ok:
       vs.Locus(0,0)
       vs.Locus(LineLength,0)
       vs.Rect(0, 0, LineLength, 50)

if __name__=='__main__':
   mainguy()
   pass

if I change say a value for the vs.rect call from 50 to 100

vs.Rect(0,0,LineLength, 100)

from Aptana, this doesnt get reflected in vectorworks until I restart VW.

I have the Session in Developer Mode set in the vectorworks preferences and still I need to restart.

This wasn't the case in Vectorscript and includes. Is this normal behaviour for Python/Aptana or am I doing something wrong?

Link to comment

..aaaand its not called 'immediate feedback' its called python caching.

Found this thread here started by Dieter @ DWorks.

Can we disable Python caching?

Interesting read.

The last post though solved my problem.

I use a different approach to solve this issue.

I created a command that clears all the modules in a designated folder. (In the example : myLibrary)

It actually removes the modules from sys.modules. Python will therefor import them again at the next import statement. I find this much easier than placing "reload(module)" statements everywhere in my code. (especially since they need to be removed for deployment)

import sys
modulesToDelete = []
for m in sys.modules:
   moduleName = str(m)
   if "myLibrary."  in moduleName:
       modulesToDelete.append(moduleName)
currentModule = __name__
for mod in modulesToDelete:
   if mod != currentModule: # Python cannot delete the current module
       del sys.modules[mod]

Thanks Musisback!

Link to comment
Hello again

Quick question, how do you get immediate feedback while developing plugins in Python.

eg

I have a plugin object which I'm writing in Aptana.

This is the code in the PIO's main script window.

from TestPlugin import MainGuy #these are setup in the env paths

MainGuy()

If you do this instead, you won't need to restart VW:

import TestPlugin
TestPlugin.MainGuy()

Only other python files that you reference in that file will acquire a restart if they are changed, but not that main file if you reference it like this.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...