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

Database output into Parameters

matjashka
Enthusiast
Hi,

The problem I have encountered is how to pull multiple variables from a database AND modify the user-defined Parameters of the receiving object, let's call them param1, param2 and paramN. This should happen automatically without user action, so I figured that Master script would be the place to place it. Normally, I'd do that in Parameter script.

After I have succesfully opened a channel and defined my input fields
INPUT (channel, 0, 0, param1, param2, paramN)
I'm trying to do the following:
parameters param1 = param1, param2 = param2, paramN = paramN
After I modify the source .txt file and reload libraries, "something" happens, namely param1 is successfully updated and the value changed; however, it ends with param1.
Here the manual says
"If the parameter is a value list, the value chosen will be either an existing value, the custom value, or the first value from the value list."
Not sure if this applies to my situation. Do I need to try to modify them one-by one in some sort of a loop? What's the best approach?

Thank you!
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA
2 REPLIES 2
Anonymous
Not applicable
Hi Matt,
sometimes the data types are different
VARTYPE(expression) will identify the variable type
1 for number, 2 for string

I use this to trouble shoot at early stages of coding, plus text2 outputs to make sure the read process works before going to the next stage.

(assuming param1 is a number, param2 is a number, paramN is text)
note, if the input record is only numbers and a single decimal point, it gets turned into a number, if it contains other characters, it changes to text.
using a text file in the loaded library called textfileA.txt
i.e.

! ------------------------------------------
! Open Channel
! ------------------------------------------
ch3 = OPEN ("text", "textfileA.txt","SEPARATOR = '\t', MODE = RO, LIBRARY")

! ------------------------------------------
! Read and Assign Values to Temp Variables
! CHECKINPUT is the number of records retrived
! ------------------------------------------
CHECKINPUT = INPUT (ch3, 0, 0, param_1, param_2, param_N)

! ------------------------------------------
! Check Variables in 2d output
! Can remove this stage after it works
! ------------------------------------------
IF CHECKINPUT > 0 THEN
text2 0,0, param_1
text2 0,1, VARTYPE(param_1)
ENDIF

IF CHECKINPUT > 1 THEN
text2 1,0, param_2
text2 1,1, VARTYPE(param_2)
ENDIF

IF CHECKINPUT > 2 THEN
text2 2,0, param_N
text2 2,1, VARTYPE(param_N)
ENDIF

! ------------------------------------------
! Close Channel
! ------------------------------------------
close ch3

! ------------------------------------------
! Checks Temp Variables are correct type
! and assigns temp variable to Parameters
! ------------------------------------------
if VARTYPE(param_1) = 1 and CHECKINPUT > 0 then !for a number
a = param_1
param1 = param_1
parameters a = param_1
parameters param1 = param_1
endif

if VARTYPE(param_2) = 1 and CHECKINPUT > 1 then !for a number
b = param_2
param2 = param_2
parameters b = param_2
parameters param2 = param_2
endif

if VARTYPE(param_N) = 2 and CHECKINPUT > 2 then !for text
paramN = param_N
parameters paramN = param_N
endif

! ------------------------------------------
! Can remove this stage after it works
! ------------------------------------------

text2 0,2, param1

text2 1,2, param2

text2 2,2, paramN

! ------------------------------------------
! End of Variable assigning
! ------------------------------------------
matjashka
Enthusiast
Thanks much, mate!

Your response helped me fix it. Turns out, I skipped one variable from the list and the script got confused. I used the text2 object to list the variables and they seemed to be interpreted correctly as Numeric vs String. Because I needed to input almost 20 different parameters, I stuffed them in an array and called out later.
NOTE that the script below does NOT check if variable type is Numeric vs String. If that were the case, I'd have to have an additional array to check against.

This is what I placed in the Master script and it's executed in case the object is on the "receiving end" of things (a child type of instance):
_numSettings = 19 !this must correspond with the amount of variables received
dim _recvdSettings[]

_dataSource2 = open("text", settingsFile, "separator='\n', mode=ro, Library")

for r=1 to _numSettings step 1
	_readValues = input(_dataSource2, r, 1, _param)
	_recvdSettings = _param
next r

parameters 	rbegin = _recvdSettings[1],
			rstop = _recvdSettings[2],
			naListing = _recvdSettings[3],
(...)
			col3wd = _recvdSettings[18],
			rowh = _recvdSettings[19]
rbegin = _recvdSettings[1]
rstop = _recvdSettings[2]
naListing = _recvdSettings[3]
(...)
col3wd = _recvdSettings[18]
rowh = _recvdSettings[19]

close _dataSource2
Best regards
Matt Krol [LinkedIn]
BHMS Architects and Planners, Chicago
AC 10 ... 26 USA

Start a new conversation!

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!