Export selected by automatically using the object name as a file name? Rhino 7 wish

Hello, is there a way to do a macro and assign it to a single custom icon, doing the following?
Once I select a group of curves that forms a flat drawing for laser cutting, I need to run these commands all in once to automate the process:

  1. Copying the object name (for example “HL-3-15”).
  2. Export selected (here is the prompt for selecting the file type, where I pick DXF).
  3. Using the copied object name as a file name (should be “HL-3-15.dxf”).

Or, is there a way that in a future release Rhino will have an option to use the object name to export multiple objects depending on their object name? For example, if there are 287 selected objects with 4 different names, Rhino would save 4 new files where the 287 objects were sorted out and allocated depending on their unique object name.

Thanks,

Bobi

Definitely scriptable (macro, no) I have scripts to export by layer or by object but not by object name, it shouldn’t be too hard to modify one of those… Probably someone will beat me to it here, it’s too late to get going on it tonight.

Hi! Sound like you know your stuff. :slight_smile: It would be great if you can write such script, because it’s a huge time saver when working with multiple named objects like that. Cheers!

You might like to give a try at this one.
It’s the script I regularly use for the purpose you said.

c5-exportwithname.py (5.4 KB)

HTH

Thanks, I will try this. Just one silly question: How to make a custom button to evoke that script? :slight_smile:

This is McNeel’s info about that …

( You might have to write the full path of the Python file in the button. )

1 Like

Thank you!

Edit: I put the full path and name of the Python script in the button’s text field, but that only brings a pop-up window to browse and manually pick the script from the folder where it’s saved. I remember that there must be a way to automate the process and skip that pop-up window. Any suggestions?

I ran the script and tried the options it provides, however, there is no DXF export and the file name will not read the object’s name. There is an option to grab the Rhino file name or the layer name, but I don’t see how to use the object’s name as a new file name for the exported drawings.

Sorry

I mis-read your request.
The script uses the document’s name, not the object’s name …

Ah, I thought your script had solved it Emilio, so I didn’t post mine -

@Rhino_Bulgaria - here’s mine to try out - let me know how it works or if anything needs to be changed…

BatchExportDXFByObjName.py (1.4 KB)

2 Likes

Glad to see that Mitch has the right script. :slight_smile:

Anyway, I tried to ‘extend’ mine to make it able to also export by object name, and using DXF .
Here it is … just in case …

c5-exportwithname.py (5.9 KB)

Thanks

You can do this pretty easily with Grasshopper as well. Heteroptera can extract all the attributes and something like Elefront can save the files. That would save you having to fiddle with Python scripts.

1 Like

Thanks again! I found a few things that could be improved if you have the time.

  1. Every time I run the script, it goes back to the default “FileName”, so it requires one extra mouse click in the command prompt to change that to “ObjectName”.

  2. Then I have to click on the “DwgOutput = No” to change it to “DwgOutput = Yes” (the script is designed to support multiple formats, so I understand why it does that, it just requires one extra mouse click).

  3. The script won’t work if the object name has space between characters (such like “Tube 20 x 20 x2”). It works only with objects named without any space, such like “Tube20x20x2”.

  4. When the model is exported as DXF, it will not ask for a file directory or will not “remember” the last used directory. Instead, it automatically saves the DXF file into the last directory where I saved other DXF files with the regular “Export selected” command in Rhino (without your script). No matter how many times I export the DWG with the script to another directory, it always saves into the old directory, as I mentioned above.

  5. Trying to export 2 or more objects with different names together will result into a single DWX file consisting the selected objects, and the file name seems to be derived by the object whose name starts with a letter which is earlier in the alphabet (example: if there are 3 objects named “tube”, “pattern” and “drawing”, the script will export them together into a single DXF file named “drawing”.

Just gave it a little go and got pretty far. It looks through all object names, filters out those without a name then creates names and sets for all objects with the same name. So now I am stuck at the last step - the actual saving, but unfortunately Elefront’s Object Save is kind of broken if triggered with a Grasshopper Button - it just keeps saving in a loop and doesn’t really support data trees, so it would need to be in a loop, but that’s fine. I need to find a more reliable alternative first, but once that works it will do exactly what you want.

Thanks! I also tried your script and it works just fine. It saves multiple files at once, using the object names. If there are 50 objects with same name, it exports them together into a single file. That’s what I was looking for! It will not export locked objects, hidden objects or objects from hidden layers. This is useful.
Small wish (if possible): Is there a way to export only the (pre)selected objects? :slight_smile:

Sure, should be possible - one question: Say that some of the objects that are not preselected have a name that is the same as at least one of the objects that is preselected - I imagine you also want to ignore these and not export them?

Anyway, assuming that’s what you want, here is a modified script. If nothing is preselected, will work like before on the whole file; if anything is preselected, it will only include objects in the preselection.

BatchExportDXFByObjName.py (1.9 KB)

That’s right, I need to export only the preselected objects, because in some cases I have multiple copies of the same objects spread across the 3d scene and I wand to have only one of these (a group of curves) saved in a dedicated DXF file. Also, because I use those grouped curves to extrude solids (metal plates with certain thickness) with the same object name, I want to export only the curves in the DXF file.

I tested the updated version of your script and it works just as you described! Thank you! :slight_smile:

PS: This functionality really deserves to be a native part of Rhino’s export options! It’s a huge time saver.

No, sorry … :slight_smile:
I think this script is meant for a different purpose.

It works fine for what I need.
( I usually use it to export the model to one or more formats, keeping the 3dm file’s name.
BTW I don’t use spaces in file names … )

If you are looking for a custom-made script, Mitch’s script is a much better choice.

Regards

Yes, I guess everyone has his/her own kind of needs when it comes to how to use the program. :slight_smile:
I found Helvetosaur’s script to be exactly what I was looking for. Thanks to both of you for your effort! :slight_smile:

1 Like