Plot 3D blocks from Vorpal .in file (now with .stl files)

Following on from the last vorpal plotter I’ve updated things a bit. Instead of plotting everything in grid coordinates I’ve added a parser and appropriate conversion functions to plot everything in meters.

[scale, distanceOrigin, cellBounds, distanceBounds] = coords.getScales(file);

Where scale is the distance per cell; distanceOrigin is the position of grid position [0 0 0]; cellBounds is the boundary in cells; distance bounds is the same in meters.

Plot of pmlSlab.pre

This is a direct plot of Plot of pmlSlab.in using vorpal plotter.

Read More

Plot 3D blocks from Vorpal .in file

Vorpal lets you define several blocks using upper and lower bounds. Sometimes these are hard to visualise so it would be nice for the computer to do it for you. Sadly Tech-x don’t supply any means of doing this at this time. This is a little matlab script that takes an .in file and plots the blocks in 3D.

Vorpal Plotter

The output for an example geometry (you can see my mistakes).

At this time it can only plot blocks which are defined using coordinates but it could be altered to plot blocks defined using distances also. I’ve used plotcube for the drawing. As vorpal uses upper and lower bounds as opposed to origin and dimensions the coordinate systems need rearranging with bounds.m.

parser.m takes the in file you present it with (which must have been processed by txpp.py) and runs through looking for code blocks who’s type is in plotList (where a block is defined <type name>). It then plots it with the colour in plotColorList.

%set up a list of things to draw and their colors (ignore everything else
plotList = {'ParticleSink'};
plotColorList = {[1 0 0]};

In addition to plotcube the two files you need are in the archive: Vorpal Plotter

Read More

Turn lyx into a simulation lab-book (with clickable hyperlinks)

Lyx is pretty good with drag and drop support for images, but its pretty poor at linking to generic local files. Having tried (and failed) to find a half decent bit of lab-book software I hacked lyx about allow it to do the last 5% of what needed to be done to make it work properly.

Lab book example

A (poor) example of what this setup produces

If you set up two relativly simple sets of scripts then you can drag and drop files straight into lyx (via a drop target) and then right click on the hyperlink to launch it in windows (I’ve not tried this with a linux machine, the last set of scripts almost certainly won’t work).

Read More

Drag and Drop files into Lyx to create links

It’s sometimes handy to drag and drop files into Lyx and have it do something of value. This works pretty well for images but not at all for generic files. You can add something like the same functionality using a simple python script and the lyx pipe.

Dropping a file on the drop target generates the code above (it even adds the right image if there is one)

Make sure the Lyx server is switched on http://wiki.lyx.org/LyX/LyXServer#toc4, and restart Lyx to make sure it is running.

Create a python file called dropper.py and copy in the source. You also need python 2.6ish and wxPython installed.

import wx, os

# perform the appropriate operations in lyx with the
def dealFile(file):
 #the adequately escaped lyx pipe
 lyxServer = "\\\\.\pipe\lyxserver.in"

 aFile = file.split('.')
 if(len(aFile) == 1):#it's a folder
 aFile = [aFile[-1], 'fld']
 print aFile

 #insert a picture with an image of ext.png
 command = "echo LYXCMD:dropper:inset-insert:graphics lyxscale 10 width 1.2em height 1.2em keepAspectRatio filename $DROPPER_IMAGES$/image/"+aFile[1]+".png>>"+lyxServer
 print(command)
 os.system(command)

 # put in a space
 command = "echo LYXCMD:dropper:self-insert: >>"+lyxServer
 #print it for debugging and send it to the os
 print(command)
 os.system(command)

 # insert the hyperlink
 aFile = file.split('\\')
 command = "echo LYXCMD:dropper:inset-insert:href LatexCommand href name "+aFile[-1]+" target \""+file+"\" type \"file:\" \end_inset>>"+lyxServer
 #print it for debugging and send it to the os
 print(command)
 os.system(command)

# the drop target
class MyFileDropTarget(wx.FileDropTarget):
 def __init__(self, window):
 wx.FileDropTarget.__init__(self)
 self.window = window

 # when a file is dropped print its name and hand it to dealFile()
 def OnDropFiles(self, x, y, filenames):
 for file in filenames:
 self.window.AppendText("%s\n" % file)
 dealFile(file)

# the application frame
class MyFrame(wx.Frame):
 def __init__(self):
 #set it all up
 wx.Frame.__init__(self, None, title="Drop Target",size=(200,200))
 p = wx.Panel(self)

 label = wx.StaticText(p, -1, "Drop some files here:")
 text = wx.TextCtrl(p, -1, "",style=wx.TE_MULTILINE)

 sizer = wx.BoxSizer(wx.VERTICAL)
 sizer.Add(label, 0, wx.ALL, 5)
 sizer.Add(text, 1, wx.EXPAND|wx.ALL, 5)
 p.SetSizer(sizer)

 #put in the drop target
 dt = MyFileDropTarget(text)
 text.SetDropTarget(dt)

# run the windowed script
app = wx.PySimpleApp()
frm = MyFrame()
frm.Show()
app.MainLoop()

Make sure you replace $DROPPER_IMAGES$ by a path to an image directory with thumbnails in. These need to be in the form extension.png.

There is a bug in Lyx before 1.6.8 which duplicates the final character of an image when it is inserted by the dropper. All images end up being called extension.pngg.

Note: The basis for this script is from an example site, can’t remember which one though… The Lyx code is the interesting part (as far as it goes).

Read More

Lyx clickable hyperlinks

If you are trying to use lyx as a lab-book (like me) then it’s quite handy to link to local files. You can do this with a hyperlink but the pdf viewers support of these can be a bit limited (for very good reason). You can however persuade lyx to lauch the links pretty effectively.

If you click edit externaly then lyx has a crack at launching it

Read More