Setting material selection state

I want to chnage the selection state of a material, but DzMaterial.select( true ) doesn't seem to do anything. I can get the selection state, so I think I am working on the correct property. This is a cut down version of the code - I have used a print() to make sure it is getting to the section that should be changing the selection state.

	// node obtained from elsewhere		var object = node.getObject();	if ( object == null ) {		// no mesh so quit		return;	}		// try to get the object's current shape	var shape = object.getCurrentShape();	if ( !shape ) {		// also no geometry so quit		return;	}		// try to get the shape's material list	var materials = shape.getAllMaterials();	if ( materials.length == 0 ) {		// no materials, so quit		return;	}		for ( var n = 0 ; n < materials.length ; n++ ) {		// Other code goes here		materials[ n ].select( true );	}

Is this a typo, misunderstanding, change in the commands, or a bug?

Comments

  • Odd, now it is working. I don't know if I was getting my fingers in a muddle earlier, the code hasn't changed. Anyway, please ignore.

  • And now I am going to take back my retraction - it works some of the time, but not all. I'm not sure it's consistent even then but I think it is working in the release build. I will poke some more at the beta.

  • djigneodjigneo Posts: 283

    Your code should work, though in my experience the code only works if the Scene selection (Scene.getSelectedNodeList()) includes the object node you're wishing to select surfaces on.

    Using your code snippet, it works if the node is highlighted and doesn't work if it's not.

  • My results weren't even that consistent, I don't think, though I was getting a bit muddled (as the number of posts indicates).

  • djigneodjigneo Posts: 283

    I can tell you I have scripts that I use on a daily basis that use similar code and it's consistently behaved as I've described above. I have an explicit Scene.setPrimarySelection() before the material selection bit, so the subsequent DzMaterial.select(true) works.

  • OK, thank you - that's a useful workaround.

Sign In or Register to comment.