How to select face groups or facets programatically?

What I really want is to be able to select certain face groups (ie from Geometry Editor) and do some voodoo magic with them. The closest thing I saw was the DzSelectionMap and tried setting the node's selection map to that but it didn't do anything.

Comments

  • andya_b341b7c5f5andya_b341b7c5f5 Posts: 694
    edited July 2023

    I think you'll need to access the face groups via a DzFacetMesh object.  Parts of the following may be useful to you.

     

    // DAZ Studio version 4.15.0.2 filetype DAZ Script(function(){	try {		var oNode = Scene.getPrimarySelection();		var oObject = oNode.getObject();		var oShape = oObject.getCurrentShape();		var oFacetMesh = oShape.getFacetMesh();				// Create a face group		oFacetMesh.createFaceGroup("MyFaceGroup");		print("Facets = ", oFacetMesh.getNumFacets(), " face groups ", 			oFacetMesh.getNumFaceGroups());				print("Face groups...");		for (var i = 0; i < oFacetMesh.getNumFaceGroups(); i++) {			var faceGroup = oFacetMesh.getFaceGroup(i);			print(faceGroup.objectName, i);		}				// Add some facet indices to face group		for (var i = 0; i < oFacetMesh.getNumFacets(); i++) {			if (i % 3 == 0) { 				faceGroup.addIndex(i)			};		}		print("Face Group ", faceGroup.getName(), " count ", faceGroup.count(), "face group contents ", faceGroup.toList());				var oMaterial = new DzDefaultMaterial();		oMaterial.name = "My Material";		oMaterial.setLabel(oMaterial.name);		oShape.addMaterial(oMaterial); // will work		if(!oFacetMesh.createMaterialGroup(oMaterial.name)) {			print("Failed to create mat group");			return;		}				// Set contrasting colors on the two materials		var col = Color(255,0,0);		oShape.findMaterial("Default").setDiffuseColor(col);		col = Color(0,255,0);		oShape.findMaterial("My Material").setDiffuseColor(col);				oFacetMesh.deselectAllFacets();		// Select faces as defined in the face group				oFacetMesh.selectFacets(faceGroup);		selFacets = oFacetMesh.getSelectedFacets();		print("Facets selected via face group ", faceGroup.getName(), selFacets);				// Add the facets currently selected to the newly created material group		var newMgIdx;		for (i = 0; i < oFacetMesh.getNumMaterialGroups(); i++) {			if (oFacetMesh.getMaterialGroup(i).getName() == "My Material") {				newMgIdx = i;			}		}		oFacetMesh.addSelectedFacetsToMaterialGroup(newMgIdx);		print("Material group ", oFacetMesh.getMaterialGroup(newMgIdx).getName(), " contains facets ", 			oFacetMesh.getMaterialGroup(newMgIdx).toList());					// What is the result?		for (var i = 0; i < oFacetMesh.getNumFacets(); i++) {			f = oFacetMesh.getFacet(i);			// faceGroupIndex always returns 0 ?			print("Facet ", i, 				"face group index ", f.faceGroupIndex,				"material index ", f.materialIndex,				"material group ", oFacetMesh.getMaterialGroup(f.materialIndex).name)		}			} catch (err) {		debug("ERROR in MyScript (" + err.lineNumber + "): " + err);	}})();

     

    Post edited by andya_b341b7c5f5 on
Sign In or Register to comment.