Copy Paste to all Layouts with Python

Hi all,

Is there a way to copy pasted an object (or a selection of objects) to all layouts? If I copy/paste a block to all layouts then I only need to edit the block once then all instances of the block on all layouts will be updated.

I got as far as this with Python, I’d like to know how to activate each layout iteratively, I don’t think my code for activate layout is working:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

pageViews = sc.doc.Views.GetPageViews()

for pageView in pageViews:
    Rhino.Display.RhinoPageView.SetPageAsActive(pageView)
    
    rs.Command('_Paste')

Any pointer would be greatly appreciated
Thank you in advance

Hi David,

To activcate all layouts you can do this:

for view_name in rs.ViewNames(return_names = True, view_type=1):
    rs.CurrentView(view_name)

Does that help?

let us know if you have more questions
-Willem

3 Likes

thank you @Willem, it totally worked!

for anyone who needs it, the script lets you select an annotation object on one layout and copy/paste it to all layouts in the Rhino doc. :slight_smile:

import rhinoscriptsyntax as rs


obj = rs.GetObject("Select annotation on layout to copy to all", rs.filter.annotation)

rs.SelectObject(obj)
rs.Command('_CopyToClipboard')

rs.EnableRedraw(False)

for view_name in rs.ViewNames(return_names = True, view_type=1):
    rs.CurrentView(view_name)
    rs.Command('_Paste')
    
rs.EnableRedraw(True)
3 Likes

Hi David,
Thanks for the script!
Could you please help me with a slight modification?
I would like to be able to select multiple objects at once to copy to all layouts. Is this possible?
Thank you in advance
John

Hi,

Does this work:

import rhinoscriptsyntax as rs


objs = rs.GetObjects("Select objects on layout to copy to all")

rs.SelectObjects(objs)
rs.Command('_CopyToClipboard')

rs.EnableRedraw(False)

for view_name in rs.ViewNames(return_names = True, view_type=1):
    rs.CurrentView(view_name)
    rs.Command('_Paste')
    
rs.EnableRedraw(True)

Hi John

Thanks! I think Willem’s script should work.

Since my last post, I have added a function that lets you select which layout(s) you want to paste into, rather than just paste to all layouts.

Let me know how this one work for you, cheers

here is the code:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc



#using the sticky library, show a message box with Tool Description for 
#the first run. Message box is disabled afterwards
#Refer to Rhino Python sample files shipped with Rhino

stickyval = 0
if sc.sticky.has_key("pasteSelObjsToSelLayouts"):
    stickyval = sc.sticky["pasteSelObjsToSelLayouts"]
if stickyval < 1:
    rs.MessageBox(message='Copy Paste selected layout objects to selected layouts.', title='First Run Tool Tip',  buttons = 0 | 64)
    stickyval += 1
    sc.sticky["pasteSelObjsToSelLayouts"] = stickyval
    
    

def pasteSelObjsToSelLayouts():
    
    objs = rs.GetObjects("Select objects on layout to copy")
    
    rs.SelectObjects(objs)
    rs.Command('_CopyToClipboard')
    
    rs.EnableRedraw(False)
    
    pageNames = []
    pageViews = []
    for i in sc.doc.Views:
        if type(i) is Rhino.Display.RhinoPageView:
            pageNames.append(i.PageName)
            pageViews.append(i)
            
    printLayouts = rs.MultiListBox(pageNames, 
        message='Layout to paste into',
        title='Select layouts to paste into. Hold Ctrl+Shift for multiple selection. Hold Ctrl to add selection.')
    
    
    for printLayout in printLayouts:
        rs.CurrentView(printLayout)
        rs.Command('_NoEcho _Paste _SelNone _Zoom _All _Extents _SelDup _Delete')
        
    rs.EnableRedraw(True)     

pasteSelObjsToSelLayouts()
1 Like

Thank you Willem and David!
Haven’t tried it yet, when I do I’ll let you know.
Cheers guys!