Adding a messages function in VBA for Excel

A quick script for debugging in Excel. Works like a “print” command in a command line interface – just add Msg(~) comments in your VBA code where you want to know what it’s thinking, and the script will return a line. Newest comments appear at the top. Much more useful than using message boxes! Continue reading Adding a messages function in VBA for Excel

Create keyboard shortcuts for coding in C# using AutoHotKey

AutoHotKey is a remarkably useful piece of free software which allows you to automate any repetitive keyboard or typing task. It effectively allows you to program any key, or any combination of keys, to any command of your choosing.

Here, I will show how to use AutoHotKey to make writing C# code a little faster and easier.

Continue reading Create keyboard shortcuts for coding in C# using AutoHotKey

Film course day at Bristol, 6th Aug

A great problem for academics and those in highly technical professions is trying to communicate what they actually do in terms that the wider public can understand. Quite often, such people can explain their research in wonderfully deep detail that sounds fascinating to anybody already in the know, but there will always come a time when it is necessary to get somebody non-technically-minded excited about your work.

Continue reading Film course day at Bristol, 6th Aug

Setting up Visual Studio Express 2012 and 2013 to write your own Grasshopper components in C#

A quick guide for setting up Visual Studio Express for developing Grasshopper components for Rhino 5. Continue reading Setting up Visual Studio Express 2012 and 2013 to write your own Grasshopper components in C#

A simple deflection analysis in ANSYS 13

ANSYS is a highly advanced program for performing a wide range of analyses based around a finite element analysis engine. Thanks to its well-developed feature set in static, non-static and CFD problems, it is well-used by mechanical engineers and the like, but less so in structural engineering, where programs such as Robot and GSA are preferred. However, a recent task called for a quick deflection analysis of a prototype building form, which turned into an opportunity to try out this program. Continue reading A simple deflection analysis in ANSYS 13

Data trees and C# in Grasshopper

Understanding how Grasshopper handles data is crucial for taking full advantage of GH’s capabilities. For collections of data, they can either be in the form of lists or trees.

A list is a collection of items of data, in a particular order, but with no hierarchical structure. Here is a list of numbers:

Grasshopper list of numbers with series component

The component in the top-right is the param viewer. Double click it to see this:

Grasshopper series list with param viewer

The ‘N’ denotes a list with N items. A list can be thought of as a tree with a single branch {0}. So here, we are looking at a single list, with address {0}, containing 5 items.

A tree is any data structure in GH with multiple branches. In other words, it’s a data structure with multiple lists. Each list has its own address.

Now, let’s make a grid of points. We can do this with our list of numbers and the ‘construct point’ component.

Grasshopper construct grid of points

Here, we have cleverly grafted the Y input to coerce Grasshopper into giving us 25 points for our list of 5 numbers. But the output looks a little different. Instead of a list of 25 points, we have 5 groups of 5 points each.

What’s happened here is that Grasshopper has created 5 branches. Each branch contains a list of 5 points. Each branch has its own address {0} to {4}, shown in the panel.

We can verify this using the param viewer.

Grasshopper param viewer for trees

Trees in C#

Trees can be created and manipulated in C# components too. When we add data to a tree in C#, we need two pieces of information:

  • The data we are saving, such as a Point3d or an integer
  • The path we are saving to

The path is declared as a list of numbers denoting the sequence of the branches needed to access the list we are interested in. As some examples:

DataTree<Point3d> myTree = new DataTree<Point3d>();
GH_Path pth = new GH_Path(2);
myTree.Add(P, pth);

point P will be written to the list at the end of branch 2.

GH_Path pth = new GH_Path(i,j)

point P will go down branch i, then be added to the list at the end of branch j

Setting up a tree

You can either add to a tree on the fly – if you know that the data in the tree will be in the same order that you’ll be adding to it. But a more flexible way is to create a blank tree of the size you want, and then edit the values later.

Setting up a tree called boolTree (I am creating a tree based upon another tree called pts):

//declare tree
DataTree<bool> boolTree = new DataTree<bool>();
//set up tree
 for(int i = 0; i < pts.BranchCount;i++)
 {
   GH_Path pth = new GH_Path(i);
   for (int j = 0; j < pts.Branch(0).Count;j++)
   {
     boolTree.Add(false, pth);
   }
 }

This has now created a tree filled with ‘false’.

