Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get patches, nodes and links #466

Open
Meetem opened this issue Dec 28, 2018 · 2 comments
Open

Get patches, nodes and links #466

Meetem opened this issue Dec 28, 2018 · 2 comments

Comments

@Meetem
Copy link

Meetem commented Dec 28, 2018

Hello.
I've just became RPD newbie, and looking for functions for get patch, nodes or links out of Rpd. It's easy to store created patch by

patch = Rpd.addPatch('Name of the Patch');

but I can't figure out how to get patch which has been imported from json or plain-text.

This code below imports patch (with fix #464) and then creates a new patch with right name but different id, so it can't be used for control imported path.

Rpd.import.plain(fileContent.toString());
patch = Rpd.addPatch('Name of the Patch');

I've searched for it in docs but found nothing about.

@Meetem
Copy link
Author

Meetem commented Dec 28, 2018

Ok, I've just figured out how to make this work, but you need to change some code in rpd.js

First, you need make function return import spec

return spec;

inside import function

Rpd.import.plain = function(lines)

or

Rpd.import.json = function(json)

Then you need to modify return of makeImportSpec function, like this:

return {
        patches: patches,
        nodes: nodes,
        inlets: inlets,
        outlets: outlets,
        links: links,

Now you can use result of import function and get patch by id like this:

    imported = Rpd.import.plain(fileContent.toString());
    patch = imported.patches['d08w'];
    //or just select first
    patch = imported.patches[Object.keys(imported.patches)[0]];

I'am not sure is it right way to get imported things, but at least this method works for me.

@Meetem
Copy link
Author

Meetem commented Dec 28, 2018

So there is some behaviour you should know about.
If you get export function for json/plain, then it will works like diff (previous commands, created nodes e.t.c won't be included into export file).
Then after you call export function it will unsubscribe from all future events, and you should obtain export function again like

var exportFunc = Rpd.export.plain('Patch name');

but previous events will not be included in new export file.
If you want to get export work without unsubscribing go to
Rpd.export.plain\json and comment knownEvents.offValue(pushCommand); line in return function.
You may also like to fix plain export move duplication, then you need to modify return value of Rpd.export.plain to

/* uncomment if you want use unsubscribe as function argument
if(unsubscribe === true) 
    knownEvents.offValue(pushCommand);
*/

var prevLines = lines.slice(0);
storeMoves();

var text = lines.join(COMMAND_SEPARATOR);
lines = prevLines;
return text;

BUT I don't know how to get current patch/nodes/links without importing them or listen to Rpd.events (this method is not really comfortable to use for obtain information)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant