Project data & BIM
About BIM-based management of attributes, schedules, templates, favorites, hotlinks, projects in general, quality assurance, etc.

A small python script to adapt the Archicad library objects to your pen set

Anonymous
Not applicable
Hi everyone,

I just wanted to share a small python script I just made. It lets you scan through XML files and edit every pen color parameters according to a correspondance file.

I did this because we use a custom pen set in our office and I was sick of changing the pen colors of every objects every time just because they are programmed to work specifically for the base pen set (yes, favorites are a great help and we intensively use GOs, but it is not a complete and satisfying answer to this specific problem).

Here's the process :
  • Extract the content of your Archicad LCF and convert the GSM files into XML files using the LP_XMLConverter (How to use the LP_​XMLConverter tool).
  • Create a spreadsheet with 2 columns. The first one represents the pen number value to be replaced (the base pen set value) and the second one the new value (the corresponding value of you custom pen set). The first column will simply be a listing of numbers from 1 to 255 (you don't need to replace the -1 and 0). The script will then replace every pen color parameter it finds on the left column by the corresponding number to its right.
  • Save this file as a CSV file. You then need to open it and replace the column separator (";" or ",") by a simple space.
  • Edit the paths in the python script so that it can find the files on your computer.
  • Launch the script ant let it do its magic.
  • Using the LP_​XMLConverter, transform the patched XML files back to GSM files and then pack them back to an LCF.
  • You can now safely archive the old LCF file and replace it by your patched one.
I successfully used this technique and I can tell you it was welcomed with a lot of enthusiasm by my colleagues who were used to always edit the pen colors of every objects, but with the new stair and railing tool and their huge number of graphical options, it had become a real pain in the a##.

I can give a more thorough explanation if needed.
I only have a very small experience in python scripting so if someone finds a way to optimise or make this script better in any way, please let me know. If you want to make it better by yourself, feel free but share it with us please.

Hope it will help some of you.
Let me know what you think!

Johan

P.S. To run the python script, you can use pyCHARM, it's free and open source (but not the only solution). You will need to run it with python 3.6 and it needs the lmxml library to work. Once again, I can help you if needed.
9 REPLIES 9
Aaron Bourgoin
Virtuoso
Wow. I think. Will have to digest this, but sounds like a really valuable tool in the arsenal. Thank you for your work.
Think Like a Spec Writer
AC4.55 through 27 / USA AC27-6000 USA
Rhino 8 Mac
MacOS 14.6.1
Anonymous
Not applicable
Hi,

I already made a few modifications to the script. It is now more stable and more versatile.
You can change pen numbers, line types and fill colors.

I also added a small explanation on how to use it.
Cheers!
Anonymous
Not applicable
nice job!
Anonymous
Not applicable
Nice. I didn't know that LP_XMLConverter tool existed. Thanks. Also, the approach is nice. We actually skipped changing original pen values since graphical overrides were introduced, because it was such pain .
furtonb
Advisor
Johan wrote:
Hi,

I already made a few modifications to the script. It is now more stable and more versatile.
You can change pen numbers, line types and fill colors.

I also added a small explanation on how to use it.

Cheers!
Hi Johan,

Thank you for your work, it could save tremendous amount of time!
I'm having problems though: although the script runs OK, the .xml files seem to remain intact for me, after reopening, all PenColor values are as they were.

At the moment I'm stuck with troubleshooting, do you have any idea what could be the problem?

I have tried both versions of your script, the first one doesn't run, the following error pops:
/Users/furtonb/Desktop/AC21 xml/Object Library 21/1. BASIC LIBRARY 21/1.1 Furnishing 21/Chairs 21/Lounge Chair 21.xml
Traceback (most recent call last):
  File "/Users/furtonb/Downloads/PenNumbersReplacement.py", line 34, in <module>
    index = oldValue.index(valeur.text)
ValueError: '4' is not in list
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/furtonb/Downloads/PenNumbersReplacement.py"]
[dir: /Users/furtonb/Downloads]
[path: /Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
The v2 version runs OK (example line):

(...)
('File modified :', '/Users/furtonb/Desktop/AC21 xml/Object Library 21/1. BASIC LIBRARY 21/1.1 Furnishing 21/Chairs 21/Bar Stool 21.xml')
[Finished in 0.2s]
[Process finished with exit code 0]
The only thing I did is replacing the xml folder path and removing the linetype and fill colour sections from v2.

I did the .csv file as you said, only a space is limiting the values.
I hope you have something in mind!
odv.hu | actively using: AC25-27 INT | Rhino6-8 | macOS @ apple silicon / win10 x64
furtonb
Advisor
Ok, I've found where the error is: my .csv file.

When using your PARAM.csv from the first version, the PenColor values cycle through as they should.

I used Excel to create my spreadhseet, then to export the .csv (TextEdit to replace the ";" to " ").
Maybe it was the encoding.
Numbers works fine.

Thank you again for this script, you just saved a couple of hours for me! I don't know where you are located, but consider yourself invited for a few beers!:)
odv.hu | actively using: AC25-27 INT | Rhino6-8 | macOS @ apple silicon / win10 x64
Anonymous
Not applicable
Hi Furton,

I'm glad this script is helping someone, and that you found your solution.
I'm located in Switzerland by the way!

Johan
Anonymous
Not applicable
Yeah!!!: DDD Totally what I need. uncountable files and different pensets everywhere.... Does the same work for other xml libraries as (rooms, tables ?) Actually I try to get an xml to work (Imput and otuput) in an object but I can't manage it at all. I am not sure if I can manage your script but I like the idea there is a solution.
sl
Participant

hi! great idea! I‘m also interested in adapting the standard AC library, but simply with a text editor that can search and replace in multiple text files in the HSF format. this works quite well, my only concern is how to migrate a running project that is using a customized library. will it work to customize, for example, the AC22 library, begin a project there, customize the AC24 library and migrate the project from custom library 22 to custom library 24?

does anybody have experiences here?