Author Topic: How to make script find a brick by its name  (Read 942 times)


Try invoking the dump() member function of a brick group and look at the output.

I'm assuming that by name, you mean the name you can set with the wrench

_<brick name>

So if the brick's name is 'test'
_test.delete();
would delete it

I'm assuming that by name, you mean the name you can set with the wrench

_<brick name>

So if the brick's name is 'test'
_test.delete();
would delete it

The proper way is looking at the variables on a brick group in order to see all bricks named that (and also to see it for a specific person).

This will work.

This is the easy way.
Code: [Select]
function findBrickByName(%name)
{
   eval("%currentbrick = \"_\" @ %name;");
   if(isObject(%currentBrick) && %currentBrick.getClassName() $= "fxDTSBrick")
   {
      return %currentbrick.getID();
   }
   else
   {
      return 0;
   }
}
Keep in mind that this only looks for single named bricks so I'd appreciate it if somebody did it with Port's way.
« Last Edit: May 28, 2012, 12:46:48 PM by Axolotl »

This will work.

This is the easy way.
Code: [Select]
function findBrickByName(%name)
{
   eval("%currentbrick = \"_\" @ %name;");
   if(isObject(%currentBrick) && %currentBrick.getClassName() $= "fxDTSBrick")
   {
      return %currentbrick.getID();
   }
   else
   {
      return 0;
   }
}
Keep in mind that this only looks for single named bricks so I'd appreciate it if somebody did it with Port's way.
Eval is not necessary there nor do you ever want to use it where you don't have to. If you're using this code, switch it to this.

Code: [Select]
function findBrickByName(%name)
{
   %brick = ("_" @ %name).getID();
   if(isObject(%brick) && %brick.getClassName() $= "fxDTSBrick")
      return %brick;
   else
      return 0;
}
Exact same thing without eval. It will return the most recently placed brick named %name.

The proper way is looking at the variables on a brick group in order to see all bricks named that (and also to see it for a specific person).
I could see looping through every brick becoming a problem after a few thousand bricks.

I could see looping through every brick becoming a problem after a few thousand bricks.

No, there are variables in the brickgroup that list the named bricks.

No, there are variables in the brickgroup that list the named bricks.
|
how would you be able to find that out

|
how would you be able to find that out

Try invoking the dump() member function of a brick group and look at the output.