<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python palette - how to create a new layout? in Archicad Python API</title>
    <link>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/273262#M716</link>
    <description>&lt;DIV class="actalk-migrated-content"&gt;Hello all,&lt;BR /&gt;&lt;BR /&gt;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!&lt;BR /&gt;I'm struggling with the python scripts, not knowing how to handle the commands, types, utilities...&lt;BR /&gt;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.&lt;BR /&gt;My first goal now is how to create a layout using a script.&lt;BR /&gt;Does anyone could help me with this?&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;/DIV&gt;</description>
    <pubDate>Wed, 15 Sep 2021 07:52:09 GMT</pubDate>
    <dc:creator>felcunha</dc:creator>
    <dc:date>2021-09-15T07:52:09Z</dc:date>
    <item>
      <title>Python palette - how to create a new layout?</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/273262#M716</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hello all,&lt;BR /&gt;&lt;BR /&gt;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!&lt;BR /&gt;I'm struggling with the python scripts, not knowing how to handle the commands, types, utilities...&lt;BR /&gt;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.&lt;BR /&gt;My first goal now is how to create a layout using a script.&lt;BR /&gt;Does anyone could help me with this?&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Sep 2021 07:52:09 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/273262#M716</guid>
      <dc:creator>felcunha</dc:creator>
      <dc:date>2021-09-15T07:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Python palette - how to create a new layout?</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/273263#M717</link>
      <description>You can't be reasonably expecting Graphisoft to teach you Python  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_wink.gif" style="display : inline;" /&gt; &lt;BR /&gt;
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 &lt;A href="https://learnxinyminutes.com/docs/python/" target="_blank"&gt;this&lt;/A&gt;.&lt;BR /&gt;
&lt;BR /&gt;
And now for some code!&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;
# Simplest example for creating a Layout in Archicad
# BOML | runxel 2020
# v1.0 | works in ac24.b3008
# create_layout.py
# for &amp;lt;https://archicad-talk.graphisoft.com/viewtopic.php?f=23&amp;amp;t=70570#p315412&amp;gt;

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)

&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Aug 2020 19:53:41 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/273263#M717</guid>
      <dc:creator>runxel</dc:creator>
      <dc:date>2020-08-26T19:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python palette - how to create a new layout?</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/361150#M718</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.graphisoft.com/t5/user/viewprofilepage/user-id/640"&gt;@runxel&lt;/a&gt;&amp;nbsp;for your solution! It works if I already have a subset created before.&lt;/P&gt;&lt;P&gt;Now I'd like to create a new subset directly under the root. I've tried with a command that I've called &lt;EM&gt;Nouveau_dossier,&lt;/EM&gt; and I've set the name of the parent to "".&lt;/P&gt;&lt;P&gt;But, AC returns an error.&lt;/P&gt;&lt;P&gt;Here's the script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 12:17:02 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Python-palette-how-to-create-a-new-layout/m-p/361150#M718</guid>
      <dc:creator>felcunha</dc:creator>
      <dc:date>2022-11-04T12:17:02Z</dc:date>
    </item>
  </channel>
</rss>

