ZBrushCentral

Scaling Problem

Hey all,

i have another little problem with a plugin i am currently working on. I try to create a routine to scale all subtools somewhat similar to the unify scale button of scale master. I need that routine to make other parts of the plugin work bug-free.

My goal is to scale all subtools and their position by a certain factor. Example: You have a character that consists of 20 subtools and i want to make it a fifth of it’s size.

I try to do that by getting the values of the Position and Size Sliders in the Geometry Tab, multiply them with my scaling factor and then set the sliders to the new values. This routine is executed as a loop through all subtools.

The problem: When i do all this by hand without a script everything works perfectly. Now when i run my script ZBrush scales everything weirdly. Some subtools even become bigger and everything is a mess. Now when i go into the history of each subtool i recognize that the position and size sliders are somhow linked to each other. When i go back in the history and move one of the sliders, the others move too. Does anyone know what is going on here and how i can solve this? I have absolutely no idea what’s wrong here.

Here’s my code (Note commands are for debugging purposes):

[Loop, totalSubtools,
    [SubToolSelect,[Val,n]]
    //[Note, "Current Subtool"]
    //[Note, [Val,n]]

           /// Set Scaling Factor to 0.5
          [VarSet, ScalingFactor, 0.5]

           /// Get X, Y, Z Positions and XYZ Size in Geometry Tab
	[VarSet, OldXPosition, [IGet,Tool:Geometry:X Position]]
	[VarSet, OldYPosition, [IGet,Tool:Geometry:Y Position]]
	[VarSet, OldZPosition, [IGet,Tool:Geometry:Z Position]]
	[VarSet, OldXYZSize, [IGet,Tool:Geometry:XYZ Size]]

	[VarSet, NewXPosition, OldXPosition*ScalingFactor]
	[VarSet, NewYPosition, OldYPosition*ScalingFactor]
	[VarSet, NewZPosition, OldZPosition*ScalingFactor]
	[VarSet, NewXYZSize, OldXYZSize*ScalingFactor]

	//[Note, [StrMerge, "Old X: ", OldXPosition, "\nOld Y: ", OldYPosition, "\nOld Z: ", OldZPosition, "\nOld XYZ Size: ", OldXYZSize]]
	//[Note, [StrMerge, "\nNew X: ", NewXPosition, "\nNew Y: ", NewYPosition,"\nNew Z: ", NewZPosition, "\nNew XYZ Size: ", NewXYZSize]]


	[ISet,Tool:Geometry:XYZ Size, NewXYZSize]
	[ISet,Tool:Geometry:X Position, NewXPosition]
	[ISet,Tool:Geometry:Y Position, NewYPosition]
	[ISet,Tool:Geometry:Z Position, NewZPosition]
	
,n]

Thanks in advance!

I agree there’s something odd about scripting those sliders. I’m not entirely sure this is reliable so use with caution but try this:

[VarDef, NewXPosition, 0]
[VarDef, NewYPosition,0]
[VarDef, NewZPosition,0]
[VarDef, NewXYZSize, 0]
	

[IButton,ScaleDown,"Do it",
	[Loop, [SubToolGetCount],
    [SubToolSelect,[Val,n]]   
    [VarSet, ScalingFactor, 0.5]
		[If,(n==0),
		  // Get X, Y, Z Positions and XYZ Size in Geometry Tab
			[VarSet, OldXPosition, [IGet,Tool:Geometry:X Position]]
			[VarSet, OldYPosition, [IGet,Tool:Geometry:Y Position]]
			[VarSet, OldZPosition, [IGet,Tool:Geometry:Z Position]]
			[VarSet, OldXYZSize, [IGet,Tool:Geometry:XYZ Size]]
		
			[VarSet, NewXPosition, OldXPosition*ScalingFactor]
			[VarSet, NewYPosition, OldYPosition*ScalingFactor]
			[VarSet, NewZPosition, OldZPosition*ScalingFactor]
			[VarSet, NewXYZSize, OldXYZSize*ScalingFactor]
		]
		[ISet,Tool:Geometry:XYZ Size, NewXYZSize]
		[ISet,Tool:Geometry:X Position, NewXPosition]
		[ISet,Tool:Geometry:Y Position, NewYPosition]
		[ISet,Tool:Geometry:Z Position, NewZPosition]	
,n]
]

I imagine there is something going on under the hood that treats scripted values in a different way. If I remember correctly, it only happens when using [SubToolSelect] and using [IPress,Tool:SubTool:SelectDown] everything works as expected. Anyway, have fun testing or alternatively use the Tool>Deformation>Offset/SCale sliders!

-Marcus

Hey Marcus,

thanks a lot for your answer and the hint! I will definetely try that and see if it works!

All the best!

1 Like