Editing values in the tree

boolTree.Branch(1,2)[5] = true;

This edits the 5th value of the list at the end of branch 1, sub-branch 2 to ‘true’.

My first post

Hello! It looks like I’ve decided to start a blog. I’ll hopefully be writing about what I’m getting up to in my EngD and all the wonderful and interesting things I’ll be learning about, and if I have anything else to babble about, who knows, it may end up on here too.

As for my first post, I should probably give some actual content. Here is a picture of a duck:

Image

(Made in Rhino, a program for modelling with curved surfaces. This was my greatest and proudest achievement in my first week!)

Taking the Trans-Siberian from Moscow to Beijing

This is a throwback to my travels in 2010 when I spent 4 months travelling around Europe and Asia. This is taken word-for-word from my TravelPod blog that I kept at the time, and have just re-discovered.

This post starts as I boarded the Trans-Siberian train for the week-long journey to Beijing.

This slideshow requires JavaScript.

Boarding the Trans-Siberian

Found the train in the station without a problem. Took cheesy photos of ourselves outside the train (catching unsuspecting passengers within the train in the photos). Was a very long train – maybe 15 passenger carriages. Two carriages first class, remainder second. Every one was a sleeper carriage – second was 4 beds to a room, first was 2 beds and a tiny en suite.

Milan and Christine were indeed in the next carriage. They were sharing with Coreen, a very Scottish 27 year old travelling to Mongolia assisting with research for three months. Made for a very entertaining compartment – Milan and Christine have the most amazing love-hate relationship – it’s quite amusing to see them bicker, fall out, make up, and fall out again in the space of half a minute. It’s all in good humour – I don’t think they could ever actually fall out. But I must say nice things – I did give them the address of this blog 🙂

In my compartment was Rita, an extremely friendly lady who, according to Milan, had designated me her adoptive grandson for the length of the journey. She was quite undoubtedly the most sociable person on the train – within a day it seems she had met every person on their train, learnt their names and their story. She is a very talented linguist with knowledge in English, Finnish, Russian, Mandarin and probably more that I can’t remember right now. She had many stories to tell – many of them revolved around her ex-husband – he would only travel 5-star, and she was taking this opportunity to do what she had always wanted to do and rebel – stay in youth hostels, travel the world by train, and meet lots of people – none of which he seemed to want to do. She took a great interest in my plans – she insisted that she takes a copy of my itinerary.

Also in our compartment was an Australian couple who were concluding their tour of Europe, a Polish (I think) couple who were taking the Trans Siberian to Beijing basically for the journey – they only had 2 days in Beijing (Adam doesn’t have much interest in the city) before returning home. There was a group of 4 to the other end of the carriage, 3 guys and a girl. The guys were cycling across Mongolia – not sure exactly what she was doing. There was a Mongolian woman who Rita was very friendly with – her Russian visa had expired by 18 months (she had a Russian husband), but she was trying to return to Mongolia to pick up her papers. Or something like that. Finally (as far as I remember) there were three Swedish girls who had taken three weeks off work so they could take this train, spend a little time in Asia and then return home. They couldn’t quite explain why they wanted to do it though… but then nobody on the train (including myself) could give a definite and concise answer. It’s probably clear that a bit of a community spirit develops when a group of people are held together for such an amount of time! But then, when we had a look at other carriages, none of the others seemed quite as sociable – most of the doors were shut and the passengers kept themselves to themselves. Carriage 6 was the place to be 😀

The carriage itself was comfy enough. The beds were very hard but long enough. The outside temperature was hot from Moscow, got very cold in Siberia, before getting hot towards Beijing. Shame the heating didn’t follow that pattern in the slightest. The Chinese conductors were friendly, though they spoke little English. The lack of a shower or even a good sized basin was a problem – but when everyone on the train is not showering at the same time, nobody minds 🙂 The toilet was the crude dumping-on-tracks job – the ‘flush’ was simply the hole in the bottom of the toilet opening up, revealing the track below. I was thinking of marking on the map each point when I’d gone to the toilet… or not 🙂 So yea… basically no hygiene facilities.

No food was provided, although we could help ourselves to hot water. We’d all brought a stash of noodles and biscuits. Thankfully, the train stopped for 20 minutes at a station every 4 hours or so, and if it was working hours the platform would be buzzing with hawkers selling all sorts of food, drink and other bits and pieces. The food often seemed to be home cooked Russian food and was fairly priced. At various points, I bought a chicken and potato ready meal thing (delicious and no food poisoning :D), crispy toffee tube things, and a litre can of beer!

