MoI discussion forum
MoI discussion forum

Full Version: MoI embedded inside CPython 3.91?

Show messages:  1-14  15-34  35-44

From: Michael Gibson
27 Mar 2021   [#35] In reply to [#34]
Hi Brian, does it behave any better if you pass the parameters as the second argument to moi.filesystem.shellExecute() ?

Something like this:

var res = moi.filesystem.shellExecute( 'C:\\Users\\orcha\\AppData\\Local\\Programs\\Python\\Python39\\python', 'sys.stdout.write("I am a test")', true );
if ( res.output ) moi.ui.alert( res.output );

- Michael
From: bemfarmer
27 Mar 2021   [#36] In reply to [#35]
Michael, thank you for having a look.
Nothing happens with your suggestion.

Your posts to Shane https://moi3d.com/forum/index.php?webtag=MOI&msg=9890.40 reminds me of this link:

https://memyselfandpython.wordpress.com/2018/01/14/opening-python-programs-in-command-prompt-windows-and-open-txt/
It looks like I can run python program through windows CMD...?

Still learning a lot.

- Brian

So is the RhinoPasteFromMoi.py program run in Rhino7? or MoI, or ?
From: Michael Gibson
27 Mar 2021   [#37] In reply to [#36]
Hi Brian,

Are you 100% certain that your path and filename to python is correct?

Because your path here does not target a file with an .exe file extension:

> C:\\Users\\orcha\\AppData\\Local\\Programs\\Python\\Python39\\python

re:
> So is the RhinoPasteFromMoi.py program run in Rhino7? or MoI, or ?

That's for running in Rhino, if copy from MoI and paste into Rhino is not working.

- Michael
From: bemfarmer
28 Mar 2021   [#38] In reply to [#37]
Hi Michael,
I'm 99.9% sure that the path to python.exe is correct. (Never 100% sure:-)

For Windows 10:
(Also refered to as command prompt), the command interpreter, Cmd.exe has 10 parameters, 9 of which are "switches":
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd

A Windows 7 version which might be helpful:
https://sourcedaddy.com/windows-7/using-cmd-switches.html

/c is a switch

I take it that moi.filesystem.shellExecute(...) is running the Windows 10 shellexecute?
(Or some Mac equivalent...?)

The Command Prompt in Windows provides access to over 280 commands:
https://www.lifewire.com/list-of-command-prompt-commands-4092302

- Brian

Also interesting:
https://stackoverflow.com/questions/48437377/cmd-commands-in-shellexecute
Previous link, links to:
https://www.codeproject.com/Articles/5163375/Tiny-CMD
From: bemfarmer
28 Mar 2021   [#39] In reply to [#38]
MAYBE?: I found some possible code at this "stocks and bonds program" site:
https://forum.amibroker.com/t/can-we-run-a-python-script-using-shellexecute/6125

code:
ShellExecute("C:\\Program Files\\AmiBroker\\YOURPYTHONFILE_v1.py","","",0);


Have to try them out tonight.

I believe/guess Windows 10 already has path to python.exe, so just need to add the testProgram.py???

- Brian

SheBang talk, Windows and OS X:
https://automatetheboringstuff.com/appendixb/

Also see:
http://www.amibroker.com/guide/afl/shellexecute.html

Well, my theory is that some of this is relevant to using shellExecute from the MoI command window. (???)

One more link for now:
https://docs.microsoft.com/en-us/windows/win32/shell/shell-shellexecute
(There is some JScript/ Javascript code, plus an example.)

I think that what I am trying to do is to run some python code from MoI, or Nodeeditor, to apply Math to e.g. gyroid wdomain point(curve) network csv file, which is currently done manually.
From: bemfarmer
28 Mar 2021   [#40]
The following code works in MoI. In MoI, press Tab, and paste the following code into MoI command window:

code:
var res = moi.filesystem.shellExecute('cmd /c C:\\Users\\orcha\\Desktop2\\printTest.py', '', true );
if ( res.output ) moi.ui.alert( res.output );


I created a new folder Desktop2, and placed the printTest.py python script in it.

An alternate Path and directory can be used. The printTest.py program needs to be placed in the Path and directory used.
The /c "switch parameter" is needed...
Windows 10 already knows (the Path) where the installed Python.exe program is located.

The output is a MoI alert box with the text message in it.

- Brian

Now I would like to run the gyroid python script and capture the .csv file...

Attachments:
printTest.zip


From: bemfarmer
28 Mar 2021   [#41]
The following code performed the python script gNetP0.py, and produced the output Desktop\gNetP0.csv, from Desktop\gDomain3_12.csv. However there was no visible indicator in MoI that python had done its job.

code:
 
var res = moi.filesystem.shellExecute('cmd /c C:\\Users\\orcha\\Desktop2\\gNetP0.py', '', true );
if ( res.output ) moi.ui.alert( res.output );


Maybe some parameter could be added to show the action occured?
Or the gNetP0.py could have a completed print(...) message added at end...

- Brian

ps:
https://stackoverflow.com/questions/89228/how-to-execute-a-program-or-call-a-system-command-from-python

"If you're on Python 3.5 or later, you can use the new subprocess.run function, which is a lot like the above but even more flexible and returns a CompletedProcess object when the command finishes executing."

"...There are serious security implications if any part of the string that you pass can not..."
From: Michael Gibson
28 Mar 2021   [#42] In reply to [#38]
Hi Brian,

re:
> I take it that moi.filesystem.shellExecute(...) is running the Windows 10 shellexecute?
> (Or some Mac equivalent...?)

It depends - if the optional "WaitForFinished" function argument is false then it will run straight Win32 ShellExecute(). If "WaitForFinished" is true then it will use Qt QProcess to create the process, wait for it to finish, and capture it's output.

- Michael
From: bemfarmer
29 Mar 2021   [#43] In reply to [#33]
An attempt was made to offset or shell patch P0, and gyroid boundary patch.

It appears that the "symmetry" operations have resulted in Flip of some surface normals, as some patches offset or shell in opposite directions.
Also P1 and P2 offset or shell with a little wiggle near a corner.

PatchPO Shell Centerline, 0.02, works very well. Node creation from PatchPO Shell slolid to the boundary patch with 12 solids looks good.
Boolean union two of the 12 solid patches has not worked. But hiding two skins and deleting the two surfaces in common, does permit two solid patches to boolean.

A few stray curve segments were created a some time...

- Brian
From: bemfarmer
30 Mar 2021   [#44] In reply to [#43]
The 12 patches of the boundary surface do not quite meet at the center. Some faint grooves are visible in the resulting surface. Boolean union of the shelled patches created up to 3 each of sliver solids that look like lines... The python math is not perfect... Join was an alternative to Boolean union, also showing the 'grooves".
The project is probably sufficiently complete to move on...
Or further investigate the papers math for z coordinates...
And investigate the symmetry "Flips"...

- Brian

Boolean union once created or modified two offset surfaces which acted as one surface, and also sometimes deleted one surface...

Show messages:  1-14  15-34  35-44