Import a new layout

Hi, how could I import a layout from file using pythonscript? Thank you.

Hi @Yang_Cao,

just found a very old rhinoscript (vb) which was converted to python line by line. You need to define the page number to import in the script when multiple layout pages exist in the source file.

import rhinoscriptsyntax as rs

def ImportLayoutFromFile():
    f = rs.OpenFileName("Import Layout", "Rhino Files (*.3dm)|*.3dm||")
    if not f: return
    # define the page number
    page = 1
    # the import command options
    cmd = "_-ImportLayout" + chr(32)
    cmd += chr(34) + f + chr(34) 
    cmd += chr(32) + str(page) 
    cmd += chr(32) + "_EnterEnd"
    # import
    result = rs.Command(cmd, False)
    if not result:
        print "error importing layout from {}".format(f)
    else:
        print "layout page number {0} imported from {1}".format(page, f)

if __name__=="__main__":
    ImportLayoutFromFile()


There might be better ways using Rhino.File3dm class and GetPageViews(), but i´m not save with it :wink:

c.

1 Like

It worked! Thank you so much Clement!!