Itoo Software Forum

Forest Pack => Forest Pro (*) => Topic started by: CO2263 on February 28, 2013, 11:25:09 PM

Title: Replace object in all forests
Post by: CO2263 on February 28, 2013, 11:25:09 PM
Hi,
I have a huge scene with about 30-40 forest objects. And it's kid of a headache when you need to change one tree type to another. I need to go through all forests and do it manually. Sometimes you can just forgot to make changes to some forests...
Is there any way to replace a proxy for all forest object in one click? If not then would be great to have this feature with new updated Forest Pack version.
Thanks
Title: Re: Replace object in all forests
Post by: iToo on March 01, 2013, 10:58:44 AM

The attached script would help you. It replaces the geometry of one object by other, and update names and materials in all Forest objects.

To use it, just set the name of the objects in the two first variables and run it (with the default values, it replaces the "box" by the "cone")

Code: [Select]
-- object that we want to replace
src = $box
-- object that will replace it
dst = $cone
-- processing
instanceReplace src dst
src.name = dst.name
for i in Geometry where classOf i == Forest_Pro do
(
for n = 1 to i.cobjlist.count do
(
if (i.geomlist[n] == 2) and (i.cobjlist[n] != undefined) then
(
i.matlist[n] = i.cobjlist[n].material
i.namelist[n] = i.cobjlist[n].name
)
)
)

Title: Re: Replace object in all forests
Post by: CO2263 on March 02, 2013, 03:41:17 PM
Thanks for reply
It works but...
is it possible not to delete the original object instance? Just change it inside forest
any way to have UI for that small script (like pickbutton)
Thx
Title: Re: Replace object in all forests
Post by: iToo on March 02, 2013, 04:26:57 PM
Here is. Source is the object that you want to replace, and Target which replace it.

Code: [Select]
rollout forest_obj_replace "Forest Object Replacer"
(
pickbutton sourceButton "Source" width:140
pickbutton targetButton "Target" width:140
button replaceButton "Replace"
local src, tgt

on sourceButton picked obj do
(
if obj != undefined do
(
sourceButton.text = obj.name
src = obj
)
)
on targetButton picked obj do
(
if obj != undefined do
(
targetButton.text = obj.name
tgt = obj
)
)
on replaceButton pressed do
(
message
if src != undefined and tgt != undefined then
(
for fo in Geometry where (classOf fo == Forest_Pro or classOf fo == Forest_Pro_3) do
(
for n = 1 to fo.cobjlist.count do
(
if (fo.geomlist[n] == 2) and (fo.cobjlist[n] == src) then
(
fo.cobjlist[n] = tgt
fo.matlist[n] = tgt.material
fo.namelist[n] = tgt.name
)
)
)
)
)
)

createDialog forest_obj_replace
Title: Re: Replace object in all forests
Post by: CO2263 on March 02, 2013, 04:46:46 PM
UI works
but 'replace' button does nothing ((

(http://clip2net.com/clip/m198803/thumb640/1362239169-clip-30kb.png) (http://clip2net.com/s/2TDd0)
Title: Re: Replace object in all forests
Post by: iToo on March 02, 2013, 05:17:11 PM

The script is written for Forest Pro 4, it was necessary to add a small change for Forest 3.

I have updated it, now should work with both versions.

Title: Re: Replace object in all forests
Post by: CO2263 on March 02, 2013, 05:34:55 PM
Perfect!!!
Thanks a lot Carlos!  ;)