Notifications
Clear all

[Closed] Copy/Paste transform data?

OK, kind of solved it… did the XML version It’s way faster than the INI version and it works at least with 2200 objects in a matter of seconds (saving and loading). Cheers!

macroScript ObjCopyPaste
category:"K Scripts"
(
	try (destroyDialog ObjCopyPaste_Rollout) catch()
	
	rollout ObjCopyPaste_Rollout "ObjT Copy/Paste"  width:300
	(
		label lbl_objects "Objects:" align:#left
		dotnetcontrol lst_obj "System.Windows.Forms.Listbox" align:#center height:200
		label lbl_transform "Transform:" align:#left width: 275 height:42 style_sunkenedge:true
		button 	btn_save "Save" align:#left across:2
		button 	btn_load "Load" align:#right
		button btn_apply "Apply all"
		button btn_site "?" align:#center
		local xmlPath=getdir(#export) + "\\ObjCopyPaste.xml"
		local XML=dotnetobject "System.Xml.XmlDocument"
		
		on objdataT open do
		(
			lst_obj.HorizontalScrollbar=True
		)
		
		on btn_save pressed do
		(
			if selection.count!=0 then
			(
				xmlPath=getdir(#export) + "\\ObjCopyPaste.xml"
				fileSave=getSaveFileName  filename:xmlPath types:"XML File (*.xml)|*.xml"
				if fileSave!=undefined then 
				(
					lst_obj.BeginUpdate()
					lst_obj.Items.Clear()
					---
					XML=dotnetobject "System.Xml.XmlDocument"
					root=XML.CreateElement "Root"
					XML.AppendChild root
					
					for i in selection do
					(
						xName=XML.CreateElement i.name
						xName.InnerText=i.transform as string
						root.AppendChild xName
						lst_obj.Items.Add i.name
					)
					
					XML.Save fileSave
					---
					lst_obj.EndUpdate()
				)
			)
		)
				
		on btn_load pressed do
		(
			fileOpen=getOPenFileName  filename:xmlPath types:"XML File (*.xml)|*.xml"
			if fileOpen!=undefined then 
			(
				lst_obj.BeginUpdate()
				lst_obj.Items.Clear()
				---								
				XML.Load fileOpen
				
				root=XML.FirstChild
				for i=0 to root.ChildNodes.Count-1 do
				(					
					lst_obj.Items.Add root.ChildNodes.Item[i].name
				)
				
				xmlPath=fileOpen
				---
				lst_obj.SelectedIndex=0
				lst_obj.EndUpdate()
			)
		)
		
		on lst_obj SelectedIndexChanged sender arg do
		(
			fNode=XML.FirstChild.GetElementsByTagName(lst_obj.SelectedItem)
			lbl_transform.text=fNode.Item[0].InnerText
		)
		
		on lst_obj DoubleClick sender arg do
		(
			setCommandPanelTaskMode mode:#create
			suspendEditing()
			for i in selection do
			(
				i.transform=execute lbl_transform.text
			)
			resumeEditing()
		)
		
		on btn_apply pressed do
		(
			if lst_obj.Items.Count!=0 then
			(
				setCommandPanelTaskMode mode:#create
				suspendEditing()
				root=XML.FirstChild
				for i=0 to root.ChildNodes.Count-1 do
				(		
					try
					(
						execute ("select $" + root.ChildNodes.Item[i].name)
						execute ("$"+ root.ChildNodes.Item[i].name + ".transform=" + root.ChildNodes.Item[i].InnerText)
					)
					catch (print ("Object " + root.ChildNodes.Item[i].name + " not found"))
					
				)				
				resumeEditing()
			)
		)
		on btn_site pressed do
		(
			process=dotnetclass "System.Diagnostics.Process"
			process.start "http://www.dimensao3.com/al"
		)
	)
	clearListener()
	createDialog ObjCopyPaste_Rollout
)

Well, I never knew you could do that. Mighty handy.

I stopped using INI stuff after all the limitations i encountered. Just in case, for those of you on max9/2008, the most recent Blur Beta tools include a component called BlurXML. It’s very straightforward to use as well… guess it’s about as easy as the .net stuff now that I look at it.


   thedoc = blurxml.newDocument()
   		FileStuff= thedoc.addnode "FileStuff"
   		Pathinfo= FileStuff.addnode "Pathinfo"
   		Pathinfo.setattribute "Folder" (maxfilepath)
   		Pathinfo.setattribute "File" (maxfilename)
   blurxml.savedocument thedoc (maxfilepath + "test.xml")
   

creates:

<?xml version="1.0" encoding="utf-8" ?>
   
   <FileStuff>
   
     <Pathinfo Folder="U:\2012\LAL\LAL_058_380\3D\LAL_058_380_fxEnv_GroundBreaking\" File="LAL_058_380_fxEnv_GroundBreaking_v055_015.max" />
   
   </FileStuff>

and reading is just as straightforward… nodes have .children and .attributes and there are functions for more specific stuff too. Very simple example:


  readdoc = blurxml.loaddocument (maxfilepath + "test.xml")
  readdoc.children[2].children[1].attributes[1].value   --returns "U:\2012\LAL\LAL_058_380\3D\LAL_058_380_fxEnv_GroundBreaking\"
  

–Thought I’d share!

Page 2 / 2