Wednesday, December 24, 2008

Lisp: Everyone draws pipes don't they?


Of course they don't. I know that. Here is now made available, not exactly on a plate, a FREE, fun way to draw pipes. Not quite the end of drafting drudgery, but the start of the end!


Unfortunately, when I tried to put them on my blog all the lines ended up all over the place.

So I have made the decision to make the files available on a "request only" basis. That means you e-m-a-i-l me, asking for them, and I send them to you. (For free). I am trying to avoid the spammers here by saying think about blecouteur at xtra dot co dot nz.


In the process of testing: another snafu-the dialog box won't fit on the screen. This is because at work I have a big screen.....So I have now 2 dialog boxes to send you- one a chopped down one and one that is the full nine bananas. The small one does dairy pipes only-Grr...I will have to see about more columns...which can be done, it just makes life more complicated. It probably needs doing anyway. Try the full one called pipeset.dcl. if it does not work try the smaller one.


Every time I use this routine I am pleased at the appearance of pipes, as if by magic. There is a certain amount of ego stuff here, but I am at least honest enough to say that out there somewhere someone has done the same thing. (Probably a while ago.)

I had thought briefly of selling the combined routine, but they are very short routines, and any

capable lisp writer, if they had seen them being used, would be able to re-write them easily.


The idea is you run one routine initally to set the diameter of the pipe you want to be drawing.

The name of this routine is pipeset.lsp

Then you draw lines representing the pipe routes. Fiddle around with these to get them right.

Next, use pir.lsp to do the pipe radii. Unfortunately you have to do this elbow by elbow. One day I may make a routine to do this all in one hit.


Now comes the big moment: Set the routine pip.lsp onto that bunch of lines/arcs. That's right just select the damn lot all at once! Whoopee!....or it should be.


One of the routines uses a dialog box. This is contained in a separate file called a .dcl file.

The trick with this one is that the routine that accompanies it (pipeset.lsp), needs to know where you stuck it on your hard drive. You should be able to see the bit early on in the routine saying where the dialog file is kept.


Some people just get lazy and stick them all in the support directory, but this can be a pain if you upgrade.


Monday, December 22, 2008

Lisp, Using an incremental approach, and Variables

The Development Approach
1. Start simple.

2. Test it.

Once you have one bit working, move on to the next bit.

Don't try to write the whole program all at once, all in one hit. You will make mistakes, and
these are quite tricky to find with Lisp.

Make your first lisp routine 3 or 4 lines if you can. Leave the handrail generator for when you have 3 weeks off.

Looking for help? Try going Tools/Autolisp/Visual Lisp Editor. Once the Editor is up you can hit help. Someone at Autodesk is a smart one, because he put all the lisp commands under an aphabetical listing in the help section. Which is good if you know the name of the command.

Basics of Variables
What is a variable? Just a name, that you have made up, and you assign a value to.
This value might change over usage.

For instance, consider:
(setq the_length 22)
The minute Autocad sees this it says "Aha! that variable the_length, it has an integer value of 22!" You may not know what an integer is. It is definitely nothing complicated, all it means
is it is a whole number. So for instance 22.23 would not be an integer.
Just a trap for young players here....do not use variables like angle or length. These are already
reserved for Autocad's own use and causes trouble if you do (Yes...I am guilty!)

How about:
(setq the_layer_name "Fred")
Here, the variable is being set to a string (whats a string?-just a bunch of characters)
You could change this in the course of the program by going:
(setq the_layer_name "Sam")

Naming of Variables
I'm afraid I have been a bad boy as far as consistency is concerned here: I seem to choose
whatever takes my fancy at the time. Sometimes I like running all the letters together, for
instance thelayername. Other times I go the_layer_name or TheLayerName.
Just remember lisp does not care about upper or lower case so just choose the system that
suits you best. But remember: One day you might have to read your own program back,
and having variables like "e" or "b" or "updown" won't make a lot of sense.

Get a peer review
At one stage I had written a 3d stair generator, which I was intensely proud of.
Until I gave it to a friend, who kindly pointed out that it did not compute the stairs he
thought it should be able to. He was right. I was wrong. But I went away and corrected
it and now it goes nicely. I hope to post this over the Xmas period, along with some other
ones.

There are good books out there, I bought one (Woops in 1992!) called Maximising Autolisp
by Rusty Gesner and Joseph Smith, and I have had good use out of it.

Friday, December 12, 2008

Autolisp

This will be a short series of posts, concentrating on Autolisp routines that I have written.



I will attempt to provide routines that are heavily commented, so you can understand how they work.



My first point is that you do not have to be a genius to write lisp routines (?!) and that you can get quite a lot of satisfaction out of just a few lines of code.



It has been usable with every version of Autocad that I can remember, and one of it's chief advantages is that most routines will run on any version. Unlike visual basic for applications (VBA).



The implementation is easy and elegant: you get Notepad (have a look under Accessories on your Windows PC) up and running and start typing. To use, you can go "appload" in Autocad, but I prefer the lazy two screen approach: just drag and drop the file into autocad to load it.



Just remeber that file extension has to be lsp, so for instance it might be called cor.lsp.



This is a hangover from the MSDOS days and you may need to go to Windows Explorer and turn on the option that says "Hide file extensions for known file types" (Under Tools-Folder Options-View) . This is important because Notepad will save it's files with the extension .txt.



You will need to change that when saving, to .lsp.



Because blogspot don't allow file downloads, all routines will be shown in the blog post: you just cut and paste them into notepad.



One last "need to know": You need to create yet another file, always called acad.lsp.

This is a special file (again, just an easy text file) , that Autocad knows about and will check for.

If it finds it, it will load the routines listed in it so you have them all available at the command line when you need them.



Here is an example that you could cut and paste into Notepad, and, if you save it into

c:\program files\autocad\support directory (yours may vary slightly from this), it will make available the commands COR and IL. I use abbreviations to cut down the typing- COR stands for COPY AND ROTATE, and IL stands for ISOLATE LAYER. These are the two simple routines I am going to start you off on.



;--loaded functions

(defun C:cor () (load "c:/bilro/bilro1/cor")(c:cor))

(defun C:il () (load "c:/bilro/bilro2/il")(c:il))



What all the above stands for is that we are defining a function (hence defun) that can be used on the command line (hence the c:) and that part of this functions job is to load a lisp routine and make it available . It is a bit cryptic, but I find if you just follow this format, it always works.



Of course, all this loading is not much point if the routines cor and il don't exist at the path I have shown ie c:/bilro/bilro1/cor. Your path can be different-it does not matter where you keep them.



Setq - what does it mean? It just means "assign this to the said variable"



So, here is the code for COR.lsp:



;written by Bill LeCouteur-this line is just a comment -ignored by Autocad because of ";"

;this routine copies & rotates-this line is just a comment -ignored by Autocad because of ";"

(defun c:cor ()

(prompt "\nSelect the items to be copied and rotated: ")

(setq ss1 (ssget)) ;gets a selection set and sets it to a variable called ss1

(setq pt1 (getpoint "\nEnter rotation point for the picked items: ")) ;gets a user defined point

(command "copy" ss1 "" "0,0" "0,0") ; issues a standard autocad command-copy

(command "rotate" ss1 "" (list (car pt1) (cadr pt1)) pause); same again -pause is for user input

(command "redraw"); same again-standard command

(princ) ;exits cleanly

);this closes the parentheses at the start.



Here is the code for IL.lsp



;Program written by Bill Le Couteur

;Auckland NZ;

Rev 0 date 16.6.95;

This program isolates a layer by picking it

(defun c:IL()

(setq edata(entget(car(entsel)))) ;gets the user to select an item and sets the variable edata to it

(setq thelayer(cdr(assoc 8 edata))) ;finds out the layer it's from by looking at edata

(command "-layer" "s" thelayer "");sets the current layer to that layer

(command "-layer" "f" "*" "");freezes every other layer

(princ);exits cleanly

);end of defun



Whew! If you have got this far, you may have such enthusiasm that you might have actually attempted to do the above, so you may need help, so I have turned the comments on this blog to anyone can comment, and I will attempt to check this regularly and help if needed.

Saturday, November 15, 2008

3D Drafting:My philosophy

Over the years, I have come up with a style of drafting in Autocad that suits me.

These are for plant layouts.

See what you think of these:

1. Do not draw holes in pipe flanges. This uses up memory, slows down display and so on.
Having them in may make the view more realistic. For plant layouts, I would hope that nobody in the whole world puts in nuts and bolts on a pipe flange.

2. Where possible, simplify! There is a great temptation to draw every curve on an item-resist it.

