MoI discussion forum
MoI discussion forum

Full Version: scripting - help dealing with special chars in file path

From: 9krausec
12 Oct 2019   [#1]
Been struggling with utf-8 encoding / decoding in Python now to drive a process chain that moi is part of. Figured out the python bit, but having a challenging time figuring out how to get moi to handle it with javascript. I'd appreciate any help or suggestions on how to go about it. Thanks in advance.

I have a method that that takes in a path to a .STEP, meshes and saves out a .OBJ with the same file name. Works a treat under ascii based file paths, but now I'm hitting a snag with file paths such as this -
'C:/Users/Clayton/Desktop/TMP/CAD/_output/FC205-Z05_3D__cfg__預設.step'

I can get the file to import by escaping the special characters individually such as -
'C:/Users/Clayton/Desktop/TMP/CAD/_output/FC205-Z05_3D__cfg__\u9810\u8A2D.step'

But I'm hoping there is a blanket application that ships with moi or in javascript that will automatically do the leg work for me during the import/export process in moi.

Maybe "moi.filesystem.openFileStream", but I can't seem to figure out how to get that working. The file opens up fine when opening directly through moi GUI.

This all is getting a bit exotic for me and I'd appreciate a push in the right direction. Thank you!
From: Michael Gibson
12 Oct 2019   [#2] In reply to [#1]
Hi 9krausec, so if I understand right you're generating a script file for MoI to run in a sort of "headless" fashion, is that correct?

So I think your problem is that although JavaScript can at runtime handle unicode strings, a .js source code file cannot itself be a unicode text file, it is expecting that a .js file containing JavaScript code in it should be ascii encoded.

That means that any unicode text that you want to store as a string literal in a .js source code file will need escaping as you describe.

At runtime it's a different story, a string variable in the javascript runtime environment can contain unicode in it just fine, it should only be string literals inside of a .js ascii text file that need the escaping.

re:
> But I'm hoping there is a blanket application that ships with moi or in javascript that
> will automatically do the leg work for me during the import/export process in moi.

There is no application that ships with MoI that is specifically oriented around generating .js source code files. They are most typically generated by a person typing the code in a text editor. If you are generating the .js files programmatically you would need to incorporate the escaping into your own .js file generating code.

Please let me know if that isn't what you are running into.

- Michael
From: 9krausec
13 Oct 2019   [#3] In reply to [#2]
Hi Michael! You are right, headless fashion. Javascript commands are being generated by Python. Thank you for confirming that I need to avoid using Unicode in the .js command argument files when running moi.exe via cmd. I'll look into exploring options to decode the incoming Unicode in Python to ensure that the proper escape chars are used for ascii compliance when writing out the .JS files.

Thank you for the prompt response and clarification.
From: passant
27 Feb 2020   [#4] In reply to [#1]
Hey! This may be the false thread and a noob question, but I'm having a really hard time finding out how to achieve a string Input into an UI-Panel inside of MoI.


What is the pendant for "numericinput" when I want to get a string?
I'd really appreciate any help. I am trying to build the script you ave already with automatic STEP to OBJ from a path.
Works fine without UI, but unfortunately not with one at the moment...

Huge thanks already!

Pascal

PS:
I know the numeric part in a .htm as of using:

...
...
<input id="filePath" class="numericinput" default="Path" style="persist:true;">

From: Michael Gibson
27 Feb 2020   [#5] In reply to [#4]
Hi passant, which version of MoI are you using?

For a numeric input, using <input class="numericinput" is what was used by v2 and earlier. It's still supported but the newer way is to use a <moi:NumericInput/>

There is also a control for a string input. The old way is <input class="textinput"> the v3+ way is <moi:TextInput/>

- Michael
From: passant
3 Mar 2020   [#6] In reply to [#5]
Hey Michael,

I am in fact using v4, I just found a few scripts online and learned from them,
but used the old way apparently, thanks for clearing that up!

I'll use the TextInput, and will come back here for further questions, if it's okay!

Thank you :)

- Pascal
From: Michael Gibson
3 Mar 2020   [#7] In reply to [#6]
Hi Pascal, you're welcome!

> I'll use the TextInput, and will come back here for further questions, if it's okay!

Certainly!

- Michael