algorithmic modeling for Rhino
Hey guys,
I have a question about exporting geometry from a layer to seperate files in python. Im just starting so im not that advance yet :) Below is my code:
rhinoscriptsyntax as rs
layers = rs.LayerNames()path = "C:\Users\ariew\Desktop\\testACAD\\"
for i in layers:
rs.CurrentLayer(i)
obj = rs.ObjectsByLayer(i, True)
pathh = path+i+".dwg"
rs.Command("_-export" +pathh)
rs.Command("_selnone")
It works almost, the thing that doesnt work is the rs.command("_-export" +pathh)
It says
"Unknown command: _-exportC:\Users\ariew\Desktop\testACAD\Level__35.dwg"
Thanks in advance,
Arie-Willem
Tags:
Hi Arie-Willem,
it seems there is a space missing (such a small mistake :) )
I'd suggest to use the format functions in Python to avoid it:
rs.Command('_-export "%s"' % (pathh))
I hope this helps,
- Giulio
________________
giulio@mcneel.com
McNeel Europe
It works, but the thing is that afterwards the rs.Command('_-export "%s"'%(pathh)) command it asks how to save it -> Default Scheme etc, I just want it 'enter' trough but no matter what i try i cant get it right.
i tried
rs.Command('_-export "%s"'%(pathh)+'_enter')
rs.Command('_-export "%s"'%(pathh)%'_enter')
rs.Command('_-export "%s"'%(pathh)&'_enter')
rs.Command('_-export "%s"'%(pathh)%'%s')
etc..
Even starting with a new line rs.Command('_enter') but that doenst work it needs to be in the same line as the export command i think.
Thanks in advance!
Arie-Willem
ps here is my code (nevermind the sloppyness :))
import rhinoscriptsyntax as rs
layers = rs.LayerNames()
path = "C:\Users\Rojkind09\Desktop\\testACAD\\"
for i in range(0,len(layers)):
__if rs.IsLayerCurrent(layers[i]) == False:
____rs.LayerLocked(layers[i],True)
for i in layers:
__rs.CurrentLayer(i)
__ch = rs.LayerChildCount(i)
__if ch == 0:
____if rs.IsLayerLocked(i):
______rs.LayerLocked(i,False)
____if rs.IsLayerEmpty(i) == False:
______obj = rs.ObjectsByLayer(i, True)
______rs.SelectObjects(obj)
______pathh = path+i+".dwg"
______print pathh
______rs.Command('_-export "%s"'%(pathh))
______rs.Command('-_enter _enter')
______rs.UnselectAllObjects()
rs.CurrentLayer("Default")
Hi again,
it seems there is a little confusion here about the Python way to format strings.
Here is the topic on python.org: http://docs.python.org/library/string.html#format-string-syntax
If you need to add more things in one line, I'd suggest to add it within the first string:
rs.Command('_-export "%s" _Enter' % (pathh))
for example, or, here, a bit more complete (geometry needs to be selected in advance):
import rhinoscriptsyntax as rs
pathh = "C:\\temp.dwg"
formatted_text = '_-export "{0}" _Enter'.format(pathh)
rs.Command(formatted_text)
Please upload a sample file if you need more help with the script, or visit the Rhino.Python discussion forum at http://python.rhino3d.com/ .
I hope this helps,
- Giulio
________________
giulio@mcneel.com
Hey Giulio, your the man! :)
Flipping the _enter around.. *sigh.. sometimes the solution can be so simple. I attached my script, maybe usefull for other people.
P.S. Im used to script in processing, they have a really clear website with script syntax, libraries, examples, books etc. Do you happen to know if there is something like this for rhino python. I searched docs.python.org and http://python.rhino3d.com/ but I got kind of lost :)
Thanks again!
Cheers!
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by