I wrote some handlers for myself to deal with links - it is work in progress and it seems I will have to make some adjustments for the upcoming version of TBX - anyhow, just a playground for you:
// Link management
function changeTheLinks_db(theParamters:dictionary) {
// Parameters passed as a dictionary with type:value pairs
// changeAllLinks_db("target:/dummy;task:changeType;old:agree;new:disagree");
// changeAllLinks_db("target:dummy2;task:removeType;dir:out;typ:clarify");
// changeAllLinks_db("target:all;task:removeType;dir:out;typ:clarify");
// changeAllLinks_db("target:dummy2;task:addLink;typ:test;tonotes:[dummy;dummy3]");
if(!theParameters.empty){
var:string theTarget = theParamters["target"];
var:string theTask = theParamters["task"];
if(theTask == "changeType"){
var:string theOld = theParamters["old"];
var:string theNew = theParamters["new"];
if((theOld != "") & (theNew != "")){
eachLink(aLink, theTarget){
if(aLink["type"] == theOld){
aLink["type"] = theNew;
};
};
};
};
if(theTask == "removeType"){
var:string theDirection = theParamters["dir"];
var:string theType = theParamters["typ"];
if(theDirection == "out"){
eval(theTarget,"unlinkTo(all,'" + theType + "')" );
} else {
eval(theTarget,"unlinkFrom(all,'" + theType + "')" );
};
};
if(theTask == "addLink"){
var:string theType = theParamters["typ"].trim();
var:list relatedNotes = theParamters["tonotes"].replace("(\[|\])",""); ;
if(relatedNotes.count > 0) {
relatedNotes.each(relatedNote){
createLink(theTarget,relatedNote,theType);
};
};
};
};
};
// remove all links on all children of a note that have a specific type
// removeAllLinks_db("target:/Test/;typ:agree;dir:out;");
function removeAllLinks_db(theParamters:dictionary){
if(!theParameters.empty){
var:string startNode = theParamters["target"];
var:string theType = theParamters["typ"];
var:string theDirection = theParamters["dir"];
var:list allMyNotes = collect(children(startNode),$IDString);
var:string theParas = "";
if(!allMyNotes.empty){
allMyNotes.each(singleNote){
theParas = "target:" + $Path(singleNote) + ";task:removeType;dir:" + theDirection + ";typ:" + theType;
changeTheLinks_db(theParas);
};
};
};
};
There are only two functions for the link management: changeAllLinks_db() and removeAllLinks_db(). The first one offers different options - use the attribute “task” to define one of those like:
changeAllLinks_db("target:/dummy;task:changeType;old:agree;new:disagree");
Will change all links of the note “/dummy” with the type “agree” to the type “disagree”
changeAllLinks_db("target:dummy2;task:removeType;dir:out;typ:clarify");
Will remove all outbound links of the type “clarify” from the note “dummy2”;
changeAllLinks_db(target:all;task:removeType;dir:out;typ:clarify);
Will remove all links with the type “clarify” from the current note.
changeAllLinks_db(target:dummy2;task:addLink;typ:test;tonotes:[dummy;dummy3]);
Will add a link from note “dummy2” to the notes “dummy” and “dummy3”
and with removeAllLinks_db(“target:/Test/;typ:agree;dir:out;”); the outbound links of all children of note “/Test/” and the type “agree” will be removed.
This is work in progress and will be improved if the new version is out - have fun!