Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

Python palette - how to create a new layout?

felcunha
Expert
Hello all,

I don't know if it's the right place to post this topic... please administrators feel free to move it if you feel so!
I'm struggling with the python scripts, not knowing how to handle the commands, types, utilities...
I think it would be nice to have a tutorial of how to deal with the syntax: when do we use dots, colons, parenthesis, double cotes, etc... Also, the few examples provided didn't help that much yet.
My first goal now is how to create a layout using a script.
Does anyone could help me with this?

Cheers,
Felipe Ribeiro Cunha

AC 25, OS X Big Sur
1 REPLY 1

runxel
Mentor
You can't be reasonably expecting Graphisoft to teach you Python
I think you already need at least a bit of knowledge. Don't worry, tho. Python is super easy to learn and there are thousands of free tutorials out there! If you are in a hurry, take a look at this.

And now for some code!


# 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)

AC 24 [ger] | Win 10 | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!