Russia

For the first few days, the scenery was relatively uninteresting. Trees, grass, few hills but largely flat, Russian shack villages, the odd chimney stack, piles of logs. Passed through many of the Russian cities along the way – lots of concrete socialist style tower blocks (even if the area was sparsely populated, tower blocks seemed the favoured way of housing people). Weather was good the first day, but by the second night it had turned cold (they forgot the heating and the blankets were hardly warm – lots of grumbling in the morning).

It was surprising how quickly time goes on the train. You spend so much time generally chatting with everyone that it doesn’t take much reading, sudoku and noodle making for the day to end. At no point did I feel bored and that I had nothing to do. Had a lot of fun on the third evening when the whiskey came out (thanks Coreen!), playing cards (none of us could remember a comprehensive set of rules for any card game – we improvised a game of Uno then some bizarre variant of Go Fish).

Into Siberia

As we approached Lake Baikal the scenery got more mountainous. We were also getting more remote – the chimneys and makeshift landfill sites in western Russia became less common. Lake Baikal itself was a truly amazing sight. The train approached it from the mountain tops – glimpses of the lake appeared every so often between the mountains. The track descended as it followed the perimeter of the lake until we were by the water’s edge. The lake was still half thawed from the winter – large sheets of ice remained. The morning was windless, so where there was water, the mountains reflected in it beautifully. The mountains themselves had also part thawed – veins of snow remained, giving me the impression that the black mountains were being illuminated from within… maybe. The scale of the ‘lake’ is hard to comprehend – I took many photos but I doubt that a single one of them will do the lake justice.

Crossing the border into Mongolia

Passing into customs from Russia to Mongolia, it unfolded that the Mongolian woman was not permitted to leave Russia due to having an invalid visa – yet of course she was not technically allowed to stay. Apparently she was aware that she would have difficulties – she attempted to bribe the customs official (this is Russia – it’s not that unusual) but unfortunately for her it didn’t work. She was led off the train by the Russians and never seen again.

Moving into Mongolia (customs took 6 hours! Horrible time!) the foresty scenery soon disappeared, giving way to tall rolling grassy hills. Most of the train got off at Ulan Bator (me, Rita, the Australian couple and the Polish couple remained) and we got a new shipment of passengers. They seemed all nice, but it wasn’t the same as before – there wasn’t quite the same community spirit. We were due to arrive in Beijing in little over a day anyway.

After Ulan Bator the greenery disappeared – we were now travelling through the Gobi Desert. Very dry, hot and sandy – such a contrast to what we’d seen just a day before.

Arriving in China

Northern China on the way to Beijing is a natural wonder. The train travels down a valley of steep tall mountains, giving glimpses down the river as we travelled between tunnels. One of the reasons I took the Trans Mongolian rather than the route avoiding Mongolia was that I’d heard the scenery is something not to be missed – I would certainly agree.

The mountains levelled off as we approached Beijing. Not an attractive introduction to the city – lots of rubbish everywhere, slums, factories. China might be on its way to becoming a developed nation but this sight demonstrated that there’s still a lot to do before China’s new found wealth becomes more universally distributed.

After 6 days of travelling, I’m sure you’ll be pleased to know that we somehow made it to the station to the minute on time – 14:04 this afternoon (that’s GMT+8, no summer time). Made our farewells, took a few last photos, and that was it. All alone in Beijing.. eep!

First day in St Petersburg

This is a throwback to my travels in 2010 when I spent 4 months travelling around Europe and Asia. This is taken word-for-word from my TravelPod blog that I kept at the time, and have recently re-discovered.

This slideshow requires JavaScript.

When Visa say that they’re accepted worldwide, they may not be lying but they’re certainly stretching the truth. It was not a great time to find this out after having arrived in St Petersburg, having not eaten a proper meal in 3 days, water supplies long gone, dehydration looming, no way to pay for my hostel for the night, and with not a single cash machine in sight sporting the Visa logo. Russia may still be insular in many ways, and the way it likes to move money around the cyberspace is certainly one example.

