Select Scene Geometry Through Array Comparison

Hello!
I finally decided to take some time and delve into Maxscript. I find it very exciting! But at the same time, a bit tough in terms of the learning curve.

I am currently trying to understand arrays.

What I want the script to do:
1. Obtain all the geometry names and positions (Assign them to specific arrays)
2. Based on a preset index range -- Example: objIndex = #{2..5} Get those names
3. Store only those names from the range in a new array
4. Compare the names in the new array with the scene geometry
5. If the scene geometry names match the new array names then (do something) -- Like Delete them

Here is the script I have so far: -- I know I am probably doing this in the most terrible and destructive way. Forgive me lol.

(
local GAPos = #()
local GAName = #()
local GASel = #()
(
GAPos = for o in geometry collect o.pos
GAName = for m in geometry collect m.name
)
GAIndex = #{3..5}
GASel = for k in GAIndex collect (GAName[k])
)

Comments

Comment viewing options

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

Wow!

Wow! Thank you for the comprehensive breakdowns and multiple examples.
I will take the next day or 2 to really try and wrap my head around each of these.

I ran into another situation and was curious how this could be accomplished in an array.
Is it possible to select objects within an array if they are greater than a specific index value?
I know this isn't right** But for the sake of an example:
index = {2..infinity} -- or any value greater than 2

Thanks again!

miauu's picture

.

(
	objsArr = #("Teapot011", "Teapot101", "Teapot022", "Teapot234", "Teapot987")
	index = 2
	newObjsArr = for i = (index + 1) to objsArr.count collect objsArr[i]
)
miauu's picture

.

I don't know why you want to works with the name of the objects, but...
Step by step.
Now examin the codes from barigazy and you will be more familiar with the arrays. :)

(
	-- 	1. Obtain all the geometry names and positions (Assign them to specific arrays)
	objNamesArr = #()
	objPosArr = #()
	for o in geometry do
	(
		append objNamesArr o.name
		append objPosArr o.pos
	)	
	-- 2. Based on a preset index range -- Example: objIndex = #{2..5} Get those names
	--	why you use bitarray? in your example the #{2..5} means that the objects with indexes 2, 3, 4, 5 will be "used"
	objIndex = #{2..5}
	-- 3. Store only those names from the range in a new array
	newNamesArr = for i in objIndex collect objNamesArr[i]	
	-- 4. Compare the names in the new array with the scene geometry
	-- I assume that some of the objects are deleted or new objects are created.
	geometryNamesArr = for o in geometry collect o.name
	matchingObjectsArr = for obj in newNamesArr where (findItem geometryNamesArr obj) != 0 collect obj
	-- 5. If the scene geometry names match the new array names then (do something) -- Like Delete them
	-- matchingObjectsArr contanis all objects that you need. Do with them what you want.
)
barigazy's picture

...

This is the one of many ways.

-- make multidimensional array to store name and position
geoData = for o in geometry collect #(o.name,o.pos)
idx = #{3..5}
-- next code will collect all objects with specified index
-- use "where" statement of "for-loop" to check if index number is not greather 
-- then actual geoData items count.
-- use "getNodeByName" fn and check if this object exist then collect it.
-- After collecting object use delete fn to remove these objects all at once
delete (for i in idx where i<=geoData.count and isValidNode (node = getNodeByName geoData[i][1]) collect node)

barigazy

barigazy's picture

...

U can consider these few way also

--#1 way (collect method)
GAPos = #()
GAName = #()
GAPos = for o in geometry collect o.pos
GAName = for m in geometry collect m.name
 
--#2 way (append method)
GAPos = #()
GAName = #()
for o in geometry do 
(
	append GAPos o.pos
	append GAName o.name
)
 
--#3 way (collect+append method)
GAPos = #()
GAName = for o in geometry collect 
(
	append GAPos o.pos
	o.name
)
 
--#4 way (multidimensional array method)
GAPosName = for o in geometry collect #(o.name,o.pos)
 
--#5 way (datapair method)
GAPosName = for o in geometry collect datapair o.name o.pos
-- or 
GAPosName = for o in geometry collect datapair name:o.name pos:o.pos

barigazy

barigazy's picture

...

The smart way is to create an function with some arguments.
Try to do this and post it here. All info you can find in MaxScript Help document

barigazy

Comment viewing options

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