Hello,
I have a bit of python code I’m working on that inserts blocks into the current layout view but am trying to insert a block into each layout view within the list of input views.
The psuedo code is as follows:
get layout names
for each layout name
set current view
insert block
Expected result:
Input L = list of layout names
Input BN = block name
Input B = boolean toggle to activate script
Return = block inserted at each layout view
Here is the code thus far:
import Rhino
import scriptcontext as sc
#import System.Drawing
import rhinoscriptsyntax as rs
#import os
def layouts_get_by_names(layout_names):
layouts = []
for layout_name in layout_names:
view = Rhino.RhinoDoc.ActiveDoc.Views.Find(layout_name, True)
if isinstance(view, Rhino.Display.RhinoPageView):
layouts.append(view)
return layouts
if B:
#setup variables
block_name = BN
#loop through created layouts & insert block
for i, view in enumerate(layouts_get_by_names(L)):
print "Layout Names: " + str(L)
rs.CurrentView = L[i]
print L[i]
rs.InsertBlock( block_name, insertion_point=[0,0,0] )
Currently it inserts the blocks at the current view only, I am trying to iterate through the list of layout names and insert 1 block at each layout.
As it stands if I have say 5 layouts in the input, currently it inserts 5 blocks into the first layout only and thats only if in Rhino I’m already in that view.
I’m stuck on trying to make each layout view the current view, spawn the block, move onto the next and repeat until the list is exhausted.
Obviously I’m new to this and any help is much appreciated, I’ve been scouring the forums and web tutorials but can’t seem to get past this loop issue.
Thank you for your time!
