3DLIRIOUS / MeshLabXML

Create and run MeshLab XML scripts with Python
GNU Lesser General Public License v2.1
202 stars 43 forks source link

Orange cube example throwing Attribute error #11

Closed DrBwts closed 6 years ago

DrBwts commented 6 years ago

Win 10 x64, Python 2.7, MeshLab_64bit_fb v2016.12

I've tried to run the Orange Cube example but I get the following...

image

3DLIRIOUS commented 6 years ago

Hi! It looks like you are using an outdated example, which uses the depreciated file-based script API. May I ask where you found it so I can update it? The newer API is class-based and much more versatile, and many filters now only work with the new API (for example, any filter that needs to perform different behavior based in the MeshLab version). The orange cube example in README.md is as follows, please give it a try instead:

import meshlabxml as mlx

orange_cube = mlx.FilterScript(file_out='orange_cube.ply', ml_version='2016.12')
mlx.create.cube(orange_cube, size=[3.0, 4.0, 5.0], center=True, color='orange')
mlx.transform.rotate(orange_cube, axis='x', angle=45)
mlx.transform.rotate(orange_cube, axis='y', angle=45)
mlx.transform.translate(orange_cube, value=[0, 5.0, 0])
orange_cube.run_script()
DrBwts commented 6 years ago

Hi I got the example from here.

I just tried the above example & got the following..

meshlab_xml_example

3DLIRIOUS commented 6 years ago

I will need to check why PyPi is no longer using Readme.md for the project description, thanks for the heads up!

Some questions:

  1. What version of MLX are you using? Are you using 2018.3 from PyPi, the latest github version, or something else?
  2. What happens if you run the py file from a terminal (i.e. cmd.exe) instead of from inside your editor? Does it provide any additional information?

Try saving to a log file and see if that provides any more info. Modified code:

import meshlabxml as mlx

log = 'orange_cube_log.txt'

orange_cube = mlx.FilterScript(file_out='orange_cube.ply', ml_version='2016.12')
mlx.create.cube(orange_cube, size=[3.0, 4.0, 5.0], center=True, color='orange')
mlx.transform.rotate(orange_cube, axis='x', angle=45)
mlx.transform.rotate(orange_cube, axis='y', angle=45)
mlx.transform.translate(orange_cube, value=[0, 5.0, 0])
orange_cube.run_script(log=log, output_mask='-m vc')
DrBwts commented 6 years ago

I installed using pip install meshlabxml

I can confirm that it works from a command terminal just not from within Spyder.

3DLIRIOUS commented 6 years ago

If it doesn't work from Spyder then perhaps Spyder cannot find meshlabserver in the path. Try adding the following code to the start of the file, correct as needed for the location of your MeshLab install:

import os

meshlabserver_path = 'C:\\Program Files\\VCG\\MeshLab'
os.environ['PATH'] = meshlabserver_path + os.pathsep + os.environ['PATH']
DrBwts commented 6 years ago

OK I hadnt restarted Spyder after I added Meshlab to PATH. All working now.

Thanks for the great tool.

3DLIRIOUS commented 6 years ago

Glad it's working for you now!