Community Forum

LUA script how to take ID of object

Forum Overview >> Scripting

Created16.02.2018 03:40

Bartek Perkowski (Unknown) 16.02.2018 03:40
Hi. I was making simple script to randomly set translation of my object but I wanted to improve it. I was looking for function sth like GetIdOfSelectedObject (or sth familiar) but I couldn't see anything like this.
I would like to include to my script to automatically get ID of selected object.
Greetings Pyrol

Colin Simpkin (Unknown) 16.02.2018 22:42
If you open Giants Editor and select Window - Script Editor there you will find a script called Object Info

Kevin K. (kevink98) 16.02.2018 22:48

If I understand you correctly then is your selected object the id. For example you have select a brush then the value is the Id. So you can use this variable directly for setWorldRotation or so.

But this works not for all. The best way is it when you post your code or explain your plan better (which object,...).

Bartek Perkowski (Unknown) 17.02.2018 04:05
@Colin I have not any scripts only 'dirtutil' and 'editorutils'

@Kevin I'd like to select an object and script should get info about(ID) which object in scenegraph I've selected, so I don't must change it to another every time

this is simple script but isn't working as I want but sill good.
Also I'd like to know how can I save object translation using function getTranslation - I can just take one coordinate (I thought about table but idk how to read every of these 3 values )

-- Author:Mustang
-- Name:TreeCopyArrayRandom
-- Description:
-- Icon:
-- Hide: no

TerrainId = 246;
ObiektId = 116325;
x = -580;
z = -50;
IloscX = 8;
IloscY = 5;
BPW = 0.35;
MinOdstepX = 20;
MaxOdstepX = 25;
MinOdstepZ = 20;
MaxOdstepZ = 25;


for i=1, IloscX do
z1 = z;
odstepX = math.random(MinOdstepX,MaxOdstepX);
offsetZ1 = math.random(5,(MaxOdstepZ));
offsetX1 = math.random(3,15);
x = x + odstepX;
NowyObiekt = clone(ObiektId,true,true,true);
TreeHeight = getTerrainHeightAtWorldPos(TerrainId, x-offsetX1,0,z1-offsetZ1);
for j=1, IloscY do
odstepZ = math.random(MinOdstepZ,MaxOdstepZ);
odstepX = math.random(MinOdstepX,MaxOdstepX);
offsetX1 = math.random(3,9); -- math.random(3,15);
offsetZ1 = math.random(6,9); -- math.random(3,15);
offsetX2 = math.random(3,(odstepX)-1);
offsetZ2 = math.random(3,(odstepZ)-1);
--if(offsetX2 < odstepX-1 and offsetZ2 < odstepZ-1) then
z1 = z1 - odstepZ;
NowyObiekt = clone(ObiektId,true,true,true);
--setTranslation(integer transformId, float x, float y, float z)
TreeHeight = getTerrainHeightAtWorldPos(TerrainId, x+offsetX2,0,z1+offsetZ2);
--offsetX2 = math.random(3,(odstepX));
--offsetZ2 = math.random(3,(odstepZ));

