Python – move a mesh using pythonscript

No difference … I tried to shift the spaces between the words of the file name and it worked … but the problem that I have to rename all the files in the target folder again ! … Is there any way to deal with the white spaces in file name ?!

Normally you can get around that by using ascii character 34 (double quote mark) as follows:

filepath=chr(34)+"C:\\folder name with spaces\\filename with spaces"+chr(34)

Don’t know if that helps…
–Mitch

1 Like

sorry but it’s not working ! :frowning:

Well, the string formatting complexity goes along with the general complexity of Python - can do more, but there’s more to learn as well. However, I think you’ll get the hang of the str.format stuff pretty quickly, it’s pretty understandable if you don’t try all the fancy switches that you generally don’t need. Just use the simple substitutions.

I’ve never been able to wrap my head around the %s %s stuff…

Of course, you can always get away with just converting stuff to strings with str(value) and then concatenating as needed. You can go your entire life that way without ever having to deal with a format statement.

–Mitch

Helvetosaur’s advice works perfectly at my place.
The last few lines of your script:

for x in range (0, len(pathes)):
    path = chr(34)+pathes[x]+chr(34)
    moveMesh(path)
    rs.Command("-_selall")
    rs.Command("-_delete")

Thanks Mitch.

I already did mitch’s advise … I even did copy & paste your code in my code but its not working … are you sure that you applied mitch’s advise to a file name which has a white space between its words ?!

Yes, chr(34) works perfectly for file paths with blank space in between words.
In order to locate the problem you would have to attach at least two of your .stl files.

1 Like

OH , I did a mistake … now it’s working … Thanks Mitch and djordje :blush:

Any chance of converting this script to ghpython? I was trying to do something similar, but have the new centroid have it’s x, y coordinates be on a slider and the z coordinate be 1/2 the objects bounding box height to orient the object on the construction plane.
mesh2world.gh (9.9 KB)

Hi Nathan,
I can’t download your .gh definition to see what you have been doing (something is wrong with discourse server at the moment), but check the attached example.
Bear in mind that volume centroid of an object is not always located at the 1/2 of the object box height. Check the cone example from the .3dm file.
I introduced two choices - one will always use 1/2 of your bounding box height, while the other one will follow your actual volume centroid.

meshMoveGh.gh (9.3 KB)
meshMoveGh.3dm (33.5 KB)