We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Archicad Python API
About automating tasks in Archicad using the Python API.

Reindex multiple attributes

Ahmed_K
Advisor

hello !

Is there a way to reindex a bunch of attributes in a single click using python ? 

reindexing 1 by 1 a list of 300 surfaces or 100 BM is a pain, and this is an important step to organise the template before starting production.

AMD Ryzen 9 3900X, 32 GB RAM, RTX 3080 10 GB
Archicad 27
Windows 11 professional
https://www.behance.net/Nuance-Architects
8 REPLIES 8
Karl Ottenstein
Moderator

Could you describe how you would like them re-indexed so that a Python person can give a better response?   For it to be one click, I assume you want your 300 surfaces or BMs all moved en masse to a new number range?  If so, no need for Python, this can be easy with Attribute Manager.  So, please clarify the goal 🙂

 

One of the forum moderators
AC 28 USA and earlier   •   macOS Sonoma 14.7.1, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
scottjm
Advisor

I suspect a custom Python API wrapper would be needed to execute the relevant API command, so it's likely more of a API coding exercise. ☹️  Any API guru's around?

The current Python addon commands are very limited in functionality.  

 

That said, I have recently messed around with exporting the attributes to XML and then manually editing the index numbers there and then overwriting the attributes with the modified XML file.

However elements or associated attributes will not have their attribute index number updated based on your modifications, so you are likely to get a lot of incorrect attributes allocated or MISSING attributes.

It works pretty well if you are restructuring your template, but not practical on a live project.

scottjm_0-1655011506647.png

The need for a bulk reindexing functions has been requested ever since they introduced the reindexing function, but suspect it's not high priority on the roadmap.

Scott J. Moore | Fulton Trotter Architects | BIM Manager, Associate, Architect
Since AC13 | Current versions AC23.7000 & AC26.5002 | BIMCloud Basic | Python, GDL, VBA, PHP, SQL, CSS
Certified Graphisoft BIM Manger (2022)
Win 10, i9-9900K, 32GB, Quadro P2200, 500GB NVMe

Editing attributes file using xml editor is a good idea, BUT, afaik, Archicad xml files are mapped in special way that can' be easily saved , so that's why all changes you made on the file were unavailable,  i played with xml classification file, and i had the same result, a gile that didn't work correctly 

AMD Ryzen 9 3900X, 32 GB RAM, RTX 3080 10 GB
Archicad 27
Windows 11 professional
https://www.behance.net/Nuance-Architects

I have a template, i delted a lot of attributes renamed some o them, so i have a lot of missing indexes in between , and that may pollute my template in the future,

How to reindex : 

Sort the attributes by name, reindex all starting from 1, to fill all the skipped indexes of deleted attributes, 

I want to have a serie of 300 surfaces indexed from 1 to 300, so when i manage my attributes in multiple files i can detect attributes created by other users (their index shoud be above 300 ) 

AMD Ryzen 9 3900X, 32 GB RAM, RTX 3080 10 GB
Archicad 27
Windows 11 professional
https://www.behance.net/Nuance-Architects

Or, if possible, reindexing by groups, 

* sort by name,

*select 23 brick surfaces total of brick surfaces that i have

*index starting from 1 indexes are from 1 to 23

*select concrete surfaces

*reindex starting from 50, i keep a place for new brick surfaces to be filled in 

 

AMD Ryzen 9 3900X, 32 GB RAM, RTX 3080 10 GB
Archicad 27
Windows 11 professional
https://www.behance.net/Nuance-Architects
poco2013
Mentor

The present Python API can not change Attribute indexes. The C++ API does have that capability via the "ACAPI_Attribute_Modify function. That said, it is possible to create a Add On interface in Python to manipulate Attributes via the Command Handler Function. However, one would have to program both sides - C++API and Python Script. For a one time operation, I doubt if it would be worth it?

Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Ahmed_K
Advisor

Hi again ! 

So, i managed to organize my attributes in a different way, 

the secret is " Don't try to be perfect " 

sorting atributes by name and then idexing by groups  is a bad idea for me, beacause : 

* if bricks are from 1 to 35, concrete from 50 to 80 for exemple, there is a risk that some attributes from other files that have index between 36 and 49 that can be merged and i can't notice it, 

i realised that indexes are used by archcad to identify attributes, so reindexing each time i add new attributes will shift attributes, then, Archicad will loose tracking of attributes, 

 

i kept it simple, in my template file, i did the folowing,

* sorting by index 

* reindexing the last items until i get a full indexed list starting from 1 to the last attribute without gaps, 

* from now on, i exchange attributes within files using indexes.

AMD Ryzen 9 3900X, 32 GB RAM, RTX 3080 10 GB
Archicad 27
Windows 11 professional
https://www.behance.net/Nuance-Architects
Barry Kelly
Moderator

If you have a lot of attributes to re-index at one time, you do not have to use the re-index option.

Simply 'Append by Name' to the right hand side.

This will re-index with all starting at "1".

You can append in groups if you want to try to keep all bricks together, paint together, etc.

If you do that I would leave gaps so you can create new bricks or what ever  in the future.

 

To leave gaps, duplicate the last attribute (highest number) on the right hand side until you get to an index number one before you want to start from again.

Then carry on 'Append by Name' from the left hand side.

Repeat until you get through your list.

 

I always duplicate the last attribute to increase the last number (delete duplicates).

This gives you a gap where you can add new attributes if you need to.

You can't re-index on the right hand side, so you have to duplicate and delete.

Or you can wait until you overwrite them back and then re-index the last attribute to a higher number.

 

The list on the right should have all the same names but with newly arranged index numbers.

Now 'Overwrite by Index Number' from the right to the left.

Your template should now have the same attributes with the amended numbers.

 

Personally I would not re-index all of you template attributes.

As you have discovered, this will just cause pain when you merge or copy & paste from other files.

I would just set the last attribute of each type to a higher number, leaving you space to create new attributes in your template - you create them and re-index them so their number is less than the highest number.

 

 

Any user creating a new attribute in a job file (based on your template), the index number will be higher than the highest number you have created.

You now have full control of the template attributes.

You can now overwrite your template attributes into any job (based on your template) "By Index Number" and know that your template attributes will update and user created attributes will not be affected.

 

Barry.

 

 

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11