GDL
About building parametric objects with GDL.

Label (ASSOCLP_PARVALUE) / Label Position

Ady84a
Booster
Hello everyone,

I have two questions related to Label for objects.
Question 1 :
I have created a Label that reads values of parameters in objects by using request (ASSOCLP_PARVALUE).
it works well, if the parameter inside the object is String or Number.
But when I have an array of parameters (by using DIM and VALUES{2}), I get the value as number but I cannot get the description by using PARVALUE_DESCRIPTION ("parameter").
here is the code:
! "Steckdose_typ" is an array with values and descriptions
rrr = request ("ASSOCLP_PARVALUE", "Steckdose_typ", Steckdose_typ)
AC_MarkerText_5 = PARVALUE_DESCRIPTION ("Steckdose_typ")         ! this didn't work
AC_MarkerText_5 = str ("%.0", Steckdose_typ)       !I got the value as number
Question 2:
When I insert the Label it is created far away from the object. How do I create the Label directly over the object? I am using a simple text command
text2 0.125,0,AC_MarkerText_5
best regards,
7 REPLIES 7
Podolsky
Ace
I've got an answer to your second question. Because label can have a pointer line with arrow - there is a global variable, that describes coordinates of three points of the pointer. If you want, that label would be located exactly where you placed it, you need to shift it. To do so, use this script:
ADD2 LABEL_POSITION[2][1]+LABEL_POSITION[3][1], LABEL_POSITION[3][2]
Ady84a
Booster
@ Podolsky : Thanks a lot, the answer to Question 2 worked out.
Palawat
Advocate
For the first question, you might want to look at the request "ASSOCLP_PARVALUE_WITH_DESCRIPTION".

Since your "Steckdose_typ" is an array, the variable "p_values_and_descriptions" should be too.

!2D Script
dim p_values_and_descriptions[]
n = REQUEST ("ASSOCLP_PARVALUE_WITH_DESCRIPTION", "Steckdose_typ", name_or_index, type, flags, dim1, dim2, p_values_and_descriptions)

for i = 1 to vardim1(p_values_and_descriptions)
	text2 0, i, p_values_and_descriptions
next i
Archicad 26, Windows 10, Corei7 3.4 GHz, 16 GB Ram.
https://www.indigofigs.com
https://www.facebook.com/indigofigs
Podolsky
Ace
Ah, of course, PARVALUE_DESCRIPTION ("parameter") is not working, because it's the wrong command. It simply does not exist in GDL.
The only way to extract a description is how Palawat is showing.
rrr = request ("ASSOCLP_PARVALUE", "Steckdose_typ", Steckdose_typ)

also not working, because it has wrong form. It must look like that:
rrr = REQUEST ("ASSOCLP_PARVALUE", "Steckdose_typ", name_or_index, type, flags, dim1, dim2, Steckdose_typ)
Ady84a
Booster
Thanks to you guys for your support, it worked!
here is the code:

! Step 1: Requesting the values of parameters in objects
!--------------------------------------------------------
number_of_sockets = 1		! Parameter 1 (Integer)
n = request ("ASSOCLP_PARVALUE", "Steckdose_anzahl",name_or_index, type, flags, dim1, dim2, number_of_sockets)

dim p_values_and_descriptions[] 	! Parameter 2 (array)
n = REQUEST ("ASSOCLP_PARVALUE_WITH_DESCRIPTION", "Steckdose_typ", name_or_index, type, flags, dim1, dim2, p_values_and_descriptions)

! Step 2: Inserting the values in textfields
!-------------------------------------------
font_size 	=1.5
font_size_m =font_size/1000*GLOB_SCALE 	! font size in meters
DEFINE STYLE "fontstyle_label" "Candela Book",font_size,4,0
SET STYLE "fontstyle_label"

ADD2 LABEL_POSITION[2][1]+LABEL_POSITION[3][1], LABEL_POSITION[3][2]  	! to move the Text to the origin of the Label
offset_textbox = 0.075			! offset between the text and the object

! Inserting the value of parameter 1 and only the description of parameter 2
for i = 2 to vardim1(p_values_and_descriptions)   	! i=2 to skip the the value of parameter 2 in the array
	text2 offset_textbox,0,str ("%.0", number_of_sockets) + "X " + p_values_and_descriptions
next i

! Inserting the elevation of the object as text
text2 offset_textbox,-(font_size_m+0.005),"H:" + STR(GLOB_ELEVATION,5,2)+ "m"

! a fill to make the selection of the Label easier
width_textbox = 0.5
add2 offset_textbox,font_size_m-0.02

fill "Nur Hintergrund-Stift"
poly2_b{5} 5,2,1,3,195,0,
 0,0,1,0,0,1,0,
 0,0,33,
 0,-font_size_m*3,33,
 width_textbox,-font_size_m*3,33,
 width_textbox,0,33,
 0,0,33

 ! drawing a line to the object 
line2 0,0,-0.1,0
Podolsky
Ace
I might recommend to make few small adjustments:

Instead of naming Fill in the script, use better GLOB_FILL_INDEX_SOLID or GLOB_FILL_INDEX_BACKGROUND (works since version 22). It's better, because if by some reason in another file named fill is missed, you will receive an error.

Also, if array p_values_and_description has only two entries, there is no point to use loop FOR - NEXT.
You can just get second entry from array: p_values_and_description[2]
Peter Baksa
Graphisoft
Graphisoft
Hi,
Ah, of course, PARVALUE_DESCRIPTION ("parameter") is not working, because it's the wrong command. It simply does not exist in GDL.
It does exist, you need to specify array indices when using it with an array.
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest