Notifications
Clear all

[Closed] What's my name v2

Hello,

following up on my humble entry for the last challenge ( http://forums.cgsociety.org/showpost.php?p=5239375&postcount=11 ) i’d like to post a new and improved version of my renaming script. This script enables you to create groups of names and helps you keep track and store them. You can apply these names to objects in the scene without typing. The script needs more work, but i wanted to post it to get some feedback and suggestions.

Typically you create a group first (bottom listview) and create some names second (the two top listviews). If you want to display the contents of a group: drag the group onto one of the two top-listviews. If you want to add the same name to another group: drag the name onto the title of the group. Assigning names to groups isn’t available in the menus yet, only drag/drop. Also you can link a wirecolor to the name which gets assigned when renaming.

You’re getting two files. The scriptfile can be stored anywhere. The xml-file is used to store the names. For the moment i save them to the #userscripts directory. So if you want to use my example file: put it in your #userscripts directory (mine is called:“C:\Users\klaas\AppData\Local\Autodesk\3dsmax\2008 – 32bit\enu\scripts” but yours is probably different). Otherwise a new, empty file will be created for you in this location.

So, enjoy and any feedback is welcome.
Klaas

2 Replies

Hello,

i've updated the renaming script. The script enables the user to apply names and wirecolors to objects in a scene. The names and colors are stored in a list and can be applied by doubleclicking an item on this list or by choosing an option from a menu.
A user can create his own names and organize them in groups. He can make names which fit a certain workflow or topic and group them together. A company can "enforce" a uniform objectnaming scheme throughout a project with ease by offering predefined groups of names.

The script uses an external xml-file to store the names. At this moment this file is stored in the #userscripts folder.

The zip-file contains a the scriptfile and an xml-file. The xml-file already has some names. Put the xml-file in your #userscripts directory to start with these names. If you don’t, you start with a blank file to start creating your own.

Well, i have a question.

The script shows a preview of the renaming action. It’s a listview with the original name and the new name shown in two columns. I use the “virtualmode” for the listview. This makes speedy updates of large selectionsets with new names possible. Nevertheless i’m getting severe errors either from max (memory and gc issue) or from dotnet itself (which i don’t understand entirely, but these make max freeze). I’ve seen examples in the msdn docs on virtualmode and caching but i have trouble understanding them.

This example here doesn’t reproduce those errors but shows the behaviour of the virtualmode. Virtualmode should redraw only the items necessary (visible?). But even when you move the mouse over the listview, the virtualmode kicks in and redraws the listviewItems. I have the event printout the available memory. This goes down fast if you imagine a heavy function is executed inside this event (in my case: a rename function).

So, i assume my memoryisues originate from this part of the script, but i’m not absolutely sure. Can somebody help me sort this problem out?

Klaas

struct str_previewMethods
 (
 	lvPreview,
 	
 	--a single virtualItem is made when needed
 	function fn_createVirtualItem control arg =
 	(
 		local newItem
 		--format "Virtual item made at: % miliseconds
" (timestamp())
 		if selection.count > 0 do
 		(
 			newItem = dotNetObject "listViewItem" (selection[arg.itemIndex+1].name) --create a listviewItem
 			newItem.subItems.add (selection[arg.itemIndex+1].name) 
 		)
 		print heapfree
 		arg.item = newItem
 	),
 	
 	function fn_constructLvPreview =
 	(
 		lvPreview = dotNetObject "listview"
 		lvPreview.name = "lvPreview"
 		lvPreview.view = (dotNetClass "System.Windows.Forms.View").Details
 		lvPreview.Dock = lvPreview.Dock.fill
 		lvPreview.columns.add "Objectname" 120 --the name column
 		lvPreview.columns.add "New objectname" 118 --the color column
 		lvPreview.scrollable = true
 		lvPreview.virtualmode = true--set the virtualmode
 		lvPreview.virtualListSize = selection.count --the amount of items in the list is ezual to the amount of selected objects
 		fn event_retrieveVirtualItem control arg = str_previewMethods.fn_createVirtualItem control arg
 		dotNet.addEventHandler lvPreview "RetrieveVirtualItem" event_retrieveVirtualItem --this event creates and adds new items to the listview
 		lvPreview
 	),
 	tmpConstruct = fn_constructLvPreview()
 )
 str_previewMethodsInstance = str_previewMethods()
 
 
 
 struct str_mainForm
 (
 	maxForm,
 	
 	function fn_constructForm =
 	(
 		maxForm = dotNetObject "MaxCustomControls.MaxForm"
 		maxForm.Size = dotNetObject "System.Drawing.Size" 250 500 
 		maxForm.Text = "What's my name v2.0 by Klaas Nienhuis July 2008"
 		maxForm.FormBorderStyle = maxForm.FormBorderStyle.fixedSingle
 		maxForm.ShowInTaskbar = false
 		maxForm.MinimizeBox = false
 		maxForm.MaximizeBox = false
 		maxForm.Controls.AddRange #(str_previewMethodsInstance.lvPreview)--add the listview to the menu
 		-- some events
 		function event_shutdown = callbacks.removeScripts id:#klaasnienhuiswhatsmyname2
 		dotNet.addEventHandler maxForm "closed" event_shutdown
 		maxForm.ShowModeless()
 	),
 	tmpConstruct = fn_constructForm()
 )
 
 try(klaasNienhuisWhatsMyName.maxForm.close())catch()
 
 global klaasNienhuisWhatsMyName = str_mainForm()
 	
 function fn_callback = 
 (
 	local mySelection = selection as array
 	klaasNienhuisWhatsMyName.maxForm.controls.item["lvPreview"].invalidate()--reset the listview. is neccesary when the selection.count doesn't change but the seletion items do
 	klaasNienhuisWhatsMyName.maxForm.controls.item["lvPreview"].virtualListSize = mySelection.count --set the virtualListSize to match the size of the selection
 )
 callbacks.removeScripts id:#klaasnienhuiswhatsmyname2
 callbacks.addScript #selectionSetChanged "fn_callback()" id:#klaasnienhuiswhatsmyname2