Exporting script including hiding/showing objects

Hi there,
I am not used to scripts so I have no idea if this request is even possible.

Following situation (see picture first to get better idea what I am writing):
I want to create 9999 numberplates going from 0001 till 9999.
Each number on the thousands, hundreds, tens and one digit is on a respective level/sublevel.

The idea is that a script starts at 0001, saves this variant as a dxf with the file name 0001.dxf.
Then switch off/on the respective sublevels and save all 9999 possibilities with the respective file name.

Does anyone here see a way to make this possible or is it too complex?

I am happy for any suggestions.

Hi Till,

Yes this is certainly possible.
HOW many experience do you have with scripting?
I made a quick setup that might work already or you might need to tweak it.
Let me know what you think and report back

BE CAREFUL with directly testing all exports.

first test for a small range to make sure all works

export_badges.py (1.5 KB)

import rhinoscriptsyntax as rs
import os


def reset_layers():
    rs.CurrentLayer('Kreis')
    
    for layer in rs.LayerNames():
        rs.LayerVisible(layer, True)
        layer_end = layer[-1]
        if layer_end in ['0','1','2','3','4','5','6','7','8','9']:
            rs.LayerVisible(layer,False)


def turn_layer_on(position_index, number):
    
    positions = ['Duizendtallen','Honderdtallen', 'Tientallen', 'Enkeltallen']
    full_layer = '{}::{}'.format(positions[position_index],number)
    rs.LayerVisible(full_layer, True)


def export_visible(folder,dxf_name):
    
    rs.UnselectAllObjects()
    rs.SelectObjects(rs.NormalObjects())
    
    dxf_file = os.path.join(folder,dxf_name+'.dxf')
    
    rs.Command('_-Export {} _Enter'.format(dxf_file))
    
    rs.UnselectAllObjects()


def export_badges():
    
    folder = rs.BrowseForFolder('folder for export')
    if not folder:
        return
    start = rs.GetInteger('start number')
    if not start:
        return
    end = rs.GetInteger('last number')
    if not end:
        return
    
    rs.EnableRedraw(False)
    for N in range(start, end+1):
        reset_layers()
        text = '{:04d}'.format(N)
        
        for i, character in enumerate(text):
            turn_layer_on(i, character)
            
        rs.Redraw()
        export_visible(folder,text)
        
    rs.EnableRedraw(True)

if __name__ == '__main__':
     export_badges()

Thanks man, works like a charm =)

1 Like