GDL
About building parametric objects with GDL.
SOLVED!

Possible to use element property value in a label?

Mats_Knutsson
Advisor

Hi,

I'd like to create a label with a 2D geometry, say a circle that changes color according to the value (text content) of a certain property. Is this possible? Let's say I've created a property "LENNART" available for doors. The property is an option set with values A, B and C and the label should change colour depending on the property value... A=red, B=green etc.LENNART.png

 

/Mats

 

AC 25 SWE Full

HP Zbook Fury 15,6 G8. 32 GB RAM. Nvidia RTX A3000.
11 REPLIES 11

Pm me I have a label that already reads properties. 

Palawat
Advocate

This is not a tutorial but it should help.

First, you need a parameter (a string type) to act as an "id" (as in GDL Ref. Guide for PROPERTY_VALUE_OF_PARENT). Let's call it "criteriaProp".

 

createParam.jpg

 *The "gs_ui_current_page" is there for the UI script to work. If you don't have it already, please create it too.

 

UI script;

 

 

ui_dialog "Test Label"

dim pageTitle[1]
pageTitle[1] = "Custom Settings"

dim pageIcon[1]
pageIcon[1] = ""

dim pageID[1]
pageID[1] = 1

ui_current_page gs_ui_current_page
ui_page gs_ui_current_page


! Page 1 --------------------------------------------------------------------------------
ui_page 1, -1, pageTitle[1], pageIcon[1]

dim parentProperties[]
n = request ("Properties_Of_Parent", "", parentProperties)
n = request ("Property_Name", criteriaProp, typeName, groupName, propertyName)

ui_custom_popup_infield	"criteriaProp", 10, 20, 200, 20,
						1, 3, 2, propertyName,
						"None", "", "", "None",
						parentProperties

 

 

Here, we populate the requested "parentProperties" into "criteriaProp" so you can select which property to use as a criteria.

The requested "propertyName" is there so the UI show the title instead of "id" after a property is selected. (Within the ui_custom_popup_infield .... , try and replace it with "" and see what happen after selecting the property in UI).

The "None", ... is there in case there is no supported property, just in case...really. You can also set the parameter to "None" as default if you want to.

ui.jpg

 

2D script;

 

 

! Getting value ---------------------------------------------
taggedValue = ""

dim propertyValues[][]
dim1 = 0
dim2 = 0
type = 1

n = request ("Property_Value_Of_Parent", criteriaProp, type, dim1, dim2, propertyValues)

if n & (glob_elem_type = 3 | glob_elem_type = 4) then	! Label works on D/W only.

	if type = 4 then	! String
		taggedValue = propertyValues[1][1]
	else
		text2 0, 0, "The criteria selected is not supported"
	endif
else
	text2 0, 0, "The Element/Property selected is not supported."
endif

! Start doing your thing ------------------------------------

text2 0, 0, taggedValue		! Just to check the value. Comment this out or delete it later.

if taggedValue <> "" then
	if taggedValue = "A" then
		! set your background fill/pen
	endif
	if taggedValue = "B" then
		! set your background fill/pen
	endif

	!.......

endif

 

 

Now we request PROPERTY_VALUE_OF_PARENT which return the value via propertyValues (2 dimensional array). In this case, we know for sure that dim1 = 0, dim2 = 0 since we create the property "LENNART" ourselves. So there's no need to fuzzing around dim1 and dim2. The value we want is propertyValues[1][1]. Just assign it to a variable "taggedValue" then manage from there. (Note: You don't really need the "taggedValue", but it is a lot nicer than using propertyValues[1][1] every time.)

You can also disregard the glob_elem_type thing if you don't want to limit the label to be used only with D/W.

 

Have fun scripting 🙂

 

 

Archicad 26, Windows 10, Corei7 3.4 GHz, 16 GB Ram.
https://www.indigofigs.com
https://www.facebook.com/indigofigs