I’ve created a set of .obj files that I would like to import them into Rhino, placing each object in a different location and orientation. So far, I can’t seem to get it to import even one .obj file. The obj file is in the same directory as my script. Here’s the command I’m using:
rs.Command("-_Import File1.obj")
When I try to run this, I get the error “Directory (null) does not exist”, which would seem to suggest that perhaps it wants a path name. But if I change the command to try to import a file name that doesn’t exist in that directory (e.g. “-_Import FFile1.obj”) it says “file not found”. So this would suggest that it IS finding the file when I give it the correct name.
Any suggestions for how to make this work would be most welcome. And I’d also appreciate any advice on how to reposition that obj file once I’ve imported it.
Not knowing what Rhino’s current working folder is, you should always specify the full path to any file you are opening/importing.
Also, in case the path string contains spaces, we will want to surround the string with double-quote characters so the command line parser will deal with the string property.
OK, I tried giving it the complete pathname:
rs.Command("-_Import “/Users/edmark/Library/Application Support/McNeel/Rhinoceros/Scripts/…/test.obj”")
It definitely finds the file (I know this because if I give it an incorrect file name with the same path, it complains that the file doesn’t exist). But now I get the following error message:
It then gives me the option of reporting the error to Rhino.
I’m rather sure that it is also finding the file when I don’t give it the complete path (since, here too, it complains if I give it a non-existant file name). But in this case I get a different error message (as stated in my earlier post):
Directory (null) does not exist
The bottom line is that I just need to be able to import a .obj file into Rhino using Python. I’m not wed to using the “_Import” syntax. I’m happy to try a completely different approach if someone would be kind enough to suggest one. Surely there must be a way to perform such a straightforward operation, no?
Thanks for the suggestion, but I’m not quite sure how to implement it. I’ve used insert to add a .3dm file, such as here, where the file is filename.3dm:
rs.Command("-_Insert filename _Block _Scale 1 _Rotate 90 0,0,0")
But I have no idea how to get it to do something like this for an .obj file, particularly since “insert” seems to assume the file is a .3dm file. Could you please suggest a syntax?
-_Insert /Users/jeff/Desktop/example.obj O M enter 0 1 0
run the -Insert command from rhino though… there are some other options available where i used M in the above… you may want/need some of those options.
if you’re using rs.Command() ,it’s basically the same thing as making a macro… it’s not really a rhinoscriptsyntax / python thing… i suppose it’s a way to ensure all commands are available via script even when a specialize rhinoscript function is not available?
so it works the same way as running the command from within rhino itself… in rhino, run the -Insert command then follow the prompts… those are the same things you’ll be able to enter in a macro or rs.Command()