Scripting Question about creating files

Next
 From:  Teddy Lindsey (TEDDYLINDSEY)
9665.1 
Michael,

A while back you provided some very useful scripts that snapshot the 3D viewport, recording the camera and target positions to an in-memory stack. Unfortunately, there's no way to persist the stack.

I'm working on a script/UI that shows a list of the saved views, allows for renaming the views and ultimately can save the views to a file so they persist.

So my questions are:

Q: does the moi.filesystem object provide the ability to read/write arbitrary files that I can store the array of views in?

Q: is there a way to embed data such as the array of saved views directly into a 3DM file?

Thank you,
Teddy
  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
9665.2 In reply to 9665.1 
Hi Teddy, yes there is a way for a script to read and write to a text file. This is done with moi.filesystem.openFileStream( filename, mode ).

moi.filesystem.openFileStream takes 2 parameters, a file name and the mode which is either 'r' for read or 'w' for write. Check out the updated version of SavePointFile (the one that says it works on Mac) for an example: http://kyticka.webzdarma.cz/3d/moi/#SavePointFile .

The Filestream object has these functions:

.readLine() - reads a line of text from the stream, the text is the return value of the function.

.writeLine( text ) - writes a line of text to the stream.

.atEOF property - returns true if the stream is at the end with nothing more to read from it.

.close() - closes the stream.

.setWriteBOM( ) - sets whether to write the byte order mark at the front of the text file, default is no BOM.

.setCodec( name ) - controls the encoding to use for reading or writing. Supported codecs are listed here: http://doc.qt.io/qt-5/qtextcodec.html#details .


> Q: is there a way to embed data such as the array of saved views directly into a 3DM file?

Sorry, no - currently there isn't really a proper way for a script to embed its own data into a 3DM file.

- 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:  Teddy Lindsey (TEDDYLINDSEY)
9665.3 In reply to 9665.2 
Thanks, Michael! I appreciate the details about the filestream and I will check out the example scripts.

- Teddy
  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:  Teddy Lindsey (TEDDYLINDSEY)
9665.4 
Is there some documentation somewhere that might help me learn the underlying Javascript API? I've taken a look at http://moi.maxsm.net/api/ but it seems like it's probably a subset of the actual functionality. I was hoping there was some kind of documentation or API reference that might be more comprehensive.

I appreciate all of your work on MOI and documentation is probably one of the last things on your mind but if you can point me in the right direction, I'd very much appreciate it.

- Teddy

EDITED: 21 Oct 2020 by TEDDYLINDSEY

  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:  Larry Fahnoe (FAHNOE)
9665.5 In reply to 9665.4 
There isn't really a current API guide, but I've found studying Michael's code (particularly the .js and .htm files in MoI's commands directory) to be quite helpful in developing a sense of how the API works. The v3/4 release notes also contain numerous hints about scripting and the API as do the forum posts.

v3 release notes: https://moi3d.com/wiki/V3Beta
v4 release notes: https://moi3d.com/wiki/V4Beta

--Larry
  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:  Teddy Lindsey (TEDDYLINDSEY)
9665.6 In reply to 9665.5 
Thanks for the tips, Larry! I will spend more time poking around in the commands directory and reading the release notes in more detail.
  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
9665.7 In reply to 9665.4 
Hi Teddy, there is also some info here but not much sorry:
http://moi3d.com/wiki/Scripting

- 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:  Teddy Lindsey (TEDDYLINDSEY)
9665.8 In reply to 9665.7 
Going through existing scripts from others has been very helpful.

What version of the Javascript/ECMAScript interpreter is built into MOI? I've found that newer language features like the "for-of loop" don't seem to be supported.

Thanks,
Teddy
  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:  bemfarmer
9665.9 In reply to 9665.8 
I believe it is ECMAScript5 = ECMAScript2009 = Javascript5 = ES5

Babeljs.io can be used online to convert ES6 to ES5. Use the "try it out" tab.

ECMAScript6 has the confusing year 2015 name.
ECMAScript6 has "let" and (weird to me) function naming, and weird double arrows. And I think Cosh() and Sinh().

- 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:  Michael Gibson
9665.10 In reply to 9665.8 
Hi Teddy, yes I think it only supports ECMAScript5 like Brian writes above.

The interpreter is JavaScriptCore that comes with QtWebKit with Qt 5.4.1 .

- 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:  bemfarmer
9665.11 In reply to 9665.10 
Hi Michael,
I wanted to use Math.js for complex numbers and elliptic functions, and possibly other functions, but notice that it is
at least ES6 (ECMAScript 2015. Do you think MoI v5 may have ES6 or later compatibility?

I guess I can translate some of Math.js to ES5...

- 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:  Michael Gibson
9665.12 In reply to 9665.11 
Hi Brian, it will take quite a bit of work to update the scripting engine so I'm not sure when that could happen. Probably not for MoI v5.

- 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:  bemfarmer
9665.13 In reply to 9665.12 
Thank you Michael.

EDITED: 7 Dec 2020 by BEMFARMER

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

Message 9665.14 deleted 7 Dec 2020 by BEMFARMER
 

Reply to All Reply to All