Thursday, 12 January 2012

Writing Object Orientated VB.net Code for Civil3D (Part 1)

At the beginning of last year I uploaded the post Visual Basic (VB) for Civil3d this post always appears to come up on my blogs statistics as one of the most popular posts.

It was my intention to post more on programming last year however I did not manage to do this as I didn’t spend much time working on my programming projects.This was partly due to lack of time and secondary lack of knowledge on how to structure my code in a better way. Anyway this year one of my resolutions is to develop my projects further.

The project I have decided to start with first is one I got going a while ago (2008-9) and posted as a wish and video. It enables you to create different types of longsections in 3 clicks or less by loading in the different Alignment, Profile and ProfileView style settings from an externally stored XML file. The reason I developed the code was to save time on small jobs drawn in one dwg. When there is a need to draw multiple small longsections of different types and styles for walls, drains, roads, etc. I have toyed with various names for the project over the years but I have decided to settle on the name “Long Section Generator” for now.

The original code was written in VBA and so far I have transferred it into VB.net in Visual Basic Express 2008 and have it running in Civil3d 2012.

Now the fun starts Refactoring.

Refactoring is the reworking of existing code to perform better and to be more maintainable using Object Orientated Design practices.

In the AU video I recommended in the previous post by Augusto Goncalves he recommends the book
Refactoring: improving the design of existing code 
which can be found on amazon at the link above or at Google books

And according to the book my code smells and it smells bad.

The reason is that previously in VBA I would sketch up a bit of a flow diagram (as below) of what I wanted to achieve. Then develop code for the flow diagram by using examples and bolt them together into a long string of routines, not the best programming technique.

So in the next post I plan to summarize some of the Object Orientated programming practices I have been reading about over the last month and while on holiday.
Image1154

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...