Home Wiki Blog Forum GEXF.net

Gephi forums

Community support

Exporting to pdf with toolkit gives empty page.

Once it's running

Exporting to pdf with toolkit gives empty page.

Postby hrududu » 23 Oct 2013 08:54

Hi, it's my first post. I'm attempting to test the features of the java/jython toolkit, but when I export to either pdf or png, I get an empty file. Any help would be greatly appreciated! Here is my code...I'm a total novice when it comes to jython.

This is the .gexf for a simple graph I made as a test.
Code: Select all
<?xml version="1.0" encoding="utf-8"?><gexf version="1.1" xmlns="http://www.gexf.net/1.1draft" xmlns:viz="http://www.gexf.net/1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">
  <graph defaultedgetype="undirected" mode="static">
    <nodes>
      <node id="1" label="1" />
      <node id="2" label="2" />
      <node id="3" label="3" />
      <node id="4" label="4" />
    </nodes>
    <edges>
      <edge id="0" source="1" target="2" />
      <edge id="1" source="1" target="3" />
      <edge id="2" source="1" target="4" />
      <edge id="3" source="2" target="3" />
    </edges>
  </graph>
</gexf>


Now, I use the following jython code to load the .gexf and hopefully print out a visual. I want to do some other stuff with the graph, but I'd like to get this working first. My code is the following:
Code: Select all
#import modules
import sys
import java.io
from org.openide.util import lookup
import org.gephi.project.api as project
import org.gephi.io.importer.api as importer
import org.gephi.io.exporter.api as exporter

#add toolkit to path
sys.path.append('C:/Program Files (x86)/Gephi-0.8.2/toolkit/gephi-toolkit.jar')

#some handles
lookup = Lookup.getDefault().lookup
def ProjectController():
    return lookup(project.ProjectController)
def ImportController():
    return lookup(importer.ImportController)
def ExportController():
    return lookup(exporter.ExportController)

#start session
pc = ProjectController()
pc.newProject()

#import .gexf file
f = java.io.File('/path/test.gexf')
container = ImportController().importFile(f) #This part seems to work, nodes/edges can be accessed etc.

#export to pdf/png...doesn't work...gives a blank file
ec = ExportController()
u = java.io.File('/outpath/test.png')
ec.exportFile(u)



Thanks for your help!
hrududu
 
Posts: 4
Joined: 23 Oct 2013 08:38
Location: United States

Re: Exporting to pdf with toolkit gives empty page.

Postby hrududu » 23 Oct 2013 19:37

The answer to my question is that it is not enough to just load the data. It also must be attached to the graph/workspace. These additional lines of code after importing do the trick:

Code: Select all
workspace = pc.getCurrentWorkspace()
import org.gephi.io.processor.plugin as processor
ImportController().process(container, processor.DefaultProcessor(), workspace)
hrududu
 
Posts: 4
Joined: 23 Oct 2013 08:38
Location: United States


Return to How-To and Troubleshooting

Who is online

Users browsing this forum: No registered users and 2 guests