The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Everything about GDL - Doors/Windows/Objects/Stairs etc. (Example: I created an object that prints an error message in 3D all the time, please help!)

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, gkmethy, Gergely Feher

User avatar
By fuzzytnth3
#11324
Hi all

I'm trying to write a script for an object that will display random/different people in 2d for elevation drawings. Problem is that the random numbers that ArchiCAD generates are generally the same and not very random!

Is there some way I can force ArchiCAD to generate better random numbers?

I remember writing a programme for my Psion that used random numbers and the best way it did it was getting the time in seconds and multiply that with a "random" number and then get the interger of that result. This was due to the Psion generating somewhat limited random numbers.

Below is the script which calls up a Fragment based on the random number.

10:
Randper= INT (RND (15))
fill bft
pen bpn
fragment2 Randper,1
RETURN
User avatar
By Matthew Lohden
#11326
Random numbers in ArchiCAD are (AFAIK) only generated once, i.e. when an object is first placed. This avoids strangely animated trees in flythroughs that rebuild the model for each frame.

You can, as you suggest, come up with your own random number code or you could delete and replace your library part for each random iteration.

The only thing is, people don't arrange themselves randomly, you are probably in for some goofy results. Oh, I get it (I think) it's not random arrangements you are looking for just random characters?
User avatar
By fuzzytnth3
#11328
Matthew Lohden wrote: Oh, I get it (I think) it's not random arrangements you are looking for just random characters?
Yep that's right. The idea is each time you insert the object into the drawing you get a different person displayed.

Basically I'm lazy and hate making decisions :D I don't want to have to keep selecting a different person myself I want the object to do it for me

So I think from what you saying that I will need to find away to script the random number so it's more random than what ArchiCAD is coming up with.
User avatar
By Matthew Lohden
#11337
There is also the question of what you mean by random. True randomness does not typically produce an even distribution. It is just as likely that flipping a coin will get you twenty heads in a row as it will an alternation between heads and tails or any other specific result. What you may be looking for is to introduce a small randomness into an otherwise sequential order.
User avatar
By Joachim Suehlo
#11342
Hi,
I have a problem similar to the Subject:

In an object the random calculation seems to be taken twice.
The first for the 3D-Script and the second for the PROJECT2 command in the 2D-Script.
How can this be?
See the pictures below: the colored is a snapshot of the 3D-window,
the non colored is a snapshot of the 2D-window where the object is shown with a PROJECT2-coomand.
(The object shows a brick girder from below; the place of the short bricks is calculated by random)
Attachments
zufall.gif
zufall.gif (5.68 KiB) Viewed 11275 times
User avatar
By fuzzytnth3
#11348
RND does let you set a limit to the range that the RND command will generate.

So in my example it should generate a number greater than 0 but not greater than 12. 12 being the number of fragments I have drawn diffeerent people on. Sadly it just keeps producing the number

I tried using the REQUEST command to find out the time in seconds but have discovered that the REQUEST command produces a text string even although it looks like numbers :cry:
User avatar
By fuzzytnth3
#11349
Joachim Suehlo wrote:Hi,
I have a problem similar to the Subject:

In an object the random calculation seems to be taken twice.
The first for the 3D-Script and the second for the PROJECT2 command in the 2D-Script.
How can this be?
See the pictures below: the colored is a snapshot of the 3D-window,
the non colored is a snapshot of the 2D-window where the object is shown with a PROJECT2-coomand.
(The object shows a brick girder from below; the place of the short bricks is calculated by random)
Do you have the RND function in the Master script? If it is in both the 3d and 2d scripts then it should give a different result each time.

Least you are getting more "randomness" than me :D
User avatar
By Matthew Lohden
#11353
I just tried the RND function and it seems to be working as expected:

Define style text_style `Arial`, 3, 1, 0
Style text_style

FOR i = 1 TO 12
Text2 0, 0, INT(RND(12))
add2 0, -0.006*GLOB_SCALE
NEXT i


This produced the attached...

A fairly typical random sequence between 0 and 12.
Attachments
RND example.jpg
RND example.jpg (14.64 KiB) Viewed 11258 times
User avatar
By fuzzytnth3
#11361
Thanks for trying that. I took your script and tried it as an object and what I found was that it does generate random numbers but if you insert the object again it produces exactly the same numbers.

What I did find was that when you close and open the drawing again all the numbers change but all the instances of the object still display the same numbers.

So to get the random People in my object to work I would have to insert one instance of the object but have a number of random People appear like your script and I suppose I could also place each Person in a random position similar to Joachim's object. Sounds like this would be an even easier way put some People in my drawing :D
User avatar
By Oleg
#11362
fuzzytnth3 wrote:Thanks for trying that. I took your script and tried it as an object and what I found was that it does generate random numbers but if you insert the object again it produces exactly the same numbers.
I think, this is some of GDL engine optimization effect.
Try this trick to avoid it.
Instead RND(12) type RND(12 + GLOB_INTID*0 )

Oleg