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

Is there a way to suppress warning messages in a GDL script?

Eric Bobrow
Enthusiast
I am creating an object that will show samples of all the materials defined in a project.

To do this, I plan to use a simple loop statement that increments an index value, then tests to see if a material exists for that index using the statement:
n=REQUEST ("Name_of_material", index, name)
I tried this, and can see that variable n is 0 when there is no material with that index, while it is 1 when a material exists.

However, when the index is not associated with a material, a warning dialog comes up stating "Material not found at line 2 in 3D script of..."

Is there a way to suppress this warning message? I know that a user can turn off error messages in general, and then will only get a single message stating "there were errors", but that's not acceptable in this case.

Alternatively, is there a way to automatically fill an array with a list of index values for materials, similar to the special request available for a list of font names?
15 REPLIES 15
Anonymous
Not applicable
Hello,

I do not know if this is usable, but this code makes a sorted value list of the material names - beginning with the given character. The looping would be better with do...while or similar, but just making a "quick one" this time.

You need to have a string type parameter named "materials" in addition to the value or master script code below.

(The array sorting code is borrowed from Frank Beister or Joachim Suehlo years ago, thanks to those gurus).


!--define arrays
dim s[], t[]

!--loop thru materials
for xx=1 to 255
	dummy= REQUEST ("Name_of_material", xx, name)
	if dummy & (strsub(materials,1,1) = strsub(name,1,1)) then
		n= n+1
		t= name
	endif
next xx


!--array sorting
for i=1 to vardim1(t)
	s= ""
next i

for i=1 to vardim1(t)
	p=i
	for j=1 to i-1
		if s>t then
			for k=i to j+1 step -1
				s=s[k-1]
			next k
			p=j : j=vardim1(s)
		endif 
	next j
	s

=t next i !--deliver the value list values "materials" s, custom

Anonymous
Not applicable
Hello,

A little modification; the same code with a word search function.

!--define arrays
dim s[], t[]

!--loop thru materials
for xx=1 to 255
	dummy= REQUEST ("Name_of_material", xx, name)
	if dummy & strstr(name, materials) then
		n= n+1
		t= name
	endif
next xx


!--array sorting
for i=1 to vardim1(t)
	s= ""
next i

for i=1 to vardim1(t)
	p=i
	for j=1 to i-1
		if s>t then
			for k=i to j+1 step -1
				s=s[k-1]
			next k
			p=j : j=vardim1(s)
		endif 
	next j
	s

=t next i !--deliver the value list values "materials" s, custom


Hope this helps.

Regards, Juha
search.png
Eric Bobrow
Enthusiast
Juha -

Thanks for the extensive code samples. I had already worked out a way to sort the materials by name, so this was not the main question. I do like how you create the arrays and then make a value list for a materials popup.

My main question is how to avoid getting an error message during execution of the script when the index does not have a defined material. This happens for me when the statement:
n=REQUEST ("Name_of_material", index, name)
is executed, and you have a similar statement in your script as you loop through to collect the material names. Do you get error messages when your script is executed?

Eric
Anonymous
Not applicable
Hello Eric,

Now I understand - yes the looping gives an error. I checked other possibilities and seems that REQUEST{2} behaves better.

I made an extra checking here.



!--define arrays
dim s[], t[]

!--loop thru materials
for xx=1 to 255
	test= REQUEST{2}("Material_info", xx, "gs_mat_surface_rgb", r, g, b)
	if test then
		dummy= REQUEST("Name_of_material", xx, name)
		if strsub(materials,1,1) = strsub(name,1,1) then
			n= n+1
			t= name
		endif
	endif
next xx


!--array sorting
for i=1 to vardim1(t)
	s= ""		!--for numbers-->0 | for strings-->""
next i

for i=1 to vardim1(t)
	p=i
	for j=1 to i-1
		if s>t then
			for k=i to j+1 step -1
				s=s[k-1]
			next k
			p=j : j=vardim1(s)
		endif 
	next j
	s

=t next i !--deliver the value list values "materials" s, custom


Hope this helps.

Best Regards, Juha
Eric Bobrow
Enthusiast
Thank you!
The REQUEST{2} test works perfectly, allowing one to test whether an index number is valid before requesting the material name for that index.

I greatly appreciate your assistance.

Now, I have one other question...

I would like to show the material texture directly on plan, but am having problems with the script syntax, and the GDL manual documentation isn't very helpful.

My script currently is creating an array of little square slabs that each have a different material, and they show beautifully in 3D. In 2D, I'm using the following statement to show the squares on plan:
project2{2} 3,270,3+1024
This is crude, but gives a quick preview of the squares with a simple color based on the material, but it does not use the actual texture files of the materials.

I'd like to create temporary Symbol Fill definitions in the 2D script, and then run my loop to draw my little squares in 2D instead of using the Project2 statement. I have coded the following two lines - the first one queries the material texture file name and size, then the second one attempts to create a new Image Fill definition:
n=REQUEST{2} ("Material_info", "07 | Spanish Tile", "gs_mat_texture", file_name, w, h, mask, alpha)
DEFINE IMAGE_FILL "TestFill" file_name, fillTYPES_MASK 2, 85, 255, 136, 255, 34, 255, 136, 255, h, w, 0, 0
However, when I use the Check Script button, I get a syntax error for the second line that says "String type expression required at line 7..." I don't know what my error is - can you try this and let me know what I'm doing wrong?

Thanks again, in advance, for your help!

Eric
Eric Bobrow
Enthusiast
Juha -
Just a quick note - I first posted a short reply thanking you for your help. Then I went back and edited my post to add another question.
Since I'm not sure whether you'd get another notification about the edited post, I'm adding this extra "reply" to make sure you know that I have another question that I hope you can help me with!
Eric
ztaskai
Graphisoft Alumni
Graphisoft Alumni
Eric wrote:
... when I use the Check Script button [with DEFINE IMAGE_FILL], I get a syntax error for the second line that says "String type expression required at line 7..." I don't know what my error is - can you try this and let me know what I'm doing wrong?
Hi Eric,

I'm afraid you found an annoying bug in the DEFINE IMAGE_FILL command. AC doesn't accept a string type variable as the file name, only a constant string expression in quotes. I can't think of any workaround. I entered this as a bug in GDL and I think the fix can get into a v14 hotfix.

I'm sorry you have to wait for the solution.

Best regards,
Zsolt Táskai
ArchiCAD Development - GDL Team
AC13, AC14 and upwards...
Eric Bobrow
Enthusiast
Zsolt -
Wow! Did this bug exist in AC13? Is this the first time this bug has been reported?
I hope we don't have to wait too long for a hotfix...
Thanks for letting me know that it's a bug rather than user error!
Eric
Anonymous
Not applicable
Hello Eric,

This might be worth trying;

- make a new string type parameter "pict" and make it a table with one cell

- put the file_name into that table with "parameters" command before using it

- use a new, just invented command: SET IMAGE_FILL



n=REQUEST{2} ("Material_info", "Testing Material", "gs_mat_texture", file_name, w, h, mask, alpha)
parameters pict[1]= file_name
DEFINE IMAGE_FILL "Testing" pict[1], 255, 255, 255, 255, 255, 255, 255, 255, w, h, 0, 0

set IMAGE_FILL "Testing"
poly2_ 4, 1+2+4+8,
	0, 0, 0,
	a, 0, 0,
	a, b, 0,
	0, b, 0


It works for me, hopefully for you too.

Best Regards; Juha