3. Don't go Layer Mad. I reckon you need layers named:
Level 1 Plant
Level 2 Plant
Level 2 Beams
Level 2 Floor
Columns
Piping (Sometimes I use the pipe label from the p and id- eg Pipe-54-102-44)
....and not a lot more. I work with a person who had the idea that one should have a layer called say Sifter, as it allowed him to work on that item easily by isolating that item. I say, if you want to work on such an item for a while, you are better off cutting and pasting that item into a new drawing all by itself and working on it there. Alternatively, assign it a temporary layer. I use about 5 main layers:
Dim: This is for all annotation, not that this is needed much any more as most items in paper space can be any old layer.
CL: For centre lines
Hid: for hidden lines, not used much for 3d
lgt:for light lines
med:for medium lines
Hvy:for heavy lines
pha: for phantom lines.
Your ctb file should allow for all numbers from 8 to 249 to be 0.2mm wide and colour black when printing. Numbers 250 to 256 should be colour by object, not black, so that on a laser printer you can show shades of grey.
I use the built in Layer Manager to save various states, but I guess layer filters would have the same end result.

4. Do not draw the fillets in on the structural steel. This is wasteful of time, energy and clutters the drawing up, making it harder to determine what is where in wireframe.

5. Do not draw the insides of things, for example, hollow sections, unless you are really keen on portraying the "real thing". I worked for one company, where it seemed that it was a badge of honour to show all the insides of a hopper-who wants to know?! The answer is sometimes you do like to show this, but please do not blindly apply it to every item so you can say your drawings are consistent. If you are a cad manager reading this, you could in theory speed up the throughput of your office manyfold, if you considered just this point carefully.

6. Keep your model pure. By this I mean: don't put text in model space, or sectional views, or parts details. Put these in their own separate drawing files, it is not much trouble and keeps things fast and tidy.

7. Write block out your sections to file called say 149993-sectionAA.dwg. Then in the drawing that you want that section to appear, Xref it into that drawing. The benefit of this is that when you make a change in the model, you can update the section file, which will automatically update the drawing it appears in.

Happy drafting!

Sunday, October 5, 2008

Rendering Using Autocad R2009

Here is a render done using R2009. I'm quite happy with the quality-some may not be.
It was done using the Illuminated Sky Background option, which I'm finding makes life easy.

Monday, September 15, 2008

Rendering in Autocad R2009

May as well put out a positive YES for R2009 here.

R2009 has improved rendering over R2008 : To get a good rendering now, just type in
LIGHTINGUNITS, set it to 2. Apply your materials-if you use realistic shading while doing so, then you get feedback that you have applied the materials.

Turn on Full shadows, then Sun and illumination-sky. You can use the visualising tab on the ribbon-just seems easier than fishing around in menus or typing.

Select the your geographical region, time of day etc and then press render, using say 640x480.

You should be pleasantly surprised. Ok, so not everyone is into rendering....but if enough users start out using the above approach, I would anticipate a huge increase in rendering.

I'm no expert in all this, but it seems to me that this business of "final gather" is involved.
Usually this is set to auto, and sometimes to get it kicked into life you need to set it to ON.

The thing about "final gather" is that, when it is enabled, all the shadows which used to be black, now look a lot more realistic.

Once you get a nicer rendering, save it as a tiff file, I find a resolution of 2400 x 1800 quite good for nice sharp pictures. They can take a while though-15 minutes is normal.

I hope to be able to post a typical rendering of mine soon.

Thursday, September 4, 2008

Blocks versus Lisps

Just plodding my way through one of my drawings today and a thought struck me: I've done this little thing before-a 75mm post with a plate on it's end and 2 x M12 bolt holes to fasten it to a nearby girt. (All in 3D of course)

In the past I have gone on about the need for blocks for every situation-but where does anyone get the time, or the inclination to be disciplined enough to organise a really comprehensive block library?

I am slightly organised now, and over the years the blocks have accumulated like dust in my computer. Maybe it is just that every situation appears to be unique, so things "need to be designed". This might be justifying our existence, or ego.

