Hello everyone.
I need to make a simple script that loads a model (lightwave format), executes a couple of commands on it, then saves it as iges format.
I need it to go through processing every file in a directory.
However I am not familiar with rhino script and my time is tight right now.
Can anyone help me with this?
Thanks in advance.
In general, it is not that hard to script a batch conversion process from one file format to another. However, there a few considerations in your particular case. The main problem I see is that the lightwave format (.lwo) is a polygon format, whereas IGES is a NURBS surface format. I’m pretty sure the IGES file format does not support meshes; I am 100% certain that Rhino does not export meshes in IGES format. So, what you want may not even be possible directly…
What is the actual need for this batch conversion?
–Mitch
No worries about the conversion of polygonal to solid. It is done through a plugin (T-Splines)
OK, then it should be possible to do - we would need to know what commands need to be executed on the objects in the file (tsConvert…) in between the import and export…
–Mitch
Just a couple
tsConvert and tsSmoothToggle. Then of course the save as IGES but i’m not sure how to define this as a command.
OK, I’ll try to adapt something I have here. Won’t be able to test the conversion as I don’t have T-Splines. I assume you just select the objects and run those two commands without any other user intervention?
Is there a specific “flavor” of IGES export or a specific destination program you need? There are about 50 varieties available in Rhino’s IGES export options…
–Mitch
Yes, for IGES output options, Solidworks Surfaces should do it just fine. Units are in mm. Tolerance i believe is default at 0.001
OK, one more question - tsSmoothToggle - is that just a visual display thing or does it actually affect the object? What I mainly need to know is if that command is really necessary for the script and if so if it actually changes the object GUID, or just modifies it in-place.
–Mitch
Yes both are needed to turn polygons into splines.
how can i check if it changes the object GUID?
Run the tsConvert command on a mesh object. Select the newly converted t-splines object, and in properties>details, note the object ID. Then run the tsSmooth command and look in details again to see if it changed.
–Mitch
It seems that the main number remains the same. There is a parenthesis at the end with another number (on my current object it was (20)) which increased by 1 after each command.
OK, sorry for the delay, here’s something to try. I have no idea how this will work as I don’t have TS to test. I threw in a test section that will convert meshes in the .lwo file to NURBS vis the Rhino native MeshToNurb command so I could debug the rest, it is activated by setting the last line in the script TS=False. Here it works running simple .lwo mesh objects.
BatchConvertLWOToIGES(TS=False, echo=False)
If TS is set to True, it will try to run your T-Splines conversion. If it errors out somewhere, we will need to track down where. Setting echo=True on the last line will print some command-line messages then the ts commands are run, maybe that will help find the problem. I was not sure if the ts commands work on multiple selected objects at once, I assumed yes, if not, the script will need a secondary loop…
That’s about as far as I can go for now without T-Splines.
BatchConvertLWOToIGES.py (3.0 KB)
–Mitch
Thank you for your time and help Mitch!
I will give this a try.
Hey Mitch.
I finally got to the point of trying your script (I should have done that first thing not last minute, oh well)
It seems like the script stops while asking for user input:
"Select T-spline objects to toggle smooth display"
But before that it doesn’t seem like it is loading anything to work on.
I give it the directory where all the files are located in the beginning.
For the script I’d expect something like this pseudo code:
loop through each file in given directory
load next file
select all ( it might be multi part)
run tsConvert (wait for it to finish, if that doesn’t happen automatically)
run tsSmoothToggle
save as "same file name.IGES"
end loop.
All of that without user input needed.
Sorry but I’m not familiar with Rhino Python to edit this.
Much appreciate your help!
OK, I was afraid of that, I think tsConvert and/or the tsSmooth may also need an _Enter in the command string.
If you change the following line
rs.Command("tsConvert")
to
rs.Command("tsConvert _Enter")
and
rs.Command("tsSmoothToggle")
to
rs.Command("tsSmoothToggle _Enter")
Does that work better?
–Mitch
There must be some error with the syntax.
You should test the script on your end with some other command that can take an enter at the end.
I did. That’s why there is the section that uses MeshToNurb - activated by setting TS=False on the last line - and that seemed to work. I’ll see if I can set up a debug version for you that prints out some intermediate results when you use the T-Splines version, but otherwise, I don’t know what is really going wrong…
–Mitch
OK, here’s a version to test, should print a lot of info to the command line. Try it with a folder with just a couple of files that have only one or two objects in them first.
–Mitch
BatchConvertLWOToIGES.py (3.9 KB)
Looks like it works!
Mitch thank you so much! That will save me tons of time.
I owe you a few beers!