Dynamic reloading of scripts

Next
 From:  mikerogers74
3544.1 
Apologies if this has been asked before, I couldn't find anything following some searches...

I'm trying out some scripting and was wondering if it were possible to make changes to script files and have these changes be executed when the script is next run via a shortcut key. It seems I have to restart MOI to see my changes.

Thanks

Mike
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
3544.2 In reply to 3544.1 
Hi Mike, there isn't currently any way to do that.

Scripts (along with other resources like images and HTML files for the UI) are cached into memory when they are first read, so that on subsequent runs of the same command it does not need to access the disk.

In v3 I should be able to add in some .ini file option that will disable that caching for scripts. I won't be able to get it in for v2 since v2 is right on the verge of being released.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dave Morrill (DMORRILL)
3544.3 In reply to 3544.2 
Mike,

The interface I use when running/testing scripts using MoI does allow scripts to be reloaded without restarting MoI. In fact, I just use my favorite text editor, makes some changes to my script, save the file, then click the 'Execute' button I've added to MoI to test it.

Hopefully at some point I'll get it all nicely packaged to the point where other people can use it easily.

If you think you are going to be doing this often, maybe I can help you get set up with the system I've got now?

- Dave Morrill
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mikerogers74
3544.4 In reply to 3544.3 
Hi Dave,

Thanks very much for the offer to help get set up! I'd be very appreciative if you would share what you have done. I'm a software developer by trade so would probably be able to make sense of even a rough framework. I'm a big fan of Python so I'm REALLY keen on seeing how that all hangs together :)

Thanks

Mike
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dave Morrill (DMORRILL)
3544.5 In reply to 3544.4 
Mike,

Since I'm working on the MoI scripting API again at the moment, let me have a few more days to tidy things up a little more before sending you something. The initial drop will just be for using the MoI Javascript API, since the Python stuff still needs a lot more luvin' before I can start letting other people use it.

I assume you've seen the links I've posted to the MoI Javascript API documentation I've been working on (off and on)? If not, look for the 'Scripting' page in the MoI wiki...

- Dave Morrill
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mikerogers74
3544.6 In reply to 3544.5 
Hi Dave,

Yup, been all over your website :) The javascript stuff on it's own is great. Just the ability to be able to reload scripts dynamically is awesome.

Mike
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dave Morrill (DMORRILL)
3544.7 In reply to 3544.6 
Mike,

Did some more work on this today. I've got all the files needed for using the scripting interface ready to go, including a readme on how to do the installation. I just need to do a test install to make sure it all hangs together. I'll try to get to that tomorrow.

Just wanted to let you know I haven't forgotten about this...

- Dave Morrill
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mikerogers74
3544.8 In reply to 3544.7 
Thanks for your efforts on this. Looking forward to seeing how it all works.

thanks

Mike
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Brian (BWTR)
3544.9 In reply to 3544.8 
Any new developments on this?
Have I missed something?

Really, really, in need of an up to date, complete, Short Cuts and a printout style understandable" shortcut keys" for my desk.

I am just too old--have spent the best part of the last 2 days trying to get my mind into gear to do it and it wont work in my brain.

Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dave Morrill (DMORRILL)
3544.10 In reply to 3544.9 
Sorry Brian, got sidetracked trying to do some more work on finishing up the Javascript API documentation before releasing the scripting package. But it looks like there is still a lot more left to do there (currently at 73% complete), so I guess I'll have to punt on getting that finished for now, and just get the rest of the stuff ready to ship. I'll set an (arbitrary) goal of Tuesday for getting that done...

- Dave Morrill
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Brian (BWTR)
3544.11 In reply to 3544.10 
That was quick Dave.
Thank you.
I am hoping that the end result for me is something like this.
Is that the aim?
Brian
Image Attachments:
Size: 82 KB, Downloaded: 36 times, Dimensions: 724x1024px
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dave Morrill (DMORRILL)
3544.12 In reply to 3544.11 
Brian, I think we have a disconnect somewhere. I thought you were looking for something to allow you to reload scripts dynamically.

If what you want is to display your current MoI shortcuts, the following Python script I just wrote should do it (at least for Vista/Windows 7):
from os import environ
from os.path import join

def key_sort ( l, r ):
    result = cmp( len( l ), len( r ) )
    if result != 0: return result
    return cmp( l, r )
    
shortcuts = {}
ini = open( join( environ[ 'APPDATA' ], 'Moi', 'moi.ini' ), 'rb' )
lines = [ line.strip() for line in ini.readlines() ]
max_key = 0
ini.close()
for i in xrange( lines.index( '[Shortcut Keys]' ) + 1, len( lines ) ):
    line = lines[i]
    if line[:1] == '[':
        break
    col = line.find( '=' )
    if col >= 0:
        key = line[ :col ].strip()
        max_key = max( max_key, len( key ) )
        shortcuts[ key ] = line[ col + 1: ].strip()
pad = ' ' * max_key
keys = shortcuts.keys()
keys.sort( key_sort )
n = len( keys[0] )
c = ' '
for key in keys:
    if (n != len( key )) or ((n > 1) and (key[:1] != c)):
        n = len( key )
        c = key[:1]
        print
    print (key + pad)[ : max_key], '=', shortcuts[ key ]

