change connection line style using script

change connection line style using script

Postby nnako » Fri Apr 18, 2014 11:44 am

Hello,

I am trying to change the style of an arrow connection between two nodes from [plain] (default) to [dashed]. The context menu (opened by right click) shows the property "connection line", with which I can choose between several line styles for the connection. But I can not find the appropriate property or method to be used within a script. Neither the documentation for the "Scripting API" accessed using the top menu, nor the API description for connectors gives information about how to proceed.

Code: Select all
// make visible arrow connecton from "ref" node to "nodReference" node
def connector = node.children[i].addConnectorTo( nodReference )
      
// change the connector style to "dashed"
connector. ???


Any hint would be appreciated.
nnako
 
Posts: 10
Joined: Tue Jul 30, 2013 1:46 pm

Re: change connection line style using script

Postby boercher » Tue Apr 22, 2014 1:38 pm

Yes, only very few connector style properties are exposed via the scripting API. Please create a feature request in Mantis for the addition of more.

In the meanwhile you could use the underlying internal API which can be studied best starting from ConnectorProxy, the implementation of Proxy.Connector.

Volker
boercher
 
Posts: 644
Joined: Tue Jul 26, 2011 7:13 am

Re: change connection line style using script

Postby nnako » Sat Apr 26, 2014 9:29 pm

boercher wrote:In the meanwhile you could use the underlying internal API which can be studied best starting from ConnectorProxy, the implementation of Proxy.Connector.

I didn't fully get the hint about ConnectorProxy. Would the usage of it lead to an even better way of accessing the internal code? If you like, please explain it a bit further so I might understand. But I have found the basis for a solution in one of your former posts. Here the resulting script:

Code: Select all
import org.freeplane.features.link.ConnectorModel

// create new child node "nodReference" with formula content of node text
def nodReference = node.createChild( "=" + node.id + ".text" )

// set link "nodReference" node to selected node
nodReference.link.node = node

// run through whole set of children
for( i=0; i<node.children.size(); i++ )
{
  // check if child node with text "ref" is already existing
  if( node.children[i].text.matches( "ref" ) )
  {
    // make visible arrow connecton from "ref" node to "nodReference" node
    node.children[i].addConnectorTo( nodReference )
      
    // change the connector shape to "dashed"
    // @TODO: when function in scripting API is present => use scripting API function
    node.children[i].connectorsOut.each {
      ConnectorModel connectorModel = it.connector
      connectorModel.dash=[3,3]
    }

    // exit loop
    break
  }
}

// check if no child "ref" present
if( i == node.children.size() )
{
  // create new child node "ref"
  def nodArrowOut = node.createChild( "ref" )

  // set style of node "ref"
  //nodArrowOut.style.setName( "klein und grau" )

  // make visible arrow connecton from "nodArrayOut" to "nodReference"
  nodArrowOut.addConnectorTo( nodReference )

  // change the connector shape to "dashed"
  // @TODO: when function in scripting API is present => use scripting API function
  nodArrowOut.connectorsOut.each {
    ConnectorModel connectorModel = it.connector
    connectorModel.dash=[3,3]
  }
}


It produces two child nodes according to this picture:
Image
The calculated node can then be dragged to other places within the mindmap always referencing the original node through hyperlink, arrow link and calculated content. This is what I wanted.

Thank you.
Last edited by nnako on Wed Apr 30, 2014 3:04 pm, edited 1 time in total.
--
Windows 7 x64
nnako
 
Posts: 10
Joined: Tue Jul 30, 2013 1:46 pm

Re: change connection line style using script

Postby boercher » Wed Apr 30, 2014 2:53 pm

nnako wrote:I didn't fully get the hint about ConnectorProxy. Would the usage of it lead to an even better way of accessing the internal code?

not better, but programmers will find everything there what is needed to do what they want with connectors. The post you cite is an even simpler way to get you started.

Regards, Volker
boercher
 
Posts: 644
Joined: Tue Jul 26, 2011 7:13 am


Return to Open Discussion

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron