Notifications
Clear all

[Closed] Counting through an ini file?

Hello again,

I keep running into consistency issues it seems, when creating / counting through an ini file.

I am using a counter as part of the ini entry, to make it easy to navigate through my file, or so I thought.
But… for some reason, max randomly seems to skip the count value on entry, so I get stuff like below


 IMAGES28=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_763923C7_0_030.jpg
 IMAGES29=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_197005B_0_031.jpg
 IMAGES30=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_763923C7_0_031.jpg
 IMAGES31=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_5A9E79B6_0_033.jpg
 IMAGES32=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_710BE4FD_0_025.jpg
 IMAGES33=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_20D7F13A_0_035.jpg
 IMAGES34=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_5C523EDD_0_036.jpg
 IMAGES35=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_197005B_0_032.jpg
 IMAGES36=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_0_0_015.jpg
 IMAGES38=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_710BE4FD_0_026.jpg
 IMAGES39=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_710BE4FD_0_027.jpg
 IMAGES40=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_2B1E785A_0_042.jpg
 IMAGES41=C:\Users\MATT\AppData\Local\Autodesk\3dsMax\2010 - 64bit\enu\Scripts	urboTools\MergeThumbs\Shop_Interior\Nemu_34BA617A_0_040.jpg

You will notice that entry 37 is missing… However, the final count of entries in the ini file is correct.

So how could I go about reading this info without relying on using the INI KeyString name, if possible?

Or does anyone know why max would skip a number like that? There isn’t any reason why it should that I can see… this is what I have where it enters the numbers…

						Counter2  = 0
 									for o in Geometry where o.isHidden == false do
 									(
 										select o
 										o.material = theMaterialColor
 										--ntm = o.transform
 										--vtm = getViewTM()
 										--	o.transform = translate (rotate (scalematrix ntm.scale) (inverse vtm.rotation)) ntm.pos
 										 
 										actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
 										macros.run "Tools" "Isolate_Selection"
 									
 										theCurrentMaxFileName = getFilenameFile  mergingPreviewFilename
 										thePath  = (pathConfig.GetDir #MaxData +"Scripts\	urboTools\MergeThumbs" + "\\" + theCurrentMaxFileName + "\\" )
 										b= bitmap 200  200 filename:(thePath + ((o.name) + ".jpg"))	
 										render frame:#current outputwidth:200 outputheight:200 to:b vfb:off --outputFile:(_scriptDir +"\\" + (o.name + ".jpg")) 
 										save b 
 										close b
 										setINISetting  (thePath +  theCurrentMaxFileName + ".ini") "JPG_FILENAME"   ("IMAGES"  + (Counter2 as string))	b.filename  --("IMAGES"  + (Counter as string))
 										setINISetting  (thePath +  theCurrentMaxFileName + ".ini") "Button_NAME"	("BUTTONS" + (Counter2 as string))  o.name
 										setINISetting  (thePath +  theCurrentMaxFileName + ".ini") "Button_TEXT"  ("BUTTONS" + (Counter2 as string))   o.name
 									
 										--print counter
 										Counter2 += 1
 
 										hide o
 										(iso2roll.c2iso.changed (iso2roll.c2iso.state = false)) 
 	
 								
 									)
 									
 									for o in Shapes where o.isHidden == false do
 									(
 										
 										select o
 										o.material = theMaterialColor
 									
 										actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
 										macros.run "Tools" "Isolate_Selection"
 		
 										theCurrentMaxFileName = getFilenameFile  mergingPreviewFilename
 										thePath  = (pathConfig.GetDir #MaxData +"Scripts\	urboTools\MergeThumbs" + "\\" + theCurrentMaxFileName + "\\" )
 										b= bitmap 200  200 filename:(thePath + ((o.name) + ".jpg"))	
 										render frame:#current outputwidth:200 outputheight:200 to:b vfb:off --outputFile:(_scriptDir +"\\" + (o.name + ".jpg")) 
 										save b 
 										close b
 										setINISetting  (thePath +  theCurrentMaxFileName + ".ini") "JPG_FILENAME"  ("IMAGES"  + (Counter2 as string))   b.filename
 										setINISetting  (thePath +  theCurrentMaxFileName + ".ini") "Button_NAME"	("BUTTONS" + (Counter2 as string))  o.name  --o.name
 										setINISetting  (thePath +  theCurrentMaxFileName + ".ini") "Button_TEXT"  ("BUTTONS" + (Counter2 as string))   o.name
 									
 										
 										Counter2 += 1
 
 										
 										hide o
 										(iso2roll.c2iso.changed (iso2roll.c2iso.state = false)) 
 											
 									)
3 Replies

Well… I think I solved it…

I just am checking each entry as I loop through them, with the hasINISetting lookup. So if that returns true, then I can read that line, otherwise go to the next one.

I also ran into an issue with invalid characters in object names, so I got a function to strip those for the JPG names.

On a side note:
I still don’t understand why Max allows for things like, the exact same names for multiple objects…??

1 Reply
(@bobo)
Joined: 2 years ago

Posts: 0

The best way to loop through an INI file without knowing the counter (or anything about the key names really) is to get all keys from a category into an array and then loop through them.

theKeys = getIniSetting theFile "SomeCategory"
 for aKey in theKeys do 
   theValue = getIniSetting theFile "SomeCategory" aKey

This is because names are really only useful when you access objects programmatically via a scripting language. When Max 1.0 was designed though, there was no such language, so there was no real need to enforce unique naming. Then it was too late
Max itself uses object references which are significantly more robust than names. That’s why the Script controllers were later rewritten to use object references instead of explicit names.
But you are right, it is a PITA.

Ah, ok… Yeah, that names thing threw me through a loop/put me into a somewhat of a rage, lol.

Thanks for the INI snippet, I will have to switch to that then :D.

So when you say object references, is that something we can access via maxscript and use like I would a name? I know objects have the GUID, but that’s per max session. I could load up max, but I need to head out very shortly. I will look when I get to work though.