When I run this on my system, it produces the following output:
A            = Rotate
C            = Circle
D            = BooleanDifference
F            = Fillet
H            = script:moi.geometryDatabase.hide();
J            = Join
L            = Line
M            = Move
O            = Offset
R            = Rectangle
T            = Trim
U            = BooleanUnion
V            = Mirror
X            = Extrude

F1           = script:moi.launchHelp();

Ctrl+A       = script:moi.geometryDatabase.selectAll();
Ctrl+C       = CopyClipboard
Ctrl+N       = New
Ctrl+O       = Open
Ctrl+S       = Save
Ctrl+V       = Paste
Ctrl+X       = Cut
Ctrl+Y       = script:moi.command.redo();
Ctrl+Z       = script:moi.command.undo();

Delete       = Delete

Ctrl+Shift+C = CopyClipboardWithOrigin
Ctrl+Shift+V = PastePart

Let me know if this is something like what you had in mind...

- Dave Morrill
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Brian (BWTR)
3544.13 In reply to 3544.12 
Sorry mate----all double dutch to me.

I really can not cope with all this script stuff I need just the simple access to --well-- Keystroke "actions" that I can get in most other programmes.

Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dave Morrill (DMORRILL)
3544.14 In reply to 3544.13 
Oops...I had you confused with the poster that started this thread. Please ignore my last couple of posts then...

- Dave Morrill
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Dan (CORNYSH)
3544.15 In reply to 3544.13 
"I really can not cope with all this script stuff I need just the simple access to --well-- Keystroke "actions" that I can get in most other programmes."

Brian, you don't have to be able to write scripts to set up keystrokes, but because MoI is so open-ended it doesn't have many keystrokes set up as standard. Although this means that you may have to do some setup work, you can make the keystroke actions anything that you like, which should make them much easier to remember.

Say you want your SaveAs keystroke to be the key 'a'. This is how to do it.

1) Click on the Options button in MoI.
2) Click on 'Shortcut keys'.
3) Click the 'Add' button. That will insert an empty row in the dialog box.
4) Enter the letter 'a' (without quote marks) in the Key field on the left of the empty row.
5) In the Command field on right enter 'SaveAs' (again without the quotes).
6) Hit the Close button and the dialog will save your changes and disappear.



Now if you hit the 'a' button you should get the Save as... dialog pop up.
In this way you can make MoI's keyboard shortcuts resemble whichever software you are most comfortable with.

As far as I can tell, the list of MoI's "native" commands is as follows (see below) so if you want to attach ArrayCircular to a particular keystroke combination, all you have to do is enter ArrayCircular in the dialog box as described above. For more complex commands you may need to use a script (just copy and paste one written by Michael) but for the sort of thing you mention standard commands should be fine and as you can see they are easy to add.

Regards
Dan


AddPoint
Align
Arc3pt
ArcCenter
ArcContinue
ArcTangent
ArrayCircular
ArrayCurve
ArrayDir
ArrayGem
ArrayGrid
Blend
BooleanDifference
BooleanIntersection
BooleanMerge
BooleanUnion
BoundingBox
BoundingBoxCenter
Box
Box3pts
BoxCenter
Chamfer
Circle
Circle3pt
CircleDiameter
CircleTangent
Cone
Conic
Copy
CopyClipboard
CopyClipboardWithOrigin
Curve
Cut
Cylinder
Delete
DoCurve
DoScale
EditOrientations
Ellipse
EllipseCorner
EllipseDiameter
ExplodeMove
Export
Extend
Extrude
Fillet
Flip
GetBoxExtrusion
GetCircle
GetCylinder
GetDistance
GetLine
GetObject
GetObjects
GetOrientation
GetPoint
GetPointOsnappedOnCurve
GetRect
GetRect3pt
GetRectRoundCorner
Helix
History
Image
Import
ImportPart
IncrementalSave
Inset
InterpCurve
Intersect
Join
Line
Loft
Merge
Mirror
Move
Network
New
Offset
Open
OpenTemplate
Orient
OrientLineToLine
OrientViewToView
Paste
PastePart
PlanarSrf
Plane
Plane3pts
PlaneCenter
Point
Polygon
PolygonEdge
PolygonStar
Polyline
Project
RadiusDiameter
RailRevolve
Rebuild
Rect3pts
Rectangle
RectCenter
RectWidthHeight
Revolve
Rotate
RotateAxis
Save
SaveAs
Scale
Scale1D
Scale2D
ScaleInput
Separate
Shell
ShowPoints
ShrinkTrimmedSrf
Silhouette
SketchCurve
Sphere
Sweep
Text
Trim
WaitForDialogDone
Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mikerogers74
3544.16 In reply to 3544.15 
Hi Dave,

Oops, thread took a quick detour :) Still interested in your approach to dynamic reloading, but no stress, looks like you have a lot on your plate.

Thanks

Mike
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Brian (BWTR)
3544.17 In reply to 3544.16 
Dan
Sorry, I think my message is being lost
I live in hope.
Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All