Deleting CustomAttributes using getDefInstances, deleteDef problems

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  10 October 2011
Deleting CustomAttributes using getDefInstances, deleteDef problems

I'm trying to delete all instances and then the actual definition of a custom attribute set. But for some reason, I run into trouble. I think there are some references dangling behind somewhere, but I can't figure out how and why.

Here's a bit of test code that does work:
testCA = attributes testCA attribID:#(0x42a4cdb9, 0x13c71b46) ( )
 (
 s = sphere()
 custattributes.add s testCA;
 custattributes.delete s testCA;
 custattributes.deleteDef testCA;
 )


But then to make it a bit more useful, I try to get all instances of the CA definition and delete them:
testCA = attributes testCA attribID:#(0x42a4cdb9, 0x13c71b46) ( )
 
 (
 	s = sphere()
  	custattributes.add s testCA;
 
 	local instances = custAttributes.getDefInstances testCA;
 	for i in instances do (
 		local owner = custAttributes.getOwner i;
 		custAttributes.delete owner testCA;
 	)
 	custAttributes.deleteDef testCA;
 )

The last line always throws a runtime exception:
custAttributes.deleteDef - Cannot delete, objects still using this definition: <AttributeDef:testCA>

When I run getDefInstances after it again, I get 1 instance, but trying to get the owner of it returns undefined... I've tried doing a garbage collect before deleting the definition, but this does not help.
Also, I noticed that the getOwner does not seem to return a valid node, but some other kind of object. For example I can't query the name, and (isValidNode owner) returns false..

Any ideas what I'm doing wrong here?

Last edited by Pjanssen : 10 October 2011 at 03:13 PM.
 
  10 October 2011
Looks like it's hold up in memory but not released in any way. Weird.

-Johan
__________________
Online: LinkedIn
 
  10 October 2011
Yes indeed, and the garbage collector doesn't seem to be able to deal with it. I'm wondering whether that's my fault or Autodesk's though...
 
  10 October 2011
Originally Posted by Pjanssen: Yes indeed, and the garbage collector doesn't seem to be able to deal with it. I'm wondering whether that's my fault or Autodesk's though...



   testCA = attributes testCA attribID:#(0x42a4cdb9, 0x13c71b46) ( )
 
(
	s = sphere()
	custattributes.add s testCA

	instances = custAttributes.getDefInstances testCA
	for i in instances where (owner = custAttributes.getOwner i) != undefined do
	(
		custAttributes.makeUnique owner testCA
		custAttributes.delete owner testCA
	)
	custAttributes.deleteDef testCA
)
   


but it's Autodesk's fault anyway.

Last edited by denisT : 10 October 2011 at 10:00 PM.
 
  10 October 2011
Hm yes that works, curiously enough. Thanks for that.
Although the scene def does appear to stay in memory while the scene is open, but that's not a big problem. It is gone after saving and reopening the scene.
testCA = undefined
gc()
custattributes.getscenedefs()
--result:
--#(<AttributeDef:testCA>)


I have to say, the more I use custom attributes, the more they annoy me. Their behavior is so strange in so many places, or just plain broken...
 
  10 October 2011
Broken where? I use turm all the time since Max 4
__________________
Paul Neale
http://paulneale.com
 
  10 October 2011
Originally Posted by PEN: Broken where? I use turm all the time since Max 4


I'm using CA for many years too, but I can't say that I like it. Every time before using it I ask myself about any alternative way.
For example, I prefer to write a scripted plug-in to extend the Point helper with new parameters than add CA to the standard Point node.

OK... here is a sample why i don't like to use CA.
The biggest problem is the CA's update/override behavior. An earlier version of CA updates the latest one!
Define a CA:

 global globalCA = attributes globalCA attribID:#(0x1967, 0x0000000a) version:1
 (
 	parameters main rollout:main
 	(
 		paramA type:#boolean ui:ui_paramA
 	)
 	rollout main "Parameters"
 	(
 		label lb "version 1"
 		checkbox ui_paramA "Parameter A" 
 	)
 	on update do format "update: %\n" this.version
 )
 /*
  custAttributes.getPBlockDefs globalCA
  -- #(#(#main, 0, 0, #(#rollout, #main), #(#paramA, #(#type, #boolean, #ui, #(#ui_paramA)))))
  */
  


add the CA to a node and save max file...

