Wings 3D Development Forum
Scripting with Scheme and Python - Printable Version

+- Wings 3D Development Forum (https://www.wings3d.com/forum)
+-- Forum: Wings 3D (https://www.wings3d.com/forum/forumdisplay.php?fid=1)
+--- Forum: Design & Development (https://www.wings3d.com/forum/forumdisplay.php?fid=6)
+--- Thread: Scripting with Scheme and Python (/showthread.php?tid=3096)

Pages: 1 2 3 4 5


RE: Scripting with Scheme and Python - ivla - 03-14-2025

New version of thread generating script (python)

Changed parameters dialog;
Corrected "Round" profile;
Added "Semi-round inside" profile.


RE: Scripting with Scheme and Python - edb - 03-22-2025

Some of the new features in the next build:
  • Simplified returning data from script
  • Plugin Scripts
  • Script Folders
  • Better designed command script API

Simplified returning data from script

Scripts for the next release will have to have a small change,
as previously scripts had to write the result themselves using
write_list_out(sys.stdout), now the data can simply be returned
instead.

In Python, this was how to create a new shape:

Code:
    ...
    shape = w3d_newshape.NewShape()
    shape.fs = Fs
    shape.vs = Vs
    o = shape.as_output_list()
    print("")
    o.write_list_out(sys.stdout)

Now it will be:

Code:
    ...
    shape = w3d_newshape.NewShape()
    shape.fs = Fs
    shape.vs = Vs
    return shape

And this was how to do a file import:

Code:
    print("")
    e3df = w3d_e3d.E3DFile()
    e3df.objs = objs
    e3df.mat = mats
    o_ok = OutputList()
    o_ok.add_symbol("ok")
    o_ok.add_list(e3df.as_output_list())
    o_ok.write_list_out(sys.stdout)

Now it has changed to:

Code:
    e3df = w3d_e3d.E3DFile()
    e3df.objs = objs
    e3df.mat = mats
    return Okay(e3df)

In Scheme, a new shape was created with:

Code:
    ...
    (newline)
    (write (list new_shape "Shape" Fs Vs)))

Now it has changed to:

Code:
    ...
    (list 'new_shape "Shape" Fs Vs))

And for a file import:

Code:
    ...
    (newline)
    (write `(ok ,e3df)))

Has now changed to:

Code:
    ...
    `(ok ,e3df))

Scripts in the wings script pack repository will be updated to
the new style when I'll have the new build available.


Plugin Scripts

A script (.py or .scm) and .wscr file can be bundled with a
plugin script conf file and the three can be added to a folder in
the user folder called "plugin_scripts" and the script will now
show up with its own menu entry in the right click menus.
This makes it so a script can be packaged for distribution and
installed like an actual plugin.


Script Folders

Script folder conf files are added in a user folder called "script_folders"
and this makes it so a folder of scripts can be made into a submenu in
the wings program. It's similar to the plugin script conf file,
but more for power users to have separate script folders in
different menus in wings.


Better designed command script API

Until now the scripting plugin didn't provide a way to actually
change anything too complicated in the #we{} other than vertex
positions and colors. The next build command scripts can actually
make changes to #we{} directly using wings' various functions
in wings_we, wings_face, wings_edge, wings_vertex, etc.

This part is getting close to complete and I'll have a new build
available when I have a few test scripts working.


RE: Scripting with Scheme and Python - ivla - 03-24-2025

Good news, edb!

(03-22-2025, 06:16 PM)edb Wrote: A script (.py or .scm) and .wscr file can be bundled with a
plugin script conf file and the three can be added to a folder in
the user folder called "plugin_scripts"
You mean it can be packed like other plugins in .tar file?
Show an example, please.


RE: Scripting with Scheme and Python - edb - 03-25-2025

Hello ivla

(03-24-2025, 08:20 AM)ivla Wrote: You mean it can be packed like other plugins in .tar file?
Show an example, please.

Yep that's exactly it, the script can be packaged in a tar file and
will be installable the same way as plugins.

The script and .wscr file won't need any changes to turn it into
a plugin script, and the extra .conf file provides the menu location.
For the .tar file, there might be a fourth file that is like a "manifest"
so wings knows which plugin to ask about installing the .tar file.

An example package might have:

Code:
manifest
special_shape_bumpy.conf
special_shape_bumpy/special_shape_bumpy.wscr
special_shape_bumpy/special_shape_bumpy.py

the file special_shape_bumpy.conf might look like:

Code:
{"unique-script-name.author-name.special-shape-bumpy.1", [
    {wscr, "special_shape_bumpy/special_shape_bumpy.wscr"},
    {menu, [
        {[shape, special_shapes, special_shape_bumpy], []}
    ]}
]}.

{strings, [
    {plugin, "unique-script-name.author-name.special-shape-bumpy.1"},
    {"en", [
        {{plugin,name}, "Bumpy Shape"},
        {{menu,special_shapes}, "Special Shapes"},
        {{menu,special_shape_bumpy}, "Bumpy Shape"}
    ]}
]}.

Some explanations:

Code:
{wscr, "special_shape_bumpy/special_shape_bumpy.wscr"},
.wscr is in a subfolder "special_shape_bumpy" relative to the .conf file.

Code:
    {menu, [
        {[shape, special_shapes, special_shape_bumpy], []}
    ]}
It will be added to a menu "Bumpy Shape" inside a custom sub menu
called "Special Shapes", inside the new shape menu.

Code:
{strings, [
    {plugin, "unique-script-name.author-name.special-shape-bumpy.1"},
    {"en", [
        {{plugin,name}, "Bumpy Shape"},
        {{menu,special_shapes}, "Special Shapes"},
        {{menu,special_shape_bumpy}, "Bumpy Shape"}
    ]}
]}.
For each language a set of strings can be made. The unique
string "unique-script-name.author-name.special-shape-bumpy.1"
needs to match though.


RE: Scripting with Scheme and Python - ivla - 03-26-2025

edb, thank  you.


RE: Scripting with Scheme and Python - edb - 05-05-2025

A new build of the scripting plugin:

PLUGIN:
wpc_scripting_shapes.tar

PATCH:
patch_scripting.tar


Another change for this release.

The syntax of .wscr has changed slightly but only
if you were using parameter queries, now they have a
different syntax to distinguish them from strings and atoms
by enclosing the parameter query in %[...] instead of "...".
Atoms used to be enclosed with "'atom'", now they are
enclosed just with single quotes 'atom'.

As an example, this .wscr file for the milkshape exporter
used to look like this:

Code:
params_title ?__(3,"Milkshape3D Exporter Settings")
...
params_set {
  export_param "tesselation"  "'triangulate'"
  export_param "include_uvs"  "'true'"
  export_param "subdivisions" "params/subdivisions"
  export_param "include_normals" "'true'"
  export_param "include_hard_edges" "bool(params/include_normals)"
  export_param "script_texture_convert" "'user'"
}
...

Now the file will look like this:

Code:
params_title ?__(3,"Milkshape3D Exporter Settings")
...
params_set {
  export_param "tesselation"  'triangulate'
  export_param "include_uvs"  'true'
  export_param "subdivisions" %[params/subdivisions]
  export_param "include_normals" 'true'
  export_param "include_hard_edges" %[bool(params/include_normals)]
  export_param "script_texture_convert" 'user'
}
...



RE: Scripting with Scheme and Python - micheus - 05-06-2025

Thanks for the update


RE: Scripting with Scheme and Python - ivla - 05-23-2025

New script for plugin, generates square slab with upper side divided as 2D Voronoi diagram (with irregular structure).

Download here

Written on Python, uses numpy and scipy modules. With large number of cells can be slow!

Parameters:
Number of upper side cells, 3..1024 (and 4 "corner" cells will be added)
Square size, 0.1 min
Slab thickness, 0 or more
Sampling optimization:
None
[Image: none.jpg]
Less
[Image: less.jpg]
or More
[Image: more.jpg]

Back (lower) side is one face:
[Image: back.jpg]