[Closed] Help with Grouping
Hi All,
I’m pretty new to maxscript (only written a couple very simple scripts) and had a couple of general questions.
Can you group objects by their location or if they touch? I have buildings that are made up of individual objects and would like to find a way to automate their grouping. Ideally I would like to turn all these objects into a single object and from what I have read, I have to group to get something like this. There are many buildings in one file (around 300) so you can imagine that it’s a lot of work to do this by hand, especially on a larger scale than that file (which I will have to work on later).
Thanks in advance.
Is this an export from another package? Have you explored the export options or where you just given a mess and told to quote : “Just use this pile of S#!^ …oh, and make it look good…” ?
It’s doable in MaxScript, but I would explore naming or material simialities from export before trying to tell if things “touch” or not, because who knows if the modeler made them touch or not…
Unfortunately, I can’t get any better data then what they have given me. The supervisors see this as better than making it ourselves, which I guess I agree with… Anyways, I have looked around to find a common attribute (material, name, etc) and can find none. I was hoping to be able to collapse them based of their spatial location/proximity to one another. I work a lot with GIS and FME which do this very well, but can’t find a way to make Max do it.
Is there a way to collapse all the objects based off their spatial proximity to one another?
This should help…
First time it runs, it creates a mesh named “CollapseInsideMe.” Use scale or move vertexes to stretch this volume to contain all the objects you wish to collapse together… run the script again and it attach objects who’s position (pivot) is within the volume.
(
tnArea = getNodeByName "CollapseInsideMe"
if ( tnArea == undefined ) then
tnArea = convertToMesh( box pos:[0,0,0] height:1200 width:1200 length:1200 name:"CollapseInsideMe" color:yellow )
else
(
-- looks through geometry and if it's not hidden.
-- attaches all objects whos pivot is located within the bounding
-- box, by common material
local NewObject = undefined
for chkObj in geometry do
(
-- if not the box, but within the volume, attach.
if chkObj != tnArea and chkObj.ishidden == false then
if chkObj.pos.x > tnArea.min.x and chkObj.pos.x < tnArea.max.x then
if chkObj.pos.y > tnArea.min.y and chkObj.pos.y < tnArea.max.y then
if chkObj.pos.z > tnArea.min.z and chkObj.pos.z < tnArea.max.z then
if NewObject == undefined then
(
NewObject = ChkObj
convertToMesh NewObject
NewObject.name = uniqueName "Building_00"
)
else
attach NewObject chkObj
)
)
)
Ok… went crazy on this one… Now makes a box with a button on the control panel to attach with… also has the option to collapse by material… fun little tool
--@ custom Attribute to add to a BOX functions to collapse
--@ geometry with within the volume and with the option
--@ of Attaching by Material
-- By Keith Morrison @ focus360
--ScriptVerisonNumber = "1.000"
AttachInVolumeCustomAtt = attributes AttachInVolume
attribID:#(0x56fed768, 0x3d12ea8c)
version:1.002
(
parameters main01 rollout:AttachInVolumeRollout
(
DefaultName ui:DefaultName_ type:#string default:"BUILDING"
ByMaterial ui:ByMaterial_ type:#boolean
)
fn AttachInVolumeIgnoreMats ObjectName =
(
tnArea = Selection[1]
-- looks through geometry and if it's not hidden.
-- attaches all objects whos pivot is located within the bounding
-- box, by common material
local NewObject = undefined
set coordSys world
local VisGeo = #()
-- cache visible, Meshable geometry
for chkObj in geometry do
if canconvertto chkObj Mesh then
if chkObj.ishidden == false then
append VisGeo chkObj
for i = VisGeo.count to 1 by -1 do
(
chkObj = VisGeo[i]
-- if not the box, but within the volume, attach.
if chkObj != tnArea then
if chkObj.pos.x > tnArea.min.x and chkObj.pos.x < tnArea.max.x then
if chkObj.pos.y > tnArea.min.y and chkObj.pos.y < tnArea.max.y then
if chkObj.pos.z > tnArea.min.z and chkObj.pos.z < tnArea.max.z then
(
format "%
" chkObj
if NewObject == undefined then
(
NewObject = ( ChkObj )
convertToMesh NewObject
NewObject.name = uniqueName ObjectName
)
else
meshop.attach NewObject (chkObj) attachMat:#neither
)
)
)
fn AttachInVolumeByMats ObjectName =
(
tnArea = Selection[1]
-- looks through geometry and if it's not hidden.
-- attaches all objects whos pivot is located within the bounding
-- box, by common material
local NewObject = undefined
set coordSys world
local VisGeo = #()
local GeoByMatArray = #()
-- cache visible, Meshable geometry
for chkObj in geometry do
if canconvertto chkObj Mesh then
if chkObj.ishidden == false then
append VisGeo chkObj
for i = VisGeo.count to 1 by -1 do
(
chkObj = VisGeo[i]
-- if not the box, but within the volume, attach.
if chkObj != tnArea then
if chkObj.pos.x > tnArea.min.x and chkObj.pos.x < tnArea.max.x then
if chkObj.pos.y > tnArea.min.y and chkObj.pos.y < tnArea.max.y then
if chkObj.pos.z > tnArea.min.z and chkObj.pos.z < tnArea.max.z then
(
local NewObject = undefined
if GeoByMatArray.count == 0 then
(
if ( chkObj.material != undefined ) then
chkObj.name = ( ObjectName + "-" + chkObj.material.name )
convertToMesh chkObj
GeoByMatArray = #(chkObj)
NewObject = ChkObj
)
else
(
for ChkGBM in GeoByMatArray do
if ( ChkGBM.material == chkObj.material ) then
NewObject = ChkGBM
if ( NewObject == undefined ) then
(
if ( chkObj.material != undefined ) then
chkObj.name = ( ObjectName + "-" + chkObj.material.name )
convertToMesh chkObj
append GeoByMatArray chkObj
NewObject = ChkObj
)
if ( NewObject != undefined ) and ( NewObject != ChkObj ) then
meshop.attach NewObject (chkObj) attachMat:#neither
)
)
)
)
rollout AttachInVolumeRollout "Attach In Volume 1.001"
(
editText DefaultName_ "" text:"Building"
checkbox ByMaterial_ "Attach by Material"
button GoCollapse "Attach in Volume"
on GoCollapse pressed do
(
undo on
(
if ByMaterial_.checked then
AttachInVolumeByMats DefaultName_.text
else
AttachInVolumeIgnoreMats DefaultName_.text
)
)
)
)
tnArea = box pos:[0,0,0] height:1200 width:1200 length:1200 name:"CollapseInsideMe" color:yellow
custAttributes.add tnArea AttachInVolumeCustomAtt
select tnArea
max modify mode