Thursday, December 16, 2010

Creating basic AutoCAD LISP with Python

I recently started a new job as a design engineer in Norway and have been looking for a way to draw line and text examples that would show the various line types and colors according to our pen settings in our plot file.
So I was going to draw a line, then change the color, and write the name of the color next to it.
The problem was that there was 255 colors in AutoCAD and that would take a long time.
Because the process was repetative I decided to try to write a lisp routine that would draw an assortment of polylines and then put them on correct layers with the appropriate colors.
Now after messing around with python I created a simple script (with the help of that would generate the lisp routine.

fn = "instructions.lsp"
instructionList = ['(defun C:layermaker()',]
for i in range(1,255):
    instructionList.append('(COMMAND "-LAYER" "MAKE" "COLOR %s" "COLOR" "%s" "" "")' % (i, i))      instructionList.append('(COMMAND "PLINE" "%s,0" "%s,2000" "")' % (i*50, i*50))
    instructionList.append('(COMMAND "TEXT" "%s,2200" "30" "0" "COLOR %s")' % (i*50,i))
f = open(fn, 'w')
This python code creates a file called instructions.lsp, then makes a list called instructionList and adds the lisp function name of (defun C:layermaker()
It then iterates from 1 to 255 items and concatenates the numbers of the colors into the autoCAD commands.
Then it opens the file, writes the list to the file, adds a parenthesis and closes it.

Here's what it generates
(defun C:layermaker()
(COMMAND "-LAYER" "MAKE" "COLOR 1" "COLOR" "1" "" "")
(COMMAND "PLINE" "50,0" "50,2000" "")
(COMMAND "TEXT" "50,2200" "30" "0" "COLOR 1")
(COMMAND "-LAYER" "MAKE" "COLOR 2" "COLOR" "2" "" "")
(COMMAND "-LAYER" "MAKE" "COLOR 254" "COLOR" "254" "" "")
(COMMAND "PLINE" "12700,0" "12700,2000" "")
(COMMAND "TEXT" "12700,2200" "30" "0" "COLOR 254"))

The coding is very basic and it basically took me several hours to figure out how to do this because I'm new at python.  But I learned alot.
If you're interested in the DXF file just add a comment and I'll see what I can do to get it to you.
Basically what you'll have is a way to plot all your pen styles onto one drawing so you know what your colors and lineweights are.

Here's the code in blue and comments in red.
fn = "instructions.lsp" #Creates a file named 'instructions.lsp'

instructionList = ['(defun C:layermaker()',]
#Creates a list called instructionList and makes the first item on the list '(defun C:layermaker()' which is the name of the function.
for i in range(1,255):#Uses the range function to iterate from 1 to 255 which is the number of colors that AutoCAD has.
    instructionList.append('(COMMAND "-LAYER" "MAKE" "COLOR %s" "COLOR" "%s" "" "")' % (i, i)) #Uses the append function to add an autoCAD command that creates a new layer.  The %s is the variable and is defined at the end by i,i
    instructionList.append('(COMMAND "PLINE" "%s,0" "%s,2000" "")' % (i*50, i*50)) #Uses the append function to add an autoCAD command that creates a polyline that is 2000 units long.  It inserts the variable i multiplied by 50 to create the spacing for the line.
    instructionList.append('(COMMAND "TEXT" "%s,2200" "30" "0" "COLOR %s")' % (i*50,i)) #Uses the append function to add an autoCAD command that creates a line of text.  Notice the i*50,i.  This multiplies the variable times 50 which allows the proper spacing, then the second i refers to the name of the color.
#At this point it loops back to the first append function and iterates with the next number untill it reaches 255
f = open(fn, 'w') #this opens the file defined as fn which is defined above as instructions.lsp
f.write("\n".join(instructionList)) #this writes the list to the file
f.write(")") #this adds a parenthesis to the end of the function
f.close() #this closes the file

Tuesday, July 20, 2010

Passed National Engineer Test!

Well today I received the results from my test in April and managed to pass the National Civil Engineering eight hour exam.  This means that I can obtain a license in all states except from New York, California, Hawaii and Alaska.  What it does for Norway I'm not sure but it's just nice to know I won't have to sit for another eight hours on a plastic chair eating almonds and almost breaking down in the middle of the test feeling like I'm going to throw up asking myself why I focused on hydrology.
To get my California license, I now need to pass the seismic portion of the test.  Woo hoo.

Wednesday, June 23, 2010

Possible Solution to capture the oil from the BP Leak

This solution modifies the existing LMRP Cap.  I've tried to reconstruct it here in the 3D model.  The first image is of the model off the BP site.  The original LMRP Cap would remove the sealing grommet and install a slightly tapered pipe that would expand the existing riser pipe as its pressed in.

One of the issues coming off the riser is that the existing pipe was clipped rather than nicely sawed.
By inserting a slightly tapered pipe end into it you could basically expand the existing steel (assuming you can place enough pressure on it through weight etc.) and insert it into the tube.  This would create a metal to metal seal.  You would have a ball valve on top of the tube you're inserting that would be open and then you close it slowly or begin taking in oil.
Here's some sketches.

This would wedge the proposed tube into the riser. If your angle of attack is shallow, then it would be a longer tube ensuring a better seal.

Sunday, June 13, 2010

Making of Star Wars, Revenge of the Kids

This is my latest Photoshop project.  It's a photo of my daughter in a battle shooting down Tie Fighters.  The wind caught her hair at just the right moment.  The caption reads, "Star Wars Revenge of the Kids".

The original image was taken of my daughter as she's looking through a spy glass at Sea Port Village in San Diego California. The other images are from a WWII photo of a fighter getting shot down, an image of a Tie fighter and the Rebel Alliance logo.  The Star Wars title is lifted off a PNG I found off the web and the text for Revenge of the Kids uses a Trajan font.
The lasers pulses are Photoshopped using the standard air brush and a green glow.

Wednesday, June 2, 2010

Painting of Chris Bot!

So my wife Runi helped me paint Chris Bot this evening.  She has a background in theater and was able to create a nice textured look like old metal on him.
Once the light is adjusted you can see his true color.  In the photo above he contemplates taking a photo of the flower.
Here's the link to the short Youtube Video.

You may have to see it a few times to get the hang of whats happening.

Friday, May 21, 2010

Chris Bot Lives!

So I couldn't wait to get the paint on Chris Bot and I just decided to start animating him.  After all, I mean, why not right?
So I made a rig out of LEGO and plasticine that kept Chris Bot standing and pulled out the web cam and started animating the guy.  The results can be seen on you tube and yes, I still have the trial version of Stop Mo pro but it's not that bad.  The rig wasn't removed because I think I can't do rig removal with the trial version, well at least export rig removal.
Anyhow, here's the embedded video and a link to the you tube video.  Once you viddie it, then drop me a line and tell me what you think!

At the end Chris Bot falls down but for some reason, you tube clipped the video.

Wednesday, May 19, 2010

Imperial Pipe Carrier

One of the things that I always wondered about as an engineer was exactly what type of infrastructure rebuilding plan the Imperial Senate had.  In comparison to our planet, I have been creating Star Warish type of infrastructure tools that the Imperial Army would have to use to maintain infrastructure.  Assuming that pipeline relining happened on Tatooine, I created a pipeline relining cart that is used to insert steel liners into existing pipes.  It's been modified with droids and other technology and of course a Storm Trooper contractor is driving the thing.  To see what relining looks like on our planet, click this link at the San Diego County Water Authority Website.
Here the carrier is carrying a steel liner.

Hydraulic driven arms expand the pipe liners allowing the liner to be securely placed in the pipe and welded.

Tuesday, May 18, 2010

LEGO Construction Site

When I was a kid I used to play occasionally with a LEGO Police Station set that my parents bought me in 1981 or thereabouts and I used to build all the police cars and buildings that came with the set.  I really wanted the space set and so I had to improvise on making air tanks with rubber bands and round studs.
People always said, 'Oh, you're going to be an engineer' and so I got it in my head that I was going to be an engineer.
As an engineer I don't play with LEGO.  I occasionally draw lines in AutoCAD that represent pipes and spend most of my time managing projects.
On my spare time, I still play with LEGO and last year made a model of a construction site for one of our pipe rehabilitation projects.  Here's a photo of one of the pipe enclosures before back filling the holes.

These projects are used to fix aging pipes in the San Diego area and construction means tearing out a piece of the pipe and dropping steel liners into this hole in the ground and transporting them to the appropriate area that needs to be installed. 

Here's a couple of photos of the diorama I did complete with sound walls to mitigate any impacts to endangered species and fencing to avoid any intrusion into the green areas.

Total cost for this model?  After shipping and handling and acquiring all the pieces from Bricklink, about 600 dollars!
The liner in the LEGO model is transparent but in reality it is half inch thick steel.
Front View of the complete model.  Notice cement truck and vent structure.

Monday, May 17, 2010

Foam Latex Chris-Bot

Over the last month I've been working on making a small puppet known as Chris-Bot.  It has an aluminum armature and a foam body.  Well, this last weekend I finally got around to casting Chris-Bot in his foam latex body and it came out pretty good I have to admit, at least for my first time doing it.
Here's a video of the birth of Chris Bot.
Special thanks to my wife for all her help in getting Chris-Bot to come alive.  Now the fun part, to animate him!

Sunday, May 2, 2010

Logo Mosaic

Over the weekend my daughter and I put together a LEGO mosaic of a water drop that is used for the San Diego County Water Authority logo.  We did it for a one of my coworkers who's retiring.
We did a time lapse video of the construction of it and posted it on Youtube.
Here's a link to the Video:

Monday, April 26, 2010

Recycling Can Fix

A couple of months ago my neighbor was upset that the recycling truck slammed her trash can down and broke the plastic hinges that held the wheels in place.  This is quite a problem for people.  The cans sit in the sun and then get slammed around by the recycling trucks and always end up breaking.  They get replaced for 60-100 bucks a pop depending on the size.  My neighbor said she was upset that she was going to have to pay 60 bucks for a new one.
For Neighbor Day (which is around my birthday this year) I decided to take care of it for her.  With a few hose clamps, screws and some plywood, I fashioned a fix for her.  From the photo you can see that the wheels where originally held on by the plastic and you can see how those are broken.  So far, this is held pretty well and no complaints from the city! She offered to pay me for the time but I said no big deal and let it go.
It's not a very impressive project but yet, it shows you how you can fix things rather than get new ones!

LEGO Office Cubicle

Last week was professional assistant's week and so for our professional assistant I created a mock set up of her cubicle that everyone signed.  It was pretty cool and it comes even complete with trash and recycling receptacles.
If you're interested in something like this, send me photos of your cube, yourself and I'll come up with a price for you and make one for you!

First Post with LEGO elevator!

Well after realizing all the fun stuff there is out there for makers I decided to start my own Maker blog detailing all the stuff that I've made, am making or gonna make.
For my first post, we'll start off with a LEGO elevator I made for my daughter.
The elevator is built out of Duplo LEGO and uses a motor from the first Mindstorm kits to pull up a little car.