[SOLVED] Creating a D-Former from script

Mike3DMike3D Posts: 87

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());

 

Post edited by Mike3D on

Comments

  • umblefuglyumblefugly Posts: 162
    edited August 17

     

    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:

     

    Scene.addNode(dForm);

    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:

    dForm.setDisplayWeights(true);

    Also, these lines should be removed:

    dForm.deleteLater();modifier.deleteLater();zone.deleteLater();

    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.

    Post edited by umblefugly on
  • umblefuglyumblefugly Posts: 162

    If you still can't get it to work, i'll share a possible solution.

  • Mike3DMike3D Posts: 87
    edited August 17

    Awesome ! It works perfectly smileyyes

    (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());

     

    Post edited by Mike3D on
  • umblefuglyumblefugly Posts: 162
    edited August 17

    Ugh pasting code here is a nightmare.
    But you are close:
    dForm.setName("D-Former");
    dForm.setLabel("D-Former");

    Post edited by umblefugly on
  • Mike3DMike3D Posts: 87

    Everything works perfectly now smiley

    Infinite thanks for the helping hand yes

  • umblefuglyumblefugly Posts: 162

    No problemo :D

Sign In or Register to comment.