The other idea I had was that maybe someone (me? when I'm not busy???) would get on and write either in lisp or VBA, general types of lisps-for instance in the above example, you feel the need to do a plate on the end of a post: you initiate the routine and a dialog box comes up with all the variables, plus an option to auto-fill the variables. For instance you might choose a 75 square post: It would then offer up say 10mm as the plate thickness, and M12 as the bolt size and so on.

I'm not sure, but my gut feeling here is that a lisp routine would be better than a block, because the option would be there to change any of the variables before the thing is drawn.

Yet another thought:

Maybe this could all be accomplished using "styles" in the manner of Autocad Architecture: You might have a style named "Plate-75mm-M12" The idea is you insert an object that has all it's settings governed by the style. So when you want one that uses say M10, you saveas the old style then modify the new style to provide M10 holes. (Oops-sounds like redefining blocks!)

All this is most un-Inventorish! After all, what do we spend half our drafting life doing? Changing what is already there. Unfortunately, I would need vast quantities of cash and a promise of a long contract to get into the Inventor club. I was told once that Autocad is OK, but to be really serious, you need Inventor....Hmmmm.

One last gasp here: what if you could somehow link your drawing objects to say a Microsoft Access database? How would it work in practice? Maybe you are in the drawing, and someone says make the holes M10, not M12 in that plate. You issue a special command, click on the plate and you are immediately in the database, right where the plate is. You then alter the hole sizes in there and go back to the drawing, and update the drawing: It is done.

How the heck this would work, I don't know, but it does seem a bit complicated to actually get it to work.

I have already experimented with a house drawing program that uses a text file to generate a drawing of a house, using 3D solids. The plan was to get my drawing outline from the architect, feed all the info into a text file and then press a button. Only trouble was that there would have be a huge amount of work drawing most common types of windows. The idea worked, but I gave up drawing house plans.

Saturday, July 5, 2008

R2009 Autocad and P and IDs

Funny how things go....I was of the impression that R2009 was fairly crash prone. However, I have been using it now at NZSugar Ltd, where I am not attached to the network, and I have have had no crashes in the 3 weeks I have been there. (I was on a network on my previous assignment.)

Another factor may be that I have not done much in the way of 3D, stuck as I am doing the hot water P and ID. So Network? 3D?

In my way of doing P and IDs, I was asked if I could stick to NZSugar standard symbols for valves and so on. This I did do, and was able to add yet more symbols that they did not have.

The design and sizing of these symbols was a trick-do you make them fit on a grid? I have done P and IDs in the past and used the idea of using a grid but got sick of putting snaps on and off, not to mention that whenever you opened up someone elses drawing, they never used a grid.

The trouble is if you make your symbols too big, the drawings look wrong, and if they are too small, they are not legible.

I would be nice if, when I get the drawing with all the standard symbols on it, I could post it on this blog so others might use it. But I have not figured out how to put a download onto this blog.

Anyone have any ideas how?

Saturday, June 14, 2008

Why I do not have an email address on my blog etc

Hi Jim!
Sorry I have not replied-I have been busy with personal things as well as falling off my bike.
I have not posted my email address as I do not wish to be engulfed with spam. Which makes me think: how can I be contacted? I have thought of this idea....since robots are trolling for things with an ampersand in them, all I have to do is put my address in a blog posting like this one and make it look like this: blecouteur at xtra dot co dot nz.
Should be easy to figure out....

Now for the autocad stuff: I have been laid off from my job at Nucon Ltd, and have managed to land a short contract at NZ Sugar Ltd, who as it happens, do not want my computer connected to their network. You could almost hear my computer go:"What....there is no network? So I will go at almost twice the speed....". Well, maybe not twice, but it is very noticeable.

Which raises the interesting question: Is this R2009's fault, or is it the networks?

Arriving at NZSugar, I was surprised to find there was already a draftsman there (they went for quite a period with none). What was interesting about him was the fact that he was into VBA for Autocad in a big way and he had applied this all to electrical drawings.

Another interesting thing was that NZSugar had bought 6 seats of Cadopedia, an autocad clone.
The version they had though, could not read more than one layout tab. The other draftsman downloaded the latest version, and apparently it can.....

Sunday, April 27, 2008

R2009 Autocad

Oops! In a previous blog about R2009, I said the best thing about R2009 was that it drew blocks on the use of the soldraw command. This DID work in one of my drawings, but the other day I noticed it did not work in another. This is cause for some investigation on my part. I will keep you posted in case you do not have R2009.

It seems some people are having no problems at all with R2009, while others are complaining about some of the "features". For myself, I am perservering with it, as it may well be things like your video driver(is it up to date). I am using smpseesaw as a means of forcing acad onto one cpu (I have a dual cpu). I presume this makes a difference, but how much I am not sure.

It appears to be slightly weird that some have problems and some don't. I would like to know what the cause is. Any ideas, anyone?

Monday, March 10, 2008

How to get your co-workers frothing at the mouth....

I've been doing this a while now for architectural stuff. I want a detail in my drawing: I drag the detail block in from explorer, and insert it in paper space, then scale it by 1:10 or whatever scale it is. Nice, neat, quick and no horsing around with viewports and model space.

I have run this technique past a couple of Cad monkeys and ......they are unanimous in their condemnation of me......how dare I insert geometry that is not 1:1?

In my defence, I claim any fool opening such a drawing will immediately see that this is indeed a block and it is in paperspace....so what is the big deal?

Saturday, February 23, 2008

File management fun...not

This post is just a warning to those of you out there that work on large projects, and there are frequent changes to files and revision files have to be kept. What a pain.



Where I work, we have all the drawings kept in a directory, and under that directory is a folder called Superceded. The plan is say you have a drawing called 5046034.dwg and it becomes rev A, you copy the original to Superceded and then rename it to 5046034A.dwg.



Well, somewhere in the piece I was renaming and renumbering files, and I used the "drag and drop" technique. It appears this works fine on c: drive but not on a network drive, as the dragged files suddenly reappeared in the next session. Needless to say, the engineer was very confused and upset!



Moral of the story? DONT USE DRAG AND DROP ON A NETWORK DRIVE!



File Management



The standard way the firm has kept files in the past has been to chuck em all in one honkin' great directory and call them things like: 5046032.dwg

So.....you want to find something? You have to have a good memory, or you make a temporary Excel or Access file. Some of our projects might have as much as 500 drawings in one directory.



Which is OK except that you are now typing out the title block all over again....which seems inefficient.



After all the shouting is over these all get put into a program called EDMS, which is nice, but who wants to manually key in all that stuff? Not me, said the draftsman!



I had encountered another firm, where some bright spark decided to give a name to the drawing file, for instance 5046-032 Sugar Surge Hopper G.A.dwg.



I thought this was a much better idea, and adopted it, even if it did mean that I had to type the title twice. I can even admit to it's major drawback, that it does use up space in the file open dialog box.

It does have one advantage: You can use a dos batch file to extract all the file names to a text file, then they can be further carried to Excel and or Access. I call mine getem.bat---all it has is one line

DIR/B/X > THELIST.TXT

It outputs the listing of the files to a file called "thelist.txt".

I would imagine there are people out there using Autocad's data extraction techniques to populate databases with things like drawing no and title.

Ahhh.....but I don't use that File Open Dialog--I use a permanently open Windows Explorer to open my drawings from.



Another refinement I tried to introduce was putting different groupings of drawings into different folders. For instance all Layouts would have their own folders. Each grouping of plant would have its special folders. We did try, but this was "not the way we have always done it..."

Revisions

Ahh....revisions....don't you just love them? Whoever wanted these, was mired in the good old days of manual drafting. There is just one big problem: Now we work on 3D models, the concept of revisions is almost unmanageable.

Someone I know says the people he deals with have actually given up on revisions. Which if you think about it is not such a bad idea. After all, all you are trying to do is provide a snapshot of the drawing at a particular time. What is wrong with (say) if you change something, take a PDF of the drawing, and save it somewhere, with the date printed on it?

Maybe the drawing should be considered a moving target until the magic "Issued for Construction" stamp gets put on?

Autocad R2009

R2009 Autocad.

In a nutshell as far as I can see, it has a few killer features:

1. The ability to have a permanently open layer dialog box. Only useful for some.

2. Click on something, and a properties box comes up. This is a bit disconcerting at first, but I predict some will just love this one. You can choose what properties will normally appear.

3. This is the absolute most wonderful item: Soldraw now does its thing on BLOCKS!(same with the section tool)

4. There are preview gadgets for drawing files and layouts, which in time may become a more useful feature, once we all get used to them.

5. The ribbon. I know I have raved on about going to keyboard entry, but my natural laziness has prompted me to use the ribbon. The reason is I have 2 screens and this really is a replacement for the Dashboard, which I have been using.

6. There are some 3D visualisation tools that may grow on me.

So there you go:
It looks prettier than R2008. Not a big consideration for some, but we spend 7-9 hours a day looking at it.....

It also allows me in my daily work to do a section on a set of solids, some of which might be a block, and have them appear....which would be worth the cost of the upgrade.

Monday, February 18, 2008

New Personal Blog

I have now realised the error of my ways. What started out as an Autocad blog has now ended up a personal photo gallery.

SO........I have now got a new blog, just for the personal stuff. It can be found at

http://williamlecouteursblog.blogspot.com/

What with all my building work at weekends and a weeks holiday, I have not had much time to rave on to the (it appears) two or three visitors I do have. (Or are they just web bots trawling?????)

Tuesday, January 1, 2008

Not Autocad...just Bill creating a heart attack for himself...

These pics explain why I have been very quiet. It is because I have been very busy. Just a 2 day job to add on a sunroom to the front of the house. (Day 7 and counting!) Thank god for Robbie helping me as I can imagine the whole thing going horribly wrong. Anyway the pics tell a thousand words, so here they are: These 2 - a door and a window took all day.....
This is Robbie...early in the day....

Hmm--just about finished....think not..
There seem to be all sorts of wrinkles, like how come cedar weather boards cost $27/metre?