How create Subnode URCAP

Hello guys, I have onde question about childNode/subNode in URCAP, my code in actual moment:

public void addAproximacaoSubNode() {
    float[] poseArray = installationContribution.getCapturedPoseArray();
    undoRedoManager.recordChanges(() -> {
        try {
            ProgramNodeFactory factory = programModel.getProgramNodeFactory();
            TreeNode thisNode = programModel.getRootTreeNode(this);
            URCapProgramNode aproxNode = factory.createURCapProgramNode(AproximacaoNodeService.class);
            thisNode.addChild(aproxNode);
        
            AproximacaoNodeContribution childContribution = aproxNode.getAs(AproximacaoNodeContribution.class);
            if (childContribution != null) {
                childContribution.setPose(poseArray);
            } else {
               System.err.println("Erro: Interface AproximacaoNodeInterface não implementada no nó filho.");
           }
        } catch (TreeStructureException e) {
            System.err.println("Erro ao adicionar o subnó de aproximação.");
            e.printStackTrace();
        }
    });
}

error:

the error is in line

  AproximacaoNodeContribution childContribution = aproxNode.getAs(AproximacaoNodeContribution.class);

I’m not able to call my subnode’s class, could anyone help me with a solution?

If I’m reading your stack trace right, it looks like it’s actually failing on addAproximacaoSubNode() (line 138) which would seem like it’s failing on

thisNode.addChild(aproxNode);

I would print the result of aproxNode just before that call and see if it’s coming back null or not. Regardless, I see what you’re trying to do and I don’t think it works that way. You have to implement a custom API interface to manipulate data in other nodes: URCap Sample: URCap CustomAPI

1 Like