+ Reply to Thread
Results 1 to 9 of 9

Thread: exporting surfaces as stl using rhino python in os x lion

  1. #1

    exporting surfaces as stl using rhino python in os x lion

    Hi,
    I'm new to rhino python and have been building a simple script to export surfaces in a layer to a stl file. I've used a pc rhino script as a basis but can't work out how to construct the rhino command to export the surfaces to an stl file. I've tried many permutations of the export command but no luck. Any help would be appreciated.


    import rhinoscriptsyntax as rs
    import os

    arrLayers=rs.LayerNames()
    pathname=rs.DocumentPath()
    name=rs.DocumentName()
    dir=os.path.split(pathname)[0]
    if arrLayers:
    for layer in arrLayers:
    rs.UnselectAllObjects()
    arrSelected = rs.ObjectsByLayer(layer, True)
    rs.ObjectsByLayer(layer, True)
    if (len(arrSelected) > 0):
    filename=dir+"/"+layer+".stl"
    print filename
    cmdToExport = "Export selAll Enter "+filename
    rs.Command(cmdToExport)

  2. #2
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    287
    Hi,

    You can try the following code out:
    python Code:
      import rhinoscriptsyntax as rs
       
      def ExportSTL():
          filepathname=rs.DocumentPath()
          if not filepathname:
              # doc has not been saved
              filepathname=rs.SaveFileName("Save STL","STL Files |*.stl||")
              if not filepathname: return
             
          filepathname=filepathname[:-4] #remove the extension
         
          arrLayers=rs.LayerNames()
          for layer in arrLayers:
              rs.UnselectAllObjects()
              #selects objects if present
              objs=rs.ObjectsByLayer(layer, True)
              if objs:
                  #path needs to be enclosed in quotes in case there are
                  #spaces in either the file name or the layer name
                  fullpath='"'+filepathname+"-"+layer+".stl"+'"'
                  rs.Command("_-Export "+fullpath+" _Enter _Enter")
       
      ExportSTL()
    This works in Windows, I don't know if it works on Mac.
    Some things I added:
    Encapsulate in a definition so you can escape if no file path is found
    Allow the user to enter a save file name if the original document has not yet been saved
    Be careful - if you have sublayers and two or more have the same name (allowed in rhino 5) the last layer will overwrite the previous ones...
    I didn't have too much time to put in a lot of explanations, yell if you don't get anything...
    --Mitch

    Oh, yes, forgot to add that this will use the last used settings for .stl export. If you want specific .stl settings, it's possible, but the script gets quite a bit longer...
    Last edited by Mitch; 04-10-2012 at 04:39 PM.

  3. #3
    Hi Mitch, thanks for the reply. The mac version of Rhino didn't like it. It came back with two errors, the first saying the there was an 'unknown or unimplemented command'. It displayed that the command that is not implemented was the fullpath. The second error was 'Command not implemented , running command with dash option not implemented'. I've had a few errors like these and I've tried various ways of building the rs.command() with no luck. I suspect it's that the mac version of rhino python that's not parsing the rs.command properly.

  4. #4
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    287
    Yes, well it looks like you're well and truly screwed on this one... It's not the Mac version of Python that's at fault on this one - it's Mac Rhino, period. Dash version of Export is not implemented and as far as I can tell, and that's the only way to export ANY kind of file (not just an stl) without going through the dialog interface. Which means that there's no way you're going to be able to batch export layer by layer and grab the layer names. Sorry.
    --Mitch

  5. #5
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    Marlin is actually in the office here in Seattle today. I went over and poked him with a stick to ask what is the status of the dashed Export command; a little moaning and groaning later he grumbled something about it being on his todo list

    As for now I think Mitch's comments are correct.

    Thanks,
    -Steve

  6. #6

    thank you

    Hi, thank you for the quick response. Keep up the great work. I'll look forward to a future with dashed export!

    Best wishes,

    Andy.

  7. #7
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    Marlin let me know that the dashed version of SaveAs and Export should be available in the next Mac build.
    -Steve

  8. #8
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    287
    Yah, cool mon...! --Mitch

  9. #9

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts