<?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 script for column numbering in Archicad Python API</title>
    <link>https://community.graphisoft.com/t5/Archicad-Python-API/Python-script-for-column-numbering/m-p/579483#M946</link>
    <description>&lt;P&gt;Is it possible to use a python script to set the ID of the columns, so that all columns of the same dimensions have a common ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have edited zone script and that's working, but every column have unique ID, I need unique ID for column with same dimensions (width, hight, length).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from archicad import ACConnection
from typing import List, Tuple, Iterable
from itertools import cycle

conn = ACConnection.connect()
assert conn

acc = conn.commands
act = conn.types
acu = conn.utilities

propertyId = acu.GetBuiltInPropertyId('General_ElementID')

propertyValueStringPrefix = 'POS S'
elements = acc.GetElementsByType('Column')

ROW_GROUPING_LIMIT = 0.25
STORY_GROUPING_LIMIT = 1

def GeneratePropertyValueString(storyIndex: int, elemIndex: int) -&amp;gt; str:
    return f"{propertyValueStringPrefix}{storyIndex:1d}{elemIndex:02d}"

def generatePropertyValue(storyIndex: int, elemIndex: int) -&amp;gt; act.NormalStringPropertyValue:
    return act.NormalStringPropertyValue(GeneratePropertyValueString(storyIndex, elemIndex))

def createClusters(positions: Iterable[float], limit: float) -&amp;gt; List[Tuple[float, float]]:
    positions = sorted(positions)
    if len(positions) == 0:
        return []
    clusters = []
    posIter = iter(positions)
    firstPos = lastPos = next(posIter)

    for pos in posIter:
        if pos - lastPos &amp;lt;= limit:
            lastPos = pos
        else:
            clusters.append((firstPos, lastPos))
            firstPos = lastPos = pos
    clusters.append((firstPos, lastPos))
    return clusters

boundingBoxes = acc.Get3DBoundingBoxes(elements)
elementBoundingBoxes = list(zip(elements, boundingBoxes))
zClusters = createClusters((bb.boundingBox3D.zMin for bb in boundingBoxes), STORY_GROUPING_LIMIT)

storyIndex = 0
elemPropertyValues = []
for (zMin, zMax) in zClusters:
    elemIndex = 1
    elemsOnStory = [e for e in elementBoundingBoxes if zMin &amp;lt;= e[1].boundingBox3D.zMin &amp;lt;= zMax]
    yClusters = createClusters((e[1].boundingBox3D.yMin for e in elemsOnStory), ROW_GROUPING_LIMIT)

    for ((yMin, yMax), reverseOrder) in zip(yClusters, cycle([False, True])):
        elemsInRow = [e for e in elemsOnStory
                        if yMin &amp;lt;= e[1].boundingBox3D.yMin &amp;lt;= yMax]

        for (elem, bb) in sorted(elemsInRow, key=lambda e: e[1].boundingBox3D.xMin, reverse=reverseOrder):
            elemPropertyValues.append(act.ElementPropertyValue(
                elem.elementId, propertyId, generatePropertyValue(storyIndex, elemIndex)))
            elemIndex += 1
    storyIndex += 1

acc.SetPropertyValuesOfElements(elemPropertyValues)

newValues = acc.GetPropertyValuesOfElements(elements, [propertyId])
elemAndValuePairs = [(elements[i].elementId.guid, v.propertyValue.value) for i in range(len(newValues)) for v in newValues[i].propertyValues]
for elemAndValuePair in sorted(elemAndValuePairs, key=lambda p: p[1]):
    print(elemAndValuePair)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can this script used for change column ID?&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 10:17:59 GMT</pubDate>
    <dc:creator>GoranA</dc:creator>
    <dc:date>2024-09-26T10:17:59Z</dc:date>
    <item>
      <title>Python script for column numbering</title>
      <link>https://community.graphisoft.com/t5/Archicad-Python-API/Python-script-for-column-numbering/m-p/579483#M946</link>
      <description>&lt;P&gt;Is it possible to use a python script to set the ID of the columns, so that all columns of the same dimensions have a common ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have edited zone script and that's working, but every column have unique ID, I need unique ID for column with same dimensions (width, hight, length).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from archicad import ACConnection
from typing import List, Tuple, Iterable
from itertools import cycle

conn = ACConnection.connect()
assert conn

acc = conn.commands
act = conn.types
acu = conn.utilities

propertyId = acu.GetBuiltInPropertyId('General_ElementID')

propertyValueStringPrefix = 'POS S'
elements = acc.GetElementsByType('Column')

ROW_GROUPING_LIMIT = 0.25
STORY_GROUPING_LIMIT = 1

def GeneratePropertyValueString(storyIndex: int, elemIndex: int) -&amp;gt; str:
    return f"{propertyValueStringPrefix}{storyIndex:1d}{elemIndex:02d}"

def generatePropertyValue(storyIndex: int, elemIndex: int) -&amp;gt; act.NormalStringPropertyValue:
    return act.NormalStringPropertyValue(GeneratePropertyValueString(storyIndex, elemIndex))

def createClusters(positions: Iterable[float], limit: float) -&amp;gt; List[Tuple[float, float]]:
    positions = sorted(positions)
    if len(positions) == 0:
        return []
    clusters = []
    posIter = iter(positions)
    firstPos = lastPos = next(posIter)

    for pos in posIter:
        if pos - lastPos &amp;lt;= limit:
            lastPos = pos
        else:
            clusters.append((firstPos, lastPos))
            firstPos = lastPos = pos
    clusters.append((firstPos, lastPos))
    return clusters

boundingBoxes = acc.Get3DBoundingBoxes(elements)
elementBoundingBoxes = list(zip(elements, boundingBoxes))
zClusters = createClusters((bb.boundingBox3D.zMin for bb in boundingBoxes), STORY_GROUPING_LIMIT)

storyIndex = 0
elemPropertyValues = []
for (zMin, zMax) in zClusters:
    elemIndex = 1
    elemsOnStory = [e for e in elementBoundingBoxes if zMin &amp;lt;= e[1].boundingBox3D.zMin &amp;lt;= zMax]
    yClusters = createClusters((e[1].boundingBox3D.yMin for e in elemsOnStory), ROW_GROUPING_LIMIT)

    for ((yMin, yMax), reverseOrder) in zip(yClusters, cycle([False, True])):
        elemsInRow = [e for e in elemsOnStory
                        if yMin &amp;lt;= e[1].boundingBox3D.yMin &amp;lt;= yMax]

        for (elem, bb) in sorted(elemsInRow, key=lambda e: e[1].boundingBox3D.xMin, reverse=reverseOrder):
            elemPropertyValues.append(act.ElementPropertyValue(
                elem.elementId, propertyId, generatePropertyValue(storyIndex, elemIndex)))
            elemIndex += 1
    storyIndex += 1

acc.SetPropertyValuesOfElements(elemPropertyValues)

newValues = acc.GetPropertyValuesOfElements(elements, [propertyId])
elemAndValuePairs = [(elements[i].elementId.guid, v.propertyValue.value) for i in range(len(newValues)) for v in newValues[i].propertyValues]
for elemAndValuePair in sorted(elemAndValuePairs, key=lambda p: p[1]):
    print(elemAndValuePair)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can this script used for change column ID?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 10:17:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-Python-API/Python-script-for-column-numbering/m-p/579483#M946</guid>
      <dc:creator>GoranA</dc:creator>
      <dc:date>2024-09-26T10:17:59Z</dc:date>
    </item>
  </channel>
</rss>

