Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Problem reading from Array variable

Anonymous
Not applicable
I am working on creating an object that will read in an xml file and allow the user to place a checklist next to the layout of what needs to be checked for the drawing. It is still pretty rough, but the framework is there. The file is read in. My problem is in actually place the text in the 2D script. In the Parameter Script, I am using the command
VALUES "displayCategories" categoryTitles
where categoryTitles is an array variable that holds text data. This command works, and I can get a pull down list of the categories. However in the 2D script, when using the code
TEXT2 0, 0, categoryTitles[1]
nothing is displayed. I am attaching the object and hoping someone might be able to figure out what I am overlooking.
8 REPLIES 8
Anonymous
Not applicable
Probably right. Now that I think of it, I didn't use the PARAMETER command to store the values. Thanks.
Anonymous
Not applicable
Actually, I can't get the values to stick by using the PARAMETERS command. I have tried to move the reading of the data out of the Parameter Script and into the Master Script, but this didn't work. Using the PARAMETER command doesn't seem to set the dynamic array value either.
Anonymous
Not applicable
Is the array a user parameter or an internally defined parameter array?
The VALUES statement only applies to the former.

You've probably noticed that my previous post disappeared. I pulled it on second thought after a closer look at your initial post.

You may also be suffering an execution order problem. The assignment may not be happening in time to get the display to update. Sometimes this will change by opening the settings or changing a parameter to force a recalculation.

Perhaps if you post a bigger chunk of code we could help better.
Anonymous
Not applicable
The values statement is populating a user parameter that reads from an internally defined array that is populated from the external xml file. I have posted the entire object along with the xml file.

It is tough to post a larger chunk of code, since the majority of the object is just parsing the xml file. Here is the logic. The xml file has a top level node of document. The document is made up of pages. Each page has 1 or more categories. Each category has 1 or more item. And each item may or may not have subitems. I have opened the file and read in all the information. It is being stored in dynamic array that are internal. This is all done within the parameter script. I have created user parameters that, using the VALUES command, read the dynamic arrays and populate the user parameters. I was using this as a way to check my code and make sure the object was functioning as it should as the info is being read. So to me it looked like everything was fine, but when I started to script out the 2D of actually redrawing the xml document in ArchiCAD, I couldn't retrieve any information from the arrays (which appear to be working because they populate pulldowns of user parameters).

I am perplexed by this. It looks like it works, but yet I can only acces the dynamic arrays through the parameter script and not the 2D. I must be overlooking something basic.

Also, it would be easy enough to hard code in all the info, but the xml file will be an evolving document updated by the users, so if I can show them how to tag a word document with the proper xml schema it should be a piece of cake for them to run with this document checklist.
Anonymous
Not applicable
It sounds like you know what you are doing. I'm afraid I don't have time to inspect this in more detail (and I don't see the attachment anyway). I know I have had problems with execution order in similar circumstances. This can be a tough one to sort out. I don't recall right now if or how I got it to work.
Ralph Wessel
Mentor
Michael wrote:
In the Parameter Script, I am using the command
VALUES "displayCategories" categoryTitles
where categoryTitles is an array variable that holds text data. This command works, and I can get a pull down list of the categories. However in the 2D script, when using the code
TEXT2 0, 0, categoryTitles[1]
nothing is displayed.
The parameter script only runs in response to a change, e.g. the user edits a parameter, and prior to displaying parameters to the user, e.g. in the UI. It is not run prior to the 2D script.

You could move your XML reading functions into the Master script instead, so they can be shared by all scripts. Then you can call the functions to read the XML file from the 2D script if required (functions in the Master script can be called from any other script because it is always run prior to any other script). To prevent your code simply running into the functions in the Master script, place a label at the end of the Master script and use goto to jump to it (so execution flows normally to the end of the script).

I've attached a modified version of your object that illustrates this (it now displays the category in 2D). If at all possible, I recommend finding a way to avoid reading in the XML every time the 2D script runs. If the XML is dynamically modified outside of the object, then this may not be feasible. I would have a user-activated mechanism that triggers the parameter script to read the XML and store the data in parameters to be used elsewhere. Otherwise your object may significantly slow down 2D redraw.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Ralph wrote:
I would have a user-activated mechanism that triggers the parameter script to read the XML and store the data in parameters to be used elsewhere.
This is excellent advice. By making the execution explicitly user controlled you not only avoid performance problems, you also eliminate concern over whether the list is updating. I have used a similar device to reset some of the default parameters of a complex part.
Anonymous
Not applicable
Thanks for checking it out Ralph. I am going to look at what you did.