[SOLVED] Creating a D-Former from script
I'm trying to create a D-Former from script.
I can either trigger the 'DzNewDFormerAction' action, or create a DzDForm object.
As I want a 'silent' creation (no user interaction), I can't use first solution (action trigger).
When trying to create a DzDForm object from script, the other components (base, modifier & zone) are also created, but the setup seems incomplete :
- the modifer ('D-Former') is not selectable (not highlighted) in the Scene pane and can't be deleted
- no colored vertices are shown in the viewport, even after setting zone influence to 'Sphere'
Maybe a complementary action is required to complete the setup ?
Code to reproduce the issue (with a figure or primitive selected in the Scene pane) :
(function(tgt){
// Create new D-Former
var dForm = new DzDForm();
dForm.setName('D-Former');
dForm.applyToNode(tgt);
// Get modifier
var modifier = dForm.getModifier(0); // DzDFormModifier
print(modifier);
var zone = dForm.getZone(); // DzDFormZone ('Field' in Scene pane)
zone.setInfluenceMode(DzDFormZone.Sphere);
dForm.deleteLater();
modifier.deleteLater();
zone.deleteLater();
})(Scene.getPrimarySelection());

Comments
I think the issue is that new DzDForm() creates the D-Former object, but it does not perform all of the setup that the normal New D-Former action does.
applyToNode() creates/applies the modifier to the target, but the D-Former itself still needs to be added to the scene:
Without that, the associated objects exist, but the Scene pane and viewport do not fully treat the D-Former as an active scene object.
The colored vertex display is also separate and can be enabled with:
Also, these lines should be removed:
because they schedule the objects that were just created for deletion.
So in short, DzNewDFormerAction appears to do some additional scene/display setup beyond simply constructing a DzDForm and calling applyToNode(). When creating one silently from script, those extra steps need to be done manually.
If you still can't get it to work, i'll share a possible solution.
Awesome ! It works perfectly

(function(tgt){ // Create new D-Former var dForm = new DzDForm(); dForm.setName('D-Former'); dForm.applyToNode(tgt); // This also creates a new DzDFormModifier Scene.addNode(dForm); // Get modifier & set weights var modifier = dForm.getModifier(0); // DzDFormModifier modifier.setInfluenceWeights(new DzWeightMap()); })(Scene.getPrimarySelection());Ugh pasting code here is a nightmare.
But you are close:
dForm.setName("D-Former");
dForm.setLabel("D-Former");
Everything works perfectly now
Infinite thanks for the helping hand
No problemo :D