CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 06-12-2013, 09:44 PM   #1
try2script
Expert
portfolio
Mike
Moldova
 
Join Date: Mar 2013
Posts: 489
attach object/group to all group instances

I have an abject/group selected and I want to attach it to all goup instances!
Here I have a code, and it works, but it still needs some corrections! Let's say, you have a group of glasses and you want to add it to all the tables that are groups and copied as instances! I have placed my glasses on one of the tables, then pressed btn and picked the table bellow=> this should automatically add it to all tables! The problem is with transform: If you rotated some tables, then the glasses may stay outside allready! Scale, I guess should not be affected by the scale of tables, otherwise, added glasses can get unreal dimesions! There are some errors also, when you have an object selected from an opened group, but I know how to fix- tu detach selection first, in this case! Please, who wants and are interested, you're wellcome to comment!


Code:
fn filterSelect obj = ( if isOpenGroupMember obj then return obj --and isValidNode obj if isGroupMember obj then ( while (obj.parent != undefined) and (not isOpenGroupHead obj.parent ) and (isGroupHead obj.parent) do obj = obj.parent return obj ) return obj ) rollout ... on instatachbtn click do ( local objList = #() local selObjList = #() local target = pickObject() target = filterSelect target append selObjList target j=1 while j<= objects.count and not keyboard.escPressed do ( if areNodesInstances target objects[j] then ( appendIfUnique selObjList objects[j] --print objects[j] ) j=j+1 ) -- print "============" -- print selObjList -- print "================Selection" for i in selection do appendIfUnique objList (filterSelect i) -- print objList local delta, deltap, deltar, deltas for i in objList do ( if isOpenGroupMember i then detachNodesFromGroup i delta = i.transform - target.transform deltap = i.position - target.position deltar = i.rotation-target.rotation deltas = i.scale - target.scale for j in selObjList do ( maxOps.cloneNodes i cloneType:#instance newNodes:&newGroup tempObj= newGroup[1] tempObj.transform = j.transform+delta --tempObj.scale = j.scale+deltas -- tempObj.rotation = j.rotation + deltar -- tempObj.position = j.position+deltap attachNodesToGroup tempObj j ) delete i ) )

Last edited by try2script : 06-12-2013 at 09:47 PM.
 
Old 06-13-2013, 01:13 PM   #2
try2script
Expert
portfolio
Mike
Moldova
 
Join Date: Mar 2013
Posts: 489
Here is a short preview of what I was talking about
Here is the code
and max file

Last edited by try2script : 06-13-2013 at 02:02 PM.
 
Old 06-13-2013, 04:40 PM   #3
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,431
Send a message via ICQ to denisT
Quote:
Originally Posted by try2script
Here is a short preview of what I was talking about
Here is the code
and max file

first of all you have to name your groups and objects with a name that makes more sense than just "group" or "ZBrush_defualt_group"...
 
Old 06-13-2013, 06:26 PM   #4
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
I managed position part only need to add rotation. Open attachment file select two teapots, use pickbutton and pick "table object" below teapots.

Code:
try(destroyDialog ::bgaRoll)catch() rollout bgaRoll "• • •" ( fn filtGroup o = isGroupMember o fn getRootGroupHead node = if isgroupmember node do ( while node != undefined and (not isgrouphead node or isgroupmember node) do (node = node.parent) node ) pickbutton pick "PickGroup" pos:[5,5] width:100 height:20 filter:filtGroup on pick picked obj do if obj != undefined and selection.count !=0 do ( local rootGroup = getRootGroupHead obj InstanceMgr.GetInstances rootGroup &groups selObjs = getCurrentSelection() if groups.count > 1 then ( with redraw off ( for i = 1 to groups.count where groups[i] != rootGroup do ( maxOps.cloneNodes selObjs cloneType:#instance newNodes:&objs for o in objs do ( if o.parent != undefined do o.parent = undefined offsetPOS = in coordsys rootGroup o.pos o.pos = [offsetPOS.x,offsetPOS.y,offsetPOS.z/2]*groups[i].transform attachNodesToGroup o groups[i] ) ) attachNodesToGroup selObjs rootGroup ) ) ) ) createDialog bgaRoll 110 30 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
__________________
Looking in the right side. [bgaTools]
 
Old 06-13-2013, 06:37 PM   #5
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,431
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
I managed position part only need to add rotation. Open attachment file select two teapots, use pickbutton and pick "table object" below teapots.

it's almost correct but not absolutely
 
Old 06-13-2013, 06:53 PM   #6
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
it's almost correct but not absolutely

I know. I not like position alignement but ... I guess you've already got a better solution for position and orientation.
__________________
Looking in the right side. [bgaTools]
 
Old 06-13-2013, 07:00 PM   #7
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,431
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
I know. I not like position alignement but ... I guess you've already got a better solution for position and orientation.

this is not about an alignment. you don't attach selection correctly. the problem is when a selection is a group member. in this case attachNodesToGroup fails with your code.
 
Old 06-13-2013, 07:27 PM   #8
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
this is not about an alignment. you don't attach selection correctly. the problem is when a selection is a group member. in this case attachNodesToGroup fails with your code.

Yup. I have limited solution. For "all case" scenario we need to consider many different conditions
# if selection have target
# is selection is a group member or group head
# is selection is child
etc.
__________________
Looking in the right side. [bgaTools]
 
Old 06-13-2013, 08:42 PM   #9
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,431
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
Yup. I have limited solution. For "all case" scenario we need to consider many different conditions
# if selection have target
# is selection is a group member or group head
# is selection is child
etc.

true... but all these cases might be check by only one condition ...
 
Old 06-13-2013, 08:45 PM   #10
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
true... but all these cases might be check by only one condition ...

isGroupMember $
__________________
Looking in the right side. [bgaTools]
 
Old 06-13-2013, 09:08 PM   #11
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,431
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
isGroupMember $

correct... if it's a group member don't process it.

but... i think that any node should be cloned and attached with its children... so you have to make another little change in your script to support it. (i say "a little". it means add two words)
 
Old 06-13-2013, 09:13 PM   #12
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
correct... if it's a group member don't process it.

but... i think that any node should be cloned and attached with its children... so you have to make another little change in your script to support it. (i say "a little". it means add two words)

expandHierarchy argument in maxOps.CloneNodes method.

__________________
Looking in the right side. [bgaTools]
 
Old 06-13-2013, 09:20 PM   #13
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,431
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
expandHierarchy argument in maxOps.CloneNodes method.


why do i have to thrust you under your nose every time?
 
Old 06-13-2013, 09:22 PM   #14
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Recently I've posted this snippet (mirror selection fn) on scriptspot.
Code:
-- ARGUMENT OPTIONS -- axis enums: {#x|#y|#z}. Default X-Axis -- center (miiror about point3) also you can use any object center. Default: world center -- clone enums: {#copy|#instance|#reference}. Default instance fn mirrorSelection axis:#x center:[0,0,0] clone:#instance = if selection.count != 0 do ( local ax = case axis of ( (#x): [-1,1,1] (#y): [1,-1,1] (#z): [1,1,-1] ) local parentslist = #() maxOps.CloneNodes (selection as array) offset:[0,0,0] cloneType:clone newNodes:&clones for i in clones do (append parentslist i.parent ; i.parent = undefined) about center scale clones ax for i = 1 to clones.count do clones[i].parent = parentslist[i] free parentslist ) mirrorSelection()

In this cases I am trying to clone selected parent object and all unselected children together
and I think that "expandHierarchy" not works here. So I used unparent/parent method
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 06-13-2013 at 09:29 PM.
 
Old 06-13-2013, 09:25 PM   #15
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
why do i have to thrust you under your nose every time?

Not undertand?
edit
I do understand you. Well I'm not sure allways in my fn's.
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 06-13-2013 at 09:38 PM.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:03 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.