Align Nodes

Apologies if this isn't the correct format to show code...

I found a sample code that will align selected nodes, and I tweaked a bit to align Origins not Centers. The script below shows no errors (I added a print statement in the IF statement if the doAlign was successful), but it doesn't do anything. However the D|S Align action works fine.

Anyone know what it's missing?

	// Set the X axis options	oAligner.setXAlign( DzNodeAligner.AlignXOrigins );	oAligner.setXUnits( 1, DzNodeAligner.UnitsFT );	oAligner.setXUseInterval( true );		// Set the Y axis options	oAligner.setYAlign( DzNodeAligner.AlignYOrigins );	oAligner.setYUnits( 1, DzNodeAligner.UnitsFT );	oAligner.setYUseInterval( true );		// Set the Z axis options	oAligner.setZAlign( DzNodeAligner.AlignZOrigins );	oAligner.setZUnits( 1, DzNodeAligner.UnitsFT );	oAligner.setZUseInterval( true );		// If alignment is possible	if( oAligner.canAlign() ){		// Start capturing changes		beginUndo();		// Perorm the alignment; if it is not successful		if( !oAligner.doAlign() ){			// Cancel/Purge the collection of changes			cancelUndo();		// If alignment is successful		} else {			// Add the undo to the stack			acceptUndo( "Align Nodes" );			print ("Alignment was successful");		}

 

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,905
    edited February 2021

    I imagine it's the doAlign() code that is crucial. I assume the "found" code is http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/nodes/node_align/start , in whichc ase the license requires that you acknowledge and link to the source.

    Post edited by Richard Haseltine on
  • ebergerlyebergerly Posts: 3,255

    Yes, I found this code for DAZ Studio scripts in the DAZ Studio documentation where they have sample scripts that show you how to write scripts in DAZ Studio. And the link is the link you provided.

    Now that we have the important stuff out of the way, yes, doAlign is the method/function that does the alignment. However, it doesn't seem to be doing the alignment in the same way the Align tab does it. Hence my question. Considering this sample script was written for D|S 4.10, I'm guessing maybe doAlign has changed in recent years? 

  • It seems to eb the Y alignment option that is causing the problem - I can change the others to Align..Centers and it works.

  • ebergerlyebergerly Posts: 3,255

    Even if I comment out the Y align code in the script the other two do nothing. But if I then leave the objects both selected and jump over to the Align tab it works fine. Weird.

  • OmnifluxOmniflux Posts: 377

    @ebergerly I don't see where you call oAligner.addNode() for the nodes you are trying to align. Did you miss this step, or just not paste it in this post?

  • ebergerlyebergerly Posts: 3,255
    edited February 2021

    Omniflux said:

    @ebergerly I don't see where you call oAligner.addNode() for the nodes you are trying to align. Did you miss this step, or just not paste it in this post?

    Yeah, it's there, I just didn't post the entire thing. The full script is at the link provided by Richard.

    BTW, on the last line of the script I posted was a modification I made to print to the terminal if it was successful in detecting two nodes to align, and when I run the script it prints out, so I assume the issue lies elsewhere. 

    Post edited by ebergerly on
  • ebergerlyebergerly Posts: 3,255

    Okay, it looks like a couple of the Align parameters were messed up in the original code. Not sure why, but if I comment them out it works fine.

    	// Set the X axis options	oAligner.setXAlign( DzNodeAligner.AlignXOrigins );	//oAligner.setXUnits( 1, DzNodeAligner.UnitsFT );	//oAligner.setXUseInterval( true );

     

    The setXUnits and setXUseInterval were the culprits. Still trying to figure out why though...

Sign In or Register to comment.