An hour or so of wandering aimlessly, I eventually found my way (at last) to a touristy bit with a Visa cashpoint. Put my card in, entered pin, yada yada yada… your card has been declined by your bank. This wasn’t turning into a good day.

I concluded that, since I had bought train tickets in Lithuania, and to a bank watching its accounts for fraud, finding transactions in Lithuania that it hadn’t expected might be considered suspicious and so HSBC had probably blocked my card. I don’t know whether they’re just keen to minimise fraud or just like being overzealous to annoy their customers, but this will have been the third time it will have happened. Not impressed…

Last resort, I decided to go straight to the hostel I was booked to stay for the night, and ask for their trust and kindness and for them to let me use their computers and check in before I had access to any cash. Thankfully, all was fine. I was able to call up the bank from the number online, sort it out, get my card unblocked, and also to give the bank my travel plan so hopefully this won’t happen again. They say.

The hostel itself is on the 4th floor on the main road into town, by the station to Moscow. In a 14 bed dorm (not too packed though – it’s a big room). Fairly clean, friendly staff, amazing showers – power shower jets and a built in radio?? Mainly chinese students in at the moment, there was a party of English people but they left this morning before I had a reasonable chance to meet them. Hostel is about 25 minutes walk from the city centre.

Spent most of the day doing some intense sightseeing. There is so much to see here, it’s incredible – landmarks like palaces, mansions, monuments, cathedrals and gardens all knit together into a seamless sequence around the city. If Moscow is where money was made, Saint Petersburg is where it was spent. And I’ve only seen a fraction of the city so far. No photos yet (USB ports on this computer have been disabled, or are just broken, dammit!) but a quick google should give you an idea.

The feel of the city itself is certainly worth noting. It’s now 22:40 and the roads are still full while pedestrians, both tourists (lots of them!) and locals, are zipping around the city or taking part in the city’s significant cafe culture. It has probably helped that today’s been stunningly hot – especially for this part of the world – 26 degrees in the afternoon I believe. For most of the day, the street outside my hostel turns into a carpark more than anything worthy of being called a road. The buses and trams are always full, and even during off peak time the subway is an intensely crowded experience. Towards peak time, crowds were spilling out of the subway stations, out of the halls, and well onto the paths outside. There are just so many people here. Even compared to London, this is something else. (And Saint P is certainly not supposed to be one of the busier cities on my route – so there could well be even more to prepare for!) It seems “off peak” isn’t defined as the time when the roads are fairly empty, just as the time you can actually move.

Speaking of the metro, at only 22 rubles a single (50p) it’s a fairly cheap way of both getting around and doing some sightseeing too. The lines are incredibly deep – the escalator journey alone takes 2 minutes each way. I believe the reasoning is that the stations underground were designed to double up as air raid shelters in case of war – which is also why they are so ornate. I wish I was able to take more photos (only got a few on my camera phone) but bringing out your camera in a tube station around 100 commuters in a packed subway station not only is asking for pickpocketers and the like, it just feels a bit silly too.

Back to the roads – if you ever thought there were some bad drivers in the UK (you know who I’m talking to) then Russia is a whole new experience. Lane discipline is optional, the horn rules, pedestrians and even other drivers are annoyances that prevent drivers getting to where they need to be, and must be eradicated. Speaking of which, there’s a very strange rule on pedestrian crossings here. When the green crossing light is on, you cross. But right turning traffic still crosses their line and is about to cross your crossing. In the UK, that would mean somebody’s done something wrong, so you jump for your life out of the way. But here (and also, oddly, in Berlin) it’s the norm that the car gives way, and then carries on when everyone’s crossed, like a UK zebra crossing. But not all the time. I still haven’t quite figured it out. Sometimes I attempt to cross and have to react quickly to the driver’s own inability to do so. Sometimes the car approaches, I jump back, the car stops anyway, the driver looks confused and annoyed. I just follow everyone else now. Also… half the cars seem to run on half flat tyres. The roads are filled with the noise of the flat tyre squelching sound. Maybe they forgot that winter’s finished? Just something I noticed. Also saw that, with the introduction of capitalism, the number of Ladas is surprisingly low on the road (separately saw 4 of them broken down on the streets today). You can’t help but get the impression that Russia still doesn’t really want to do capitalism and suchlike, but it’s getting there.

Long tiring day, exhausted. Planning tomorrow maybe to catch the train just out of the city to see one of the many palaces around the area . We’ll see.