MoI discussion forum
MoI discussion forum

Full Version: MoI embedded inside CPython 3.91?

Show messages:  1-9  10-29  30-44

From: bemfarmer
13 Mar 2021   [#30]
gPatchP0_01.3dm is a new network of curves for fundamental gyroid patch P0, via Python math and .css files, without zeta rotation of 45 degrees, and without eta move of n/4. (zeta and eta, greek letters, are defined in Table 1. The typesetter got zeta mixed up with another greek letter.)

GyroidBoundaryFrom_gPatchP0_02_3dm.7z is the nodeeditor program which uses P0 to produce P1 and P2, in MoI, with Table 1 Transformations. (rotate, mirror, move). The node permits quick variations in the +/- rotation degrees, the mirror plane(s), and the move amounts.
Nodes for P3...P12 have not yet been done. The sign of both 45 degree rotations had to be reversed from the angle figured out.

MatrixMultiply4.zip is an Excel 365 program to multipy matrices with number entries, to assist in decomposing each composite matrix for each line entry in Table 1.

Each composite matrix is created manually from the [x, y, z,1] (transposed) vector.
A symbolic matrix multiplier in Excel would be helpful...

- Brian

ps The node program has a macro for the XY plane/frame for mirror can be exported, and a copy placed in the macro folder of nodeeditor.
gPatchP0 network can be networked to a surface. The surface can be offset a little, if desired. The net, or the surface(s) can be input to the node program to yield P1 and P2, etc.

EDIT: Updated .node program and Excel 365 programs are in post 31.

Attachments:
gPatchP0_01.7z
GyroidBoundaryFrom_gPatchP0_02_3dm.7z
MatrixMultiply4.7z


From: bemfarmer
14 Mar 2021   [#31]
Patch P3 and P4 successfully created from P0, with nodeeditor program.
So far, each successive patch has used an additional MoI command / Matrix.

Excel 365 matrix math with numbers is great.
Doing matrix "symbolic" math, like .707*z would require some involved programming... Web searches are not much help.

Decomposing a matrix composed of multiple unknown matrices for revolve and mirror is not so easy, and can have multiple, different, correct solutions.
Some mirror mirror ... operations can be done with rotations & ? ... somehow.
Web search results are too simple or too complicated...Some are for elementary school, and some for mathematicians.

Only 8 more patches to figure out...

Edit: Different symmetry operations to create Patch P3 and P4 were created. See post 33.

Attachments:
MatrixMultiply1234.7z


From: bemfarmer
17 Mar 2021   [#32] In reply to [#31]
After much study and failed transformations, Table 1 is finally turned into a node, to produce the gyroid boundary patch from pre-fundamental patch P0 to P1.
P1 transforms into P2, and the remaining 10 patches. Must write it up. I think clockwise 90 degree rotations and ccw 90 degree rotations are inconsistant with respect to x, y, and z axes and +/- 90 degrees?
It also helps to think in terms of world axes.

- Brian
From: bemfarmer
25 Mar 2021   [#33]
A concise node program to create the 12 patch gyroid boundary patch is complete. Use of some Macros makes the wiring look much better.
The Inversion center permits half of the 12 patches to be simply inversions of the other 6 patches. A simple inversion macro is included in one of the macros, which can be added to the symmetry operations repertoire.
The initial patch P0, created in Python is attached. Either the netP0, or the surfaceP0 may be used, or both, as input to the node program. The surface P0 could be extruded a bit, if desired.
When a rotation axis is pointed at the observer, for a Clockwise rotation of 90 degrees, use +90 for the Euler angle in the rotate node. This is contrary to the right hand rule and contrary to the convention that CCW rotation is positive.
The symmetry operations of Table 1 are complete. It took a long time to figure out how the symmetry operations work. The symmetry operations apply to the MoI World axes. To create say P3 from P1, notice that xprime equation of P1 needs to be negated with an initial mirror with yz plane. Then rotate about MoI x axis clockwise, by +90 degrees. This shifts (rotates) zPrime equations of P1 to yPrime equations of P3. Then rotate about MoI y axis by +90 degrees clockwise. This shifts (rotates) the old yPrime equations of P1 to the xPrime equations of P3, and the old xPrime equations of P1 to the zPrime equations of P3.
The last step is a simple move (translation) of n*eta = n*(1/4). In summary, it seems to be a lot easier to "rotate" the equations of table 1 from P1 to P3 and P11, and invert to P5, P7, and P9, and similarly from P2 to P4 and P12, and invert to P6, P8, and P10, rather than try to decompose matrices.
The new SetName node belongs in the nodeeditor extensions folder.

- Brian

Attachments:
GyroidPatch_P0_to_BoundaryPatch12.zip
GyroidPreFundamentalPatchP0.7z


From: bemfarmer
27 Mar 2021   [#34]
I have been reading forum posts about shellExecute, and reading lots of google searches, with very limited results, and poor understanding.

# In Windows 10, the line of code below, following these comments, will open a python window from the MoI command box.
# Note that python 3.9.2 is already installed in the path shown.
# Note that it is necessary that \ are doubled in the path, and path must be correct.
# In MoI4, press Tab, and paste the line of code into the MoI command box and press enter.
# Code:
moi.filesystem.shellExecute( 'C:\\Users\\orcha\\AppData\\Local\\Programs\\Python\\Python39\\python.exe' )

# This Code works too:
moi.filesystem.shellExecute( 'C:\\Users\\orcha\\AppData\\Local\\Programs\\Python\\Python39\\python' )

# In Windows 10, the line of code below, following these comments, will open Rhino7 from the MoI command box.
# Note that Rhino7 is already installed in the path shown.
# Note that it is necessary that \ are doubled in the path, and path must be correct.
# In MoI4, press Tab, and paste the line of code into the MoI command box.
# Code:
moi.filesystem.shellExecute( "C:\\Program Files\\Rhino 7\\System\\Rhino.exe" )

Michaels Example code works:
var res = moi.filesystem.shellExecute( 'cmd /c dir c:\\', '', true );
if ( res.output ) moi.ui.alert( res.output );

So far, I have been unable to pass any python code or arguments, nor will the following code do anything:
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 );

I guess Windows stdout is different from python stdout?

(Still reading google searches...)

- Brian
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-9  10-29  30-44