ZBrushCentral

? Can i get the poly count or verex count of a group

Hi.

I’m in need for a script that deletes some parts of an imported model.

It should take the selected tool.
Duplicate it.
Auto group it.
Then I want to iterate the created groups and by some mean identify the groups i want to delete by the number of polygons or the number of vetices, select the group and then delete it.
Then rename the subtool.

Is this possible?
The auto grouping, duplication and renaming I’m quite sure is possible but can I get access to polygon or vertex count. I have not found anything about that in the references.

Edit:
Thought I could get the count from it from the Activepoints info in the interface but cant get it to work.
Maybe I can get it from Mesh3DGet?

Still have to figure out how to iterate the polygroups.
Anyone that has a tip on how to do that?

Arrgh, anyone that has any help to offer?

Hi,

I am not sure about iterating through the polygroups, I could be wrong (have a bit of a fever and cold right now) but I am afraid it is not possible without resorting to a dynamic library. That would involve importing the model into ZBrush, applying Tool > Polygroups > Auto Groups and then exporting as .obj where your .dll/.lib would then handle the file. If Tool > Export > Grp is enabled I believe the polygroups are assigned as groups in the .obj file.

You are correct about [Mesh3DGet,…]. It would go something like this:

[VarSet, vertCount, 0] [VarSet, polyCount, 0] [Mesh3DGet, 0, , , vertCount] [Mesh3DGet, 1, , , polyCount] [Note, [StrMerge, "Vertices: ", vertCount, " Polygons: ", polyCount]]

The code above will show the vertex and polygon count of the currently selected subtool. If you need the total vertex or polygon count you can iterate through the subtools or use [IGetInfo,…] on the currently selected tool (not subtool). This will return the text you see when the cursor is over the tool icon. Using [StrFind,…] and [StrExtract,…] you can get the total point and polygon count, like so:

[VarSet, info, [IGetInfo, 29901]] // 29901 is the currently selected tool [VarSet, find1, [StrFind, "TotalPolys", info]] [VarSet, find2, [StrFind, "TotalPoints", info]] [VarSet, find3, [StrFind, "TotalHiddenPolys", info]] [VarSet, totalPolyCount, [StrExtract, info, find1 + 11, find2 - 2]] [VarSet, totalVertCount, [StrExtract, info, find2 + 12, find3 - 2]] [Note, [StrMerge, "Total Vertices: ", totalVertCount, " Total Polygons: ", totalPolyCount]]

Hope that helps a little.

May be of some use… http://www.zbrushcentral.com/showthread.php?193088-Small-script

Thank’s for helping out.

Main idea is to split a model, in this case a DAZ model, in parts and rename them.

I have noticed that sometime i lose UV in splits or merge so plan was to make duplicates and then remove polygroups not wanted as I know the retained UVs.

Looking for a workaround I have found that Slit Similar also retain UVs as well a keeping both eyes in same subtool witch I want.

I suppose I can iterate the subtools and rename those that has the expected number of points that want to keep and delete other.

Update:
From what I can figure out it’s not possible to rename subtools in an easy direct way.
Feels as zScripting really is lacking in usability :frowning:

Suppose I have to continue to do It manually.
At least the Split Similar will save me some time :slight_smile:

Only thing I wont get right working this way is the mouth that I want to keep as one subtool but as it get split into several and I cant merge the parts back without losing Uvs I guess I just have to handle that one manually.

Unfortunately there are some instances where zscripting loses focus, such as when a rename subtool or rename layer dialog window appears. However, if you are on a Mac I could try out an idea I had for renaming using a dynamic library. Let me know if you are interested.

You can rename the top subtool by using [ToolSetPath]. For the other subtools, either you can move them to the top to rename or alternatively here’s a simple hack. If you import an empty file with a “.dat” extension then the subtool will be renamed to the file name:

[RoutineDef,NameSubTool,
[If,[MemGetSize,SubT_Namer],[MemDelete,SubT_Namer]]//make sure this memory block isn’t around
[MemCreate,SubT_Namer,16]//create memblock
[VarSet,newS,[MemWriteString,SubT_Namer," ",0,0]]//write empty string
[MemResize,SubT_Namer,newS]//resize memblock
[MemSaveToFile,SubT_Namer,#newName]//save to file
[MemDelete,SubT_Namer]//delete memblcok
,newName]//end routine

[VarSet,newFile,“My_SubTool.dat”]
[RoutineCall,NameSubTool,newFile]
[FileNameSetNext,#newFile]
[IPress,Tool:Import]
[FileDelete,newFile]

Unfortunately there are some instances where zscripting loses focus, such as when a rename subtool or rename layer dialog window appears. However, if you are on a Mac I could try out an idea I had for renaming using a dynamic library. Let me know if you are interested.

Sorry, but I’m not on a Mac.
Thank’s for offering to help :slight_smile:

[RoutineDef,NameSubTool,
[If,[MemGetSize,SubT_Namer],[MemDelete,SubT_Namer]]//make sure this memory block isn’t around
[MemCreate,SubT_Namer,16]//create memblock
[VarSet,newS,[MemWriteString,SubT_Namer," ",0,0]]//write empty string
[MemResize,SubT_Namer,newS]//resize memblock
[MemSaveToFile,SubT_Namer,#newName]//save to file
[MemDelete,SubT_Namer]//delete memblcok
,newName]//end routine

[VarSet,newFile,“My_SubTool.dat”]]
[RoutineCall,NameSubTool,newFile]
[FileNameSetNext,#newFile]
[IPress,Tool:Import]
[FileDelete,newFile]

Thank’s.
Might try your “hack” :slight_smile:

Thanks Marcus, I am going to archive that one.

If anyone is curious the Mac .lib idea worked fine for changing subtool / layer names. The only problem is the variable delay when using zscripting to press Tool > Subtool > Rename and when the dialog window appears. So i added a generous 1 second safety net which of course would result in a 20 second execution time when renaming 20 subtools. But it works :lol:

In any case, it is possible to instantiate a class that creates an NSTimer which will call a method after you have pressed the Rename button in ZBrush. That method would then use CGEventCreateKeyboardEvent and CGEventPost for each character (terminating with the return key). Might still be useful for renaming layers but the hack Marcus showed is probably preferable for subtools.

Mark,

I’d like to try your solution for renaming layers on Mac, if you’re happy to let me test. I’ve thought that something like that might work but hadn’t had time to try some code.

Cheers,

Marcus,

Sure, but i’ll have to implement a per character interpreter first. What I have right now is just a proof of concept that changes every name to MO.

I tried putting the new name into NSPasteboard but I simply cannot simulate a CMD + V keypress to paste the name, which would have made things much easier. I don’t believe it is anything specific to ZBrush; I cannot simulate CMD + V in other apps either. Seems like a change/bug in Yosemite (or earlier) as the Apple documentation and examples online indicate it should work.

When it is ready I will create a new thread and paste the code there.

Thanks Mark, I shall look forward to that.

I have tried using NSPasteboard myself but after trying various things simply used it to make renaming layers a little easier.

For completeness sake here is the solution for renaming subtools / layers on Mac using a Dynamic Library .

Hi Marcus

I was wondering why you write the “.dat” and not just the name. I this something to do with where the util wrights the string out?:
[VarSet,newFile,“My_SubTool.dat”]]

It has to be a valid file name or ZBrush will give an error. (Though I discovered that you don’t actually need the file to exist.)

So does it actually wright it somewhere on disc, or just stays in memory? Cause it does feel like a genius approach :slight_smile:

Actually, this morning it’s not working, for some reason. So stick with the code above that creates an empty file. That is reliable.