2020-08-22
05:17 PM
- last edited on
2021-09-15
09:52 AM
by
Noemi Balogh
2020-08-26 09:53 PM
# Simplest example for creating a Layout in Archicad
# BOML | runxel 2020
# v1.0 | works in ac24.b3008
# create_layout.py
# for <https://archicad-talk.graphisoft.com/viewtopic.php?f=23&t=70570#p315412>
from archicad import ACConnection
conn = ACConnection.connect()
assert conn
acc = conn.commands
act = conn.types
acu = conn.utilities
#### some basic config ####
master_name = "A2 Querformat" # the Master Layout you want to use
parent_name = "Parent" # Parent folder name
lname = "New Layout" # Name of the layout to be created
# DIN A2 format size; always millimeter
lhor = 594
lvert = 420
lmargin_left = lmargin_top = lmargin_right = lmargin_bottom = 0
# Declare the appropiate Layout Parameters (see API for more info)
lparam = act.LayoutParameters(lhor, lvert,
lmargin_left, lmargin_top, lmargin_right, lmargin_bottom,
"", False, False, False, 1, 1, "", "", False, False)
# which tree to checkout: 'LayoutBook', 'PublisherSets', 'ViewMap'
root_tree_loc = 'LayoutBook'
# Retrieve the Root Item
layoutbook_tree = acc.GetNavigatorItemTree(act.NavigatorTreeId(root_tree_loc))
# Now a bit weird stuff:
# For the FindInNavigatorItemTree function we need a criteria function, which gets called
# with the item to check as only parameter.
# We will then automatically loop over all items in the defined tree.
# In this function we can decide if the current item adheres to our criteria,
# if so, we will return true.
def findMaster(item: act.NavigatorItem):
return True if item.name == master_name else False
def findParent(item: act.NavigatorItem):
return True if item.name == parent_name else False
list_master = acu.FindInNavigatorItemTree(layoutbook_tree.rootItem, findMaster)
list_parent = acu.FindInNavigatorItemTree(layoutbook_tree.rootItem, findParent)
lmaster = list_master[0].navigatorItemId
lparent = list_parent[0].navigatorItemId
# Now actually create the Layout; returns a GUID on `new_layout`
new_layout = acc.CreateLayout(lname, lparam, lmaster, lparent)
2022-11-04 01:17 PM
Thank you @runxel for your solution! It works if I already have a subset created before.
Now I'd like to create a new subset directly under the root. I've tried with a command that I've called Nouveau_dossier, and I've set the name of the parent to "".
But, AC returns an error.
Here's the script:
from Archicad import ACConnection
conn = ACConnection.connect()
assert conn
acc = conn.commands
act = conn.types
acu = conn.utilities
#### some basic config ####
master_name = "EOC A1" # the Master Layout you want to use
#parent_name = "GROUND FLOOR" # Parent folder name
parent_name = "" # Parent folder name
lname = "New Layout" # Name of the layout to be created
# DIN A2 format size; always millimeter
lhor = 841
lvert = 594
lmargin_left = lmargin_top = lmargin_right = lmargin_bottom = 5
# Declare the appropiate Layout Parameters (see API for more info)
lparam = act.LayoutParameters(lhor, lvert,
lmargin_left, lmargin_top, lmargin_right, lmargin_bottom,
"", False, False, False, 1, 1, "", "", False, False)
# which tree to checkout: 'LayoutBook', 'PublisherSets', 'ViewMap'
root_tree_loc = 'LayoutBook'
#dossier
dossier = act.Subset("GROUND FLOOR",True,False,True,True,False,"","","1",1,"")
# Retrieve the Root Item
layoutbook_tree = acc.GetNavigatorItemTree(act.NavigatorTreeId(root_tree_loc))
# Now a bit weird stuff:
# For the FindInNavigatorItemTree function we need a criteria function, which gets called
# with the item to check as only parameter.
# We will then automatically loop over all items in the defined tree.
# In this function we can decide if the current item adheres to our criteria,
# if so, we will return true.
def findMaster(item: act.NavigatorItem):
return True if item.name == master_name else False
def findParent(item: act.NavigatorItem):
return True if item.name == parent_name else False
list_master = acu.FindInNavigatorItemTree(layoutbook_tree.rootItem, findMaster)
list_parent = acu.FindInNavigatorItemTree(layoutbook_tree.rootItem, findParent)
lmaster = list_master[0].navigatorItemId
lparent = list_parent[0].navigatorItemId
#test création de subset
nouveau_dossier = acc.CreateLayoutSubset(dossier, lparent)
# Now actually create the Layout; returns a GUID on `new_layout`
new_layout = acc.CreateLayout(lname, lparam, lmaster, lparent)