Itoo Software Forum

Author Topic: Replace object in all forests  (Read 3269 times)

CO2263

  • Jr. Member
  • **
  • Posts: 94
Replace object in all forests
« 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

iToo

  • Administrator
  • Hero Member
  • *****
  • Posts: 4388
    • iToo Software
Re: Replace object in all forests
« Reply #1 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
)
)
)

Carlos Quintero
iToo Software

CO2263

  • Jr. Member
  • **
  • Posts: 94
Re: Replace object in all forests
« Reply #2 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

iToo

  • Administrator
  • Hero Member
  • *****
  • Posts: 4388
    • iToo Software
Re: Replace object in all forests
« Reply #3 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
« Last Edit: March 02, 2013, 05:15:24 PM by iToo »
Carlos Quintero
iToo Software

CO2263

  • Jr. Member
  • **
  • Posts: 94
Re: Replace object in all forests
« Reply #4 on: March 02, 2013, 04:46:46 PM »
UI works
but 'replace' button does nothing ((


iToo

  • Administrator
  • Hero Member
  • *****
  • Posts: 4388
    • iToo Software
Re: Replace object in all forests
« Reply #5 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.

Carlos Quintero
iToo Software

CO2263

  • Jr. Member
  • **
  • Posts: 94
Re: Replace object in all forests
« Reply #6 on: March 02, 2013, 05:34:55 PM »
Perfect!!!
Thanks a lot Carlos!  ;)