scripting - help dealing with special chars in file path

Next
 From:  9krausec
9530.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!
  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
9530.2 In reply to 9530.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
  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:  9krausec
9530.3 In reply to 9530.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.
  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:  passant
9530.4 In reply to 9530.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;">
  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
9530.5 In reply to 9530.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

EDITED: 28 Feb 2020 by MICHAEL GIBSON

  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:  passant
9530.6 In reply to 9530.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
  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:  Michael Gibson
9530.7 In reply to 9530.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
  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