ZBrushCentral

Question: Help with Polygroups context-based scripting?

Is there any script floating around somewhere that makes context-based decisions on Polygroups in ZBrush? Something that would do the Auto Groups function normally, and if the user created a mask, it would instead do Group Masked. Doesn’t need to do exactly this i suppose, if it’s similar I could Frankenstein it myself.

Here’s a script that will do what you want, and that will perhaps serve as a model for other stuff. The main problem here is checking if there’s a mask. The script has to test this by seeing if the unmasked part of the mesh can be hidden - not ideal but the best I could think of.

[RoutineDef,CheckIsMasked,
	[IFreeze,
		[If,[IExists,Tool:Visibility:HidePt],
			[IPress,Tool:Visibility:HidePt]
			[If,[IsEnabled,"Tool:Visibility:Grow"],
				[VarSet,isMasked,1]
				,
				[VarSet,isMasked,0]
			]	
			[IPress,Edit:Tool:Undo]
		]
	]
,isMasked]


[IButton,"Group It","Create a new Polygroup using AutoGroups or Mask",
	[VarSet,isMask,0]	
	//check we can actually use Group Masked (it's a polymesh or zsphere in preview mode)
	[If,[IExists,Tool:Masking:Group Masked]&&[IsEnabled,Tool:Masking:Group Masked],
		[RoutineCall,CheckIsMasked,isMask]
		[If,isMask,//it's masked so use Group Masked
			[IPress,Tool:Masking:Group Masked]
			,//else no mask - AutoGroup
			[IPress,Tool:Polygroups:Auto Groups]
		]	
	]
]

HTH,
Marcus

Hi Marcus, thank you for your sharing of this. However, if I save this to my Macros folder and restart ZBrush (2021), I don’t see this script appearing amongst my Macros. Does this not mean the script has errors and is not being read on startup properly?

EDIT: Nevermind, I was being a donkey. Thank you again Marcus, this is exactly what I was asking for :slight_smile: You are amazing.

Hi Justo,

I’m glad you got it working and it’s what you want! :slight_smile:

For the benefit of anyone else wondering about macros, they use ??? instead of the button name, so this line in my code:

[IButton,"Group It","Create a new Polygroup using AutoGroups or Mask",

for a macro becomes:

[IButton,???,"Create a new Polygroup using AutoGroups or Mask",

-Marcus

1 Like