The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Discussions about managing ARCHICAD in architectural practices (Project Setup, Templates, Attributes, Migration, Compatibility with Previous Versions, Preferences/Work Environment, User/Project/Application Administration/Management etc.)

Moderators: Barry Kelly, Karl Ottenstein, LaszloNagy, ejrolon, gkmethy

#281811
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 :
  1. 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).
  2. 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.
  3. Save this file as a CSV file. You then need to open it and replace the column separator (";" or ",") by a simple space.
  4. Edit the paths in the python script so that it can find the files on your computer.
  5. Launch the script ant let it do its magic.
  6. Using the LP_​XMLConverter, transform the patched XML files back to GSM files and then pack them back to an LCF.
  7. 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.
(1.16 KiB) Downloaded 35 times
(1.39 KiB) Downloaded 38 times
#281853
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.
(1.23 KiB) Downloaded 52 times
Cheers!
Last edited by Johan Cosandey on Wed May 16, 2018 10:40 am, edited 1 time in total.
#282549
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:
Code: Select all/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):
Code: Select all(...) ('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!
#282550
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!:)
#282791
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.