Colin Simpkin (Unknown) 17.02.2018 10:17
Sorry my mistake that script is not part of Giants 7.1 but if you download a copy of Giants 6.0.5 ( its in the script folder of that editor. I transferred all the relevant scripts when I upgraded to 7.1

Bartek Perkowski (Unknown) 17.02.2018 14:21
@Colin Even if I installed 6.0.5 I have not any scripts there, also I checked local folder (my scripts are there) but I've question about how to insert every value using "getTranslation" to table because here I'm ONLY able to get first value
(in C++ I could do like to make these values one string and in loop I would split it into X Y Z)

Colin Simpkin (Unknown) 17.02.2018 15:16
Here is the Object Info script

-- Author:LKXstudios
-- Name:ObjectInfo
-- Description:ObjectInfo v2 - this script writes informations about an object in the scripting window.
-- Icon:iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAA0VJREFUOI1Nk09oXFUchb9735uZvLzpdLTpTJqQpCaQxEaji2AVLSFGCw0kqcZgKY0KrpQignXV4spdBTdFcSN0YbJIZFKKCqWlaFGJDbRpocaJYTpoY5Iy+TOZad6M93efi4j2239ncQ5HDQ8Po5RCa41SCqXUXqXU40AaSLBDEVgJw/DXMAzvh2GItZYwDHH5nxjwTEtLy/Ojo6PHW1tbnzTGAOC6LouLi7cnJyfH8/n8j8AvQAXA6ezsRCkVAw4PDg6eGBsb+2D2N9KZqxt8ebHIxWslFvJl3KifPv5a70taayebzVaAPCBOR0cHYRi+MDQ0dKKvr++NM5+vML9US82ufdTXp6mrqyOwPjeyFb6/XuDNVzqechzHZLPZ+0Bei0i6ubn5UH//i2OnP1vBqU2TTCbJ5f7i7Ds+n7zrk88vk0wmsZE6PvqiQG9v71hjY+MhEUlrEekaGXn12Dc/rBKEu7AWlpcLBEHwXzlBELC6uoa1UKx4XJ5ZZ2DgyDER6XJFpKGpqalr/Mo94vEUy8sFAESEjiMZRCyu6yIiADQ0pJhbEJ49uq9LRBpcEUlubZW4kzPsb7VUKlU2NkuUH5SZ+LgZpRSvn/4T5UQBKJWr3MmFbG8HiEjSNcZoEcEYoVgKWF17gFhQOoZSCs/z0E4NytlZ3IQuxgTsOEa7xpgtx3Fpb4L8RhXcWhzAmgqe5xGPx9ERD+3GALAY2psANMaYLS0iSwsLv88/0RZjq7iB5+/GicbR7o7s+z7a9XCicZxoHPl7m67HouRyd+dFZEmLyK2JiYnMywfr2OOVMMEmkVgcJ1KD7/sopXAiNTiROFLZojG5TV/PI1y4kMmIyC0nlUqV1tfXIqC899/uO3D5Wpbl1Q3c2kf56qrL+UsGY6oUVxeo9wt8eqqL6empr2dmfsqEYXjTSaVSWGvvzc3d0Naiz7w31Lm7pkK5kOP2zetsrszzdHPASN9eTr11gImJ89NTU+MZrfV3gFHd3d1YaykWi16lUjnc1tbef/LkhwM9Pc+1PXQ0Zmd/Xjx37uy3i4vZK7FY7FIikdjWWvNwAOVymWq12mStPQjsB/b86xeAu1rrmWg0+ofv+yQSCbTW/ANpWIUL7TEfpAAAAABJRU5ErkJgggAAAAAAAAAAAAAj/bE9daUKAABI9AoAAAAA4D30CgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
-- source: Yusuke Kamiyamane (

-- object = selection

local objectID = getSelection();
if objectID == 0 then
error("ERROR: A object must be select!", 2);
local name = getName(objectID);
local class = getClassName(objectID);
local parentID = getParent(objectID);
local Tx, Ty, Tz = getTranslation(objectID);
local WTx, WTy, WTz = getWorldTranslation(objectID);
local Rx, Ry, Rz = getRotation(objectID);
local Sx, Sy, Sz = getScale(objectID);
print("------------------ objectInfo of '", name, "' ------------------");
print(string.format("ID: %d", objectID));
print("Name: ", name);
print("Class: ", class);
print(string.format("Parent: %s (ID %d)", getName(parentID), parentID));
print("Translation: X ", Tx, " Y ", Ty, " Z ", Tz);
print("WorldTranslation: X ", WTx, " Y ", WTy, " Z ", WTz);
print("Rotation: X ", Rx, " Y ", Ry, " Z ", Rz);
print("Scale: X ", Sx, " Y ", Sy, " Z ", Sz);
print(string.format("ClipDistance: %d", getClipDistance(objectID)));
print(string.format("ObjectMask: %d", getObjectMask(objectID)));
if class == "Shape" then
print(string.format("Number of materials: %d", getNumMaterials(objectID)));
print(string.format("Geometry ID: %d", getGeometry(objectID)));
elseif class == "TransformGroup" then
print(string.format("Number of children: %d", getNumOfChildren(objectID)));
elseif class == "Light" then
local DR, DG, DB = getLightDiffuseColor(objectID);
local SR, SG, SB = getLightSpecularColor(objectID);
print("Diffuse: R ", DR, " G ", DG, " B ", DB);
print("Specular: R ", SR, " G ", SG, " B ", SB);
print(string.format("Range: %d", getLightRange(objectID)));
elseif class == "Camera" then
print(string.format("Field of view: %d", getFovy(objectID)));
print(string.format("Near clip: %d", getNearClip(objectID)));
print(string.format("Far clip: %d", getFarClip(objectID)));
print("Current camera: " .. getName(getCamera()));
elseif class == "ParticleSystem" then
local emitterShape = getEmitterShape(objectID);
print(string.format("Emit start time: %d", getEmitStartTime(objectID)));
print(string.format("Emit stop time: %d", getEmitStopTime(objectID)));
print(string.format("Lifespan: %d", getParticleSystemLifespan(objectID)));
print(string.format("Average speed: %d", getParticleSystemAverageSpeed(objectID)));
print(string.format("Emitter shape: %s (ID:%d)", getName(emitterShape), emitterShape));

Unknown 08.12.2018 14:03
That script doesn't work. I tried selecting a single object but it says: Error: -- Author:LKXstudios...(15) : attempt to call global 'getClassName' (a nil value)

Note: Log in to post. Create a new account here.