Itoo Software Forum

Author Topic: Can you write me a very simple Script for grouped obj?  (Read 1224 times)

cc8boy

  • Sr. Member
  • ****
  • Posts: 286
  • I'll do my best.Welcome to www.c7design.cn .
    • C7design
Can you write me a very simple Script for grouped obj?
« on: April 06, 2017, 10:15:06 AM »
Hello everyone,
   I really need a MAXscript to add a grouped object as custom objects in Forest pro object. Can you write a very simple script that I can add specific group as custom object ?
I tried to use this commands
$.cobjlist[1] = $Grouphead
$.namelist[1] = $Grouphead.name
$.matlist[1] = sceneMaterials["abc"]

But it failed to add the whole group as custom objects.
We are working hard in virtual effects in 3DSMAX. Welcome to our website in China.

Michal Karmazín

  • iToo Software
  • Hero Member
  • *****
  • Posts: 2447
Re: Can you write me a very simple Script for grouped obj?
« Reply #1 on: April 06, 2017, 02:06:22 PM »
Hi,

That's possible via Maxscript in a following way:
All objects handled in such group can be selected and stored as the "items" variable for example by:

items = for i in Objects where (isGroupMember i == true) collect i;

To add it to existing Forest object, it's necessary to define .count vales for several Forest properties. You can find list of these in following ObjectToForest script.
Setting new counts you can proceed by:

existingItemsCount = $.cobjlist.count;
$.cobjlist.count = $.cobjlist.count + items.count;
...
$.problist.count = $.problist.count + items.count;


This needs to done for all of these values ($.matlist, $.namelist, $.coloridlist ... $.problist).
Finally, you can add & define these objects by:

for i = 1 to items.count do
    (
    $.cobjlist[existingItemsCount + i] = items;
    ...
    $.problist[existingItemsCount + i] = 100;
    );

Again, this have to be done for all listed properties ($.matlist, $.namelist, $.coloridlist ... $.problist).
Hope that helps.

Best regards,