select just one instance

hello
I look for a script to select just one instance of an object :
- select all objects I want to work with
- run the script
- just one instance of each object is selected.
Thanks

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
eyepiz's picture

if selection.count != 0

if selection.count != 0 do
(
local firstInstances = #()
for o in selection do
(
InstanceMgr.GetInstances o &firstOnly
if firstOnly.count > 1 do
append firstInstances firstOnly[firstOnly.count-1]
)
if firstInstances.count != 0 do select firstInstances
)

barigazy's picture

...

Using this fn U can do what you want

	fn collectUniqueNodes objs = if objs.count != 0 do
	(
		local getNodeByHandle = maxOps.getNodeByHandle, getObjIns = InstanceMgr.GetInstances
		local uniqNodes = #(), allINodes = #()
		for o in objs do append allINodes o.inode.handle
		while allINodes.count != 0 do
		(
			obj = (getNodeByHandle allINodes[allINodes.count])
			if isValidNode obj do append uniqNodes obj
			if not (refhierarchy.IsRefTargetInstanced obj) then deleteItem allINodes allINodes.count else
			(
				getObjIns obj &firstOnly
				for o in firstOnly where (idx = findItem allINodes o.inode.handle) != 0 do deleteItem allINodes idx
			)
		)
		uniqNodes
	)

Now "objs" argument in fn represent array ei.collections of object.
If you want to consider only selected objects then run

collectUniqueNodes selection

to consider only geo-objects use

arr = for o in geometry where not isKindOf o TargetObject collect o
collectUniqueNodes arr

bga

eyepiz's picture

Still now working for

Still now working for me...
We are putting a script together to clean up imported CAD geometry. What we would like it to do is to selects all non instanced objects and a single instance of the instanced objects.

our goal is to select only the necessary objects prior to running the other scripts such as delete isolated verts, weld and smooth, flip inverted normal, quadrify ect...

I would appreciate any help.

Thank you!

barigazy's picture

...

I simplified fn and now it works fine

	fn collectUniqueNodes objs = if objs.count != 0 do
	(
		local getNodeByHandle = maxOps.getNodeByHandle, getObjIns = InstanceMgr.GetInstances 
		local uniqNodes = #(), allINodes = #()
		for o in objs do append allINodes o.inode.handle
		while allINodes.count != 0 do
		(
			obj = (getNodeByHandle allINodes[allINodes.count])
			getObjIns obj &firstOnly ; append uniqNodes firstOnly[firstOnly.count]
			for o in firstOnly where (idx = findItem allINodes o.inode.handle) != 0 do deleteItem allINodes idx
		)
		uniqNodes
	)
	select (collectUniqueNodes objects)

bga

eyepiz's picture

This works!...1000 Thanks!

This works!...1000 Thanks!

eyepiz's picture

Thanks!

Thanks!

titane357's picture

Thank you very much ! :-)

Thank you very much ! :-)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.