Redefine the CA:

 global globalCA = attributes globalCA attribID:#(0x1967, 0x0000000a) version:2
 (
 	parameters main rollout:main
 	(
 		paramA type:#boolean ui:ui_paramA
 		paramB type:#boolean ui:ui_paramB
 	)
 	rollout main "Parameters"
 	(
 		label lb "version 2"
 		checkbox ui_paramA "Parameter A" 
 		checkbox ui_paramB "Parameter B" 
 	)
 	on update do format "update: %\n" this.version
 )
 /*
 custAttributes.getPBlockDefs globalCA
 -- #(#(#main, 0, 0, #(#rollout, #main), #(#paramA, #(#type, #boolean, #ui, #(#ui_paramA))), #(#paramB, #(#type, #boolean, #ui, #(#ui_paramB)))))
 */
 


create a node, add new CA...
merge the previous node from the file before...
the CA attribute will be changed to the previous version.
/*
   custAttributes.getPBlockDefs globalCA
   -- #(#(#main, 0, 0, #(#rollout, #main), #(#paramA, #(#type, #boolean, #ui, #(#ui_paramA)))))
   */
   

And there is no way to prevent this behavior.
 
  10 October 2011
Originally Posted by denisT: And there is no way to prevent this behavior.


Maxscript in Max 2012 has added version number handling for CA's during load ...


http://docs.autodesk.com/3DSMAX/14/...1BFC54-1629.htm

Quote: Custom Attributes Version Number Support On Loading

In previous versions, Custom Attribute definitions loaded from a file always replced the definitions in the scene. Starting with 3ds Max 2012, this will only happen if the version number of the definition from the loaded scene is higher than the current definition's version number. See this topic for implementation details.
__________________

PowerPreview: High Quality Nitrous Previews for 3ds Max 2012|2013|2014

[ Free Download (ScriptSpot) ]

Home of The Frogs | Online Portfolio

Last edited by spacefrog : 10 October 2011 at 05:15 PM.
 
  10 October 2011
Originally Posted by spacefrog: Maxscript in Max 2012 has added version number handling for CA's during load


yes... i know. but as i said i used CA for many years always fighting with this issue. max developers fixed it for 2012, but do you know how many users are still using max version < 2012?
 
  10 October 2011
Originally Posted by denisT:
testCA = attributes testCA attribID:#(0x42a4cdb9, 0x13c71b46) ( )
 
(
	s = sphere()
	custattributes.add s testCA

	instances = custAttributes.getDefInstances testCA
	for i in instances where (owner = custAttributes.getOwner i) != undefined do
	(
		custAttributes.makeUnique owner testCA
		custAttributes.delete owner testCA
	)
	custAttributes.deleteDef testCA
)
   

Just a quick reply, this solution doesn't entirely work.
Using custAttributes.makeUnique creates a new unique CA definition, and as a result the following delete does not do anything, because the owner no longer contains a testCA set. Yes the original definition is deleted successfully, but we now have one or more unique copies of it in the scene.
So I'm looking for another solution or a tweak to this solution.

Last edited by Pjanssen : 10 October 2011 at 03:07 PM.
 
  10 October 2011
Ok, I found a solution. It works, but no further comments...

testCA = attributes testCA attribID:#(0x42a4cdb9, 0x13c71b46) ( )

(
	s = sphere()
	custattributes.add s testCA;
 
 	local instances = custAttributes.getDefInstances testCA;
 	for i in instances where ((owner = custAttributes.getOwner i) != undefined) do
	(
		for caIndex = 1 to (custAttributes.count owner) do
		(
			if ((custAttributes.get owner caIndex).name == "testCA") do
			(
				custAttributes.makeUnique owner caIndex;
				custAttributes.delete owner caIndex;
			)
		)
 	)
	
 	custAttributes.deleteDef testCA;
 )


Ok one small comment then, it works after having saved the scene and restarted max. Until then, there's still a testCA attribute definition around. Even after setting testCA to undefined and garbage collecting.

@PEN: I think the above code answers your question better than I could have put it in words.

Last edited by Pjanssen : 10 October 2011 at 08:15 PM.
 
  10 October 2011
Originally Posted by Pjanssen:
Ok one small comment then, it works after having saved the scene and restarted max. Until then, there's still a testCA attribute definition around. Even after setting testCA to undefined and garbage collecting.

indeed, +1 !
__________________
* everyone can win previous war
 
  12 December 2011
OK, so they are a bit broken. The update issue with them isn't a bug but a work flow issue, glad it had been corrected but really like Denis said, many of my clients are still on back copies of Max and not 2012. The deleting of them I have not really worried about until now and just ran into it my self. The work around for me is to. It bother trying. Hey, if at first you don't succeed, give up.
__________________
Paul Neale
http://paulneale.com
 
  12 December 2011
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:12 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.