Sie sind auf Seite 1von 2266

The AutoLisp/Visual Lisp/VBA

Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Visual Basic and AutoCAD
In this section you will find a few applications that I've written using Visual Basic.
Most of them have been written to assist in a better understanding of VBA and AutoCAD.
I have supplied the source coding with all projects but you will need to have Visual
Basic 4, or above, installed on your system to view and/or modify the source coding
of the stand alone applications.
VB and VBA Tutorials
VBA Quick Tips G
AutoCAD API's G
An Introduction to VBA. G
VBA Primer. G
Userforms. G
Lisp To VBA. G
AutoCAD and Customizable Support Files G
VBA and Menu's G
VBA and Sequencial Text Files G
Hiding Dialogs and Other Things G
PolyLines and Arcs by Scott McGlynn G
Accessing AutoCAD by Scott McGlynn G
File Functions In Visual Basic G
Error Trapping G

VBA Applications
VBA Batch Purge. G
Change Text. G
VBA and Outlook. G
VBA and Powerpoint. G
Command Line Project. G
VBA Fax Project. G
Visual Basic Tutorials
http://www.afralisp.com/vba.htm (1 of 3) [23/03/2005 05:43:10 p.m.]
Timesheet Project. G
Loading VBA Projects. G
VBA and Excel. G
VBA and DataBases. G
VBA Steel Project. G
Drawing Setup Project. G
AutoLisp/VBA Drawing Setup G
The Utils Project. G
Drawing Layer Manager G
Save Manager G
Attributes and VBA G
VBA Steel by Cyril Horsey cyril_h@smartchat.net.au G
Multiple Inserts by Robert Endres Rendres@Landrum-Brown.com G
Block Attribute Modifier by Robert Endres Rendres@Landrum-Brown.com G
AutoCAD and HTML - VBA G
Publishing Code G
Batch Convert to AutoCAD R14 by Scott McGlynn G
VB Standalone Applications
Create a Toolbar DLL. G
Create a Toobar DLL Re-Visited G
DLL Resource Tool G
AfraLisp Screensaver. G
Batch Purge 2002. G
Batch Purge 2004. G
RC-Batcher. G
Randall Raaths Lisp Manager. G
VBA Partial Menu. G
The Acad Export Drawings Project. G
Batch Purge Project. G
AfraLisp Drawing Backup G
How to write unmaintainable code G
Shadow Controls G
AfraLisp Coffee Holder G
AutoCAD and HTML - VB G
Custom Application Setup G
Would you like the AfraLisp Newsletterdelivered to your desktop?
If so, then just enter your email address in the box below and press the "Submit" button.
Subscribe Unsubscribe
Powered by YourMailinglistProvider.com

Visual Basic Tutorials


http://www.afralisp.com/vba.htm (2 of 3) [23/03/2005 05:43:10 p.m.]
Submit
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Visual Basic Tutorials
http://www.afralisp.com/vba.htm (3 of 3) [23/03/2005 05:43:10 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Welcome to AfraLisp
any moons ago whilst in a fit of madness or drunk - I
cannot remember which - I decided to write and publish a
simple web page containing a few AutoCAD Links and maybe a
couple of AutoLisp routines. Within a couple of days I began to
receive a few queries in regards to AutoLisp so decided to post
one or two Tutorials. That was the real beginning. Now, after
more than four years, AfraLisp has grown out of all proportion
in relation to my original intention.
AfraLisp now publishes over 100 AutoLisp Tutorials and nearly 50 VB/VBA Tutorials all open source and
complete with working examples. AfraLisp also publishes a download section containing many custom
AutoLisp applications written by AfraLisp as well as others.
AfraLisp also collaborates greatly with some other brilliant AutoLisp/VB/VBA sites, namely :
The Cad Vault is focused on helping you to improve your work environment
with tutorials and working code examples written in, and for, the most
popular customizing languages for the major CAD software programs and Microsoft Office products - Visual Basic
for Applications, Visual Basic, Visual C++, AutoLisp, Visual Lisp, and DCL.
And last but by no means least, CORBIMITE.COM is the host of AfraLisp and my thanks go to Frank
Zander for his generosity and support.
Would you like the AfraLisp Newsletterdelivered to your desktop?
If so, then just enter your email address in the box below and press the "Submit" button.
Subscribe Unsubscribe
Powered by YourMailinglistProvider.com

You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
AfraLisp-The AutoLisp/VBA Resource Website
http://www.afralisp.com/index.html (1 of 2) [23/03/2005 05:43:12 p.m.]
Submit
Search
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AfraLisp-The AutoLisp/VBA Resource Website
http://www.afralisp.com/index.html (2 of 2) [23/03/2005 05:43:12 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoLisp and Visual Lisp Tutorials
Basic AutoLisp Tutorials
AutoLisp Quick Start G
The Basics in a Nutshell. G
Loading Autolisp Files G
Autolisp Quick Reference Table. G
System Variables - Download G
System Variables 2002 - Alphabetical & Topical - Download G
System Variables 2004 - Alphabetical & Topical - Download G
AutoCAD 2004 System Variables G
AutoCAD and Customizable Support Files G
Environment Variables Listing G
Migrating Express Tools G
Enhanced Express Tools 2002 Menu G
Enhanced Express Tools 2004 Menu G
DXF Group Codes - Download G
AutoCAD Command History - Download G
The AfraLisp AutoLisp Tutorials G
Default Drawing Folder G
AutoLisp Basics - Download G
AutoCAD API's G
AutoLisp and Menu's
Partial Menu's G
Partial Menu's - Visual Lisp G
Custom Hatch Patterns and Menu Access G
Creating Hatch Patterns G
Creating Linetypes G
Controlling Complex Linetypes G
Automating Menu Loading G
Preserving Custom Toolbars G
Menu Customisation G
Dealing with Tool Palettes G
AutoLisp and Visual Lisp Tutorials
http://www.afralisp.com/tutor.htm (1 of 5) [23/03/2005 05:43:13 p.m.]
Advanced AutoLisp Tutorials
Define Function (defun) G
Set and Setq G
Programme Looping G
Conditionals. G
Cond vs If G
Error Trapping G
Calculating Points (Polar) G
Locating Files. G
File Handling. G
External Data G
List Manipulation. G
Into the DataBase. G
DXF Group Codes. G
Selection Sets. G
Selection Set Filters G
Working With Layers & Styles. G
Polylines and Blocks. G
Extended Entity Data. G
(mapcar) and (lambda) G
The 'Eval' Function. G
Redefining Commands. G
Efficient Variables. G
The "DIR" Command. G
Colours and Linetypes ByLayer G
Debugging G
Dictionaries and XRecords. G
Basic Tool System Primer G
Dialogue Box Tutorials
Getting Started G
DCL Primer - Download G
Dialog Box Layout G
Dialogue Boxes Step by Step G
Dialogue Boxe in Action G
Nesting and Hiding Dialogues. G
Hiding Dialogues Revisited. G
AutoLisp Message Box. G
AutoLisp Input Box. G
Referencing DCL Files. G
AutoLISP Functions for Dialog Control Language (DCL) G
AutoLisp and Visual Lisp Tutorials
http://www.afralisp.com/tutor.htm (2 of 5) [23/03/2005 05:43:13 p.m.]
Functional Synopsis of DCL Files. G
DCL Attributes. G
Dialogue Box Default Data. G
DCL Model. G
DCL Progress Bar. G
Attributes and Dialogue Boxes G
DCL without the DCL File G
The AfraLisp DCL Tutorials G
Entering Edit Boxes G
AutoLisp Application Tutorials
Drawing Setup G
AutoLisp/VBA Drawing Setup G
Application Data. G
Time and Date Stamping. G
AutoLisp Macro Recorder. G
Auto-Breaking Blocks. G
List Variables/Functions. G
Lisp Help. G
DOSLib - Batch Slides. G
AfraLisp Slide Manager G
Working with Areas G
Lisp to HTML G
AutoCAD and HTML - AutoLisp G
AutoCAD and HTML - Revisited G
Environmental Issues G
Quick Plot G
AutoCAD Command Line Switches G
David Steins's DSXTools G
Dave Corrals DC-Tools G
AutoCAD Setup G
Express Tools Utilities G
Publishing Code G
Rtext and Drawing Setup G
AutoCAD & Binaries G
PolyLine Bulges G
A Look at Plan G
Custom Application Setup G
Standing Alone with Acad Install G
Visual Lisp Tutorials
The Visual Lisp Editor - The Beginning G
The Visual Lisp Editor G
AutoLisp and Visual Lisp Tutorials
http://www.afralisp.com/tutor.htm (3 of 5) [23/03/2005 05:43:13 p.m.]
The Beginning G
Viewing Objects G
Properties & Methods G
Methods Reference G
Arrays G
Selecting Objects G
Collections G
Reactors G
Menu's G
Error Trapping G
Layers G
Profiles G
Sample Profile Utilities G
Attributes G
Attributes Re-visited G
Loading VBA Files G
Directories and Files G
Compiling AutoLisp Files G
VLAX Enumeration Constants G
Polylines G
The Utilities Object G
Visual Lisp and VBA G
AutoCAD and HTML - Visual Lisp G
The AfraLisp Visual Lisp Tutorials G
David Steins's Visual LISP Developers Bible G
Visual Lisp Sample Files G
Scripting Objects G
"Talking" to External Applications G
How to make Tripe and Onion's G
Would you like the AfraLisp Newsletterdelivered to your desktop?
If so, then just enter your email address in the box below and press the "Submit" button.
Subscribe Unsubscribe
Powered by YourMailinglistProvider.com

AutoLisp and Visual Lisp Tutorials


http://www.afralisp.com/tutor.htm (4 of 5) [23/03/2005 05:43:13 p.m.]
Submit
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoLisp and Visual Lisp Tutorials
http://www.afralisp.com/tutor.htm (5 of 5) [23/03/2005 05:43:13 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp Newsletter
Would you like the AfraLisp Newsletterdelivered to your desktop?
If so, then just enter your email address in the box below and press the "Submit" button.
Subscribe Unsubscribe
Powered by YourMailinglistProvider.com
Archives 2004
Issue 2004-01 G
Issue 2004-02 G
Issue 2004-03 G
Issue 2004-04 G
Issue 2004-05 G
Issue 2004-06 G
Issue 2004-07 G
Issue 2004-08 G
Issue 2004-09 G
Issue 2004-10 G
Issue 2004-11 G
Issue 2004-12 G
Issue 2004-13 G
Issue 2004-14 G
Issue 2004-15 G
Issue 2004-16 G
Issue 2004-17 G
Issue 2004-18 G
Issue 2004-19 G
Issue 2004-20 G

Archives 2003
Issue 2003-01 G
Issue 2003-02 G
Issue 2003-03 G
Issue 2003-04 G
Issue 2003-05 G
Issue 2003-06 G
Issue 2003-07 G
Issue 2003-08 G
Issue 2003-09 G
Issue 2003-10 G
Issue 2003-11 G
Issue 2003-12 G
Issue 2003-13 G
Issue 2003-14 G
Issue 2003-15 G
Issue 2003-16 G
Issue 2003-17 G
Issue 2003-18 G
Issue 2003-19 G
Issue 2003-20 G
Issue 2003-21 G
Issue 2003-22 G
Issue 2003-23 G
Issue 2003-24 G

AfraLisp Newsletter
http://www.afralisp.com/newsletter/newsletter.htm (1 of 3) [23/03/2005 05:43:15 p.m.]
Submit
Archives 2002
Issue 2002-01 G
Issue 2002-02 G
Issue 2002-03 G
Issue 2002-04 G
Issue 2002-05 G
Issue 2002-06 G
Issue 2002-07 G
Issue 2002-08 G
Issue 2002-09 G
Issue 2002-10 G
Issue 2002-11 G
Issue 2002-12 G
Issue 2002-13 G
Issue 2002-14 G
Issue 2002-15 G
Issue 2002-16 G
Issue 2002-17 G

Archives 2001
Issue 2001-01 G
Issue 2001-02 G
Issue 2001-03 G
Issue 2001-04 G
Issue 2001-05 G
Issue 2001-06 G
Issue 2001-07 G
Issue 2001-08 G
Issue 2001-09 G
Issue 2001-10 G
Issue 2001-11 G
Issue 2001-12 G
Issue 2001-13 G
Issue 2001-14 G
Issue 2001-15 G

Archives 1999
Issue 03-05-99 G
Issue 12-05-99 G
Issue 27-05-99 G
Issue 01-06-99 G
Issue 11-06-99 G
Issue 18-06-99 G
Issue 23-06-99 G
Issue 06-07-99 G
Issue 10-07-99 G
Issue 22-07-99 G
Issue 30-07-99 G
Issue 02-08-99 G
Issue 15-08-99 G
Issue 25-08-99 G
Issue 08-09-99 G
Issue 17-09-99 G
Issue 06-10-99 G
Issue 12-10-99 G
Issue 18-10-99 G
Issue 28-10-99 G
Issue 01-11-99 G

The AfraLisp Newsletter PDF Archives


If you so wish, you can download, in PDF format, all of the AfraLisp Newsletters.
This service will be updated on approx. a three monthly basis and/or as time allows.
Latest Updated Download : Issue 03-05-99 to 2004-07 Dated March 9th 2004 ( 1033 Kb )
New!! You can now download the AfraLisp Newsletters PLUS all 3 AfraLisp Books in one installation file. To do
AfraLisp Newsletter
http://www.afralisp.com/newsletter/newsletter.htm (2 of 3) [23/03/2005 05:43:15 p.m.]
so, just click here. ( 5227 kb)

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AfraLisp Newsletter
http://www.afralisp.com/newsletter/newsletter.htm (3 of 3) [23/03/2005 05:43:15 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
"Utter Rubbish"
Page II Page III Page IV Page V
Warning : Some of the articles in this section are slightly blue in nature, include bad language, are sexist
and are generally insulting to a whole cross section of people.
You have been warned!!
Disclaimer: If you take this section seriously you are an idiot, and any damages caused by taking these
articles seriously are deemed to be too bad.

Memo from Bin Laden


To: All Al Qaeda Fighters
From: Bin Laden, Osama
Subject: The Cave
Hi Guys
We have been putting in long hours recently but weve really come together as a
group and I love that. However, while we are fighting a jihad, we cant forget to
take care of the cave, and frankly I have a few concerns:
Fist of all, while it is good to be concerned about cruise missiles, we should be
even more concerned about the dust in our cave. We want to avoid excessive
dust inhalation, (a health and safety issue) so we need to sweep the cave daily.
I have done my bit on the cleaning rosterhave you??
I have posted a sign-up sheet near the cave reception area. Next to the halaal toaster.
Second: It is not often I make a video address but when I do, Im trying to scare the
living shit out of most of the worlds population, okay? That means that while were
taping; please do not ride your scooter in the background or keep doing the
Wassup thing. Thanks.
Third: Food. I bought a box of Dairylea recently. Clearly wrote Ossy on the front,
and put it on the top shelf. Today, two of my Daillea slices were gone.
Consideration. Thats all Im saying.
Fourth: Im not against team spirit and all that, but we must distance ourselves
from the Infidels bat and ball games. Please do not chant Ossy, Ossy Ossy, Oy Oy Oy
when I ride past on my donkey. Thanks.
Five: Graffiti. To whoever wrote OSAMA SHAGS DONKEYS on the group toilet wall,
its a lie. The donkey backed into me whilst I was relieving myself at the edge of the
mountain.
Six: The use of chickens is strictly for food. Assam, the old excuse that the chicken
backed into me, whilst I was relieving myself at the edge of a mountain will not
be accepted in the future. (With donkeys, there is a grey area)
Finally: Weve heard that there may be Western soldiers in disguise trying to infiltrate
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (1 of 18) [23/03/2005 05:43:19 p.m.]
our ranks. I want to set up patrols to look for them. First patrol will be Omar, Muhammad,
Abdul, Akbar and Dave.
Love you lots, Group hug.
Os
More Dinosaurs Are The Solution To The Oil Crisis
From somewhere off the web
IF YOU'VE been to a gas station lately, you have no doubt been shocked by the prices: $1.67, $1.78,
even $1.92. And that's just for Hostess Twinkies. Gas prices are even worse. Americans are ticked off
about this, and with good reason: Our rights are being violated! The First Amendment clearly states: "In
addition to freedom of speech, Americans shall always have low gasoline prices, so they can drive
around in 'sport utility' vehicles the size of minor planets."
And don't let any so-called "economists" try to tell you that foreigners pay more for gas than we do.
Foreigners use metric gasoline, which is sold in foreign units called "kilometers," plus they are paying
for it with foreign currencies such as the "franc," the "lira" and the "doubloon." So in fact there is no
mathematical way to tell WHAT they are paying.
But here in the United States we are definitely getting messed over, and the question is: What are we
going to do about it?
Step 1, of course, is to file a class-action lawsuit against the cigarette companies. They have nothing to
do with gasoline, but juries really hate them, so we'd probably win several hundred billion dollars. But
that is a short-term answer. To truly solve this problem, we must understand how the oil business
works. Like most Americans, you probably think that gasoline comes from the pump at the gas station.
Ha ha! What an idiot. In fact, the gasoline comes from tanks UNDER the gas station. These tanks are
connected to underground pipelines, which carry large oil tankers filled with oil from the Middle East.
But how did the oil get in the Middle East in the first place? To answer that question, we must go back
millions of years, to an era that geologists call the Voracious Period, when giant dinosaurs roamed the
Earth, eating everything that stood in their path,
except for broccoli, which they hated. And then, one fateful day (Oct. 8), a runaway asteroid, believed by
scientists to be nearly twice the diameter of the late Orson Welles, slammed into the Earth and killed the
dinosaurs, who by sheer bad luck all happened to be standing right where it landed. The massive
impact turned the dinosaurs, via a process called photosynthesis, into oil; this oil was then gradually
covered with a layer of sand, which in turn was gradually covered by a layer of people who hate each
other, and thus the Middle East was formed. For many years, the Middle East was content to supply the
United States with as much oil as we wanted at fair constitutional prices. But then the major
oil-producing nations-Saudi Arabia, Iran, Iraq, Kuwait and Texas-got all snotty and formed an
organization called OPEC, which stands for "North Atlantic Treaty Organization." In the 1970s, OPEC
decided to raise prices, and soon the United States was caught up in a serious crisis: The Disco Era. It
was horrible. You couldn't go to a bar or wedding reception without being ordered onto the dance floor
to learn "The Hustle."
AT THE SAME time, we also had an oil crisis, which was caused by the fact that every motorist in the
United States was determined to keep his or her automobile gas tank completely filled at all times. As
soon as your gas gauge dropped from "Full" to "Fifteen-sixteenths," you'd rush to a gas station and get
in a huge line with hundreds of other motorists who also had nearly full tanks. Also a lot of people,
including me, saved on heating oil by buying kerosene space heaters, which enabled us to transform a
cold, dank room into a cold, dank room filled with kerosene fumes. Buying gas and dancing "The
Hustle" with people who smelled like kerosene: That was the '70s.
So anyway, the oil crisis finally ended, and over time we got rid of our Volkswagen Rabbits and replaced
them with Chevrolet Suburbans boasting the same fuel economy as the World Trade Center. Now, once
again, we find ourselves facing rising gas prices, and the question is: This time, are we going to learn
from the past? Are we finally going to get serious about energy conservation? Of course not! We have
the brains of mealworms! So we need to get more oil somehow. As far as I can figure, there's only one
practical way to do this. That's right: We need to clone more dinosaurs.
We have the technology, as was shown in two blockbuster scientific movies, "Jurassic Park" and
"Jurassic Park Returns with Exactly the Same Plot." Once we have the dinosaurs, all we need is an
asteroid. Or, if he is available, Marlon Brando.
If this plan makes sense to you, double your medication dosage, then write to your congressperson.
Do it now! That way you'll be busy when I siphon your tank.
Aussie Humour
From down under.
The AfraLisp Fortune Teller
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (2 of 18) [23/03/2005 05:43:19 p.m.]
Pop in here to have your fortune told.
All You Needed To Know About Life
Author Unknown
If you take an Oriental person and spin him around several times, does he become disoriented?
- Only if he has to much to much saki before hand.
If people from Poland are called Poles, why aren't people from Holland called Holes?
- Dutchmen were called 'Holes' before the Pope in the Vatican kicked up a fuss when they were refered to as
'Holey-men'.
Do infants enjoy infancy as much as adults enjoy adultery?
- I know I did.
Why is the man who invests all your money called a broker?
- The word 'broker' has Spanish origins, alboroque, meaning 'ceremonial gift at conclusion of business deal'.
e.g., while they are making you money, they get a 'little gift' along the way.
Why is a person who plays the piano called a pianist, but a person who drives a race car not called a
racist?
What is the difference between a slim chance and a fat chance?
- From Old England when milk demand was high, so getting your milk was a problem. The chance of getting
slim milk and the chance of getting normal [fat] milk was known as slim chance and fat chance.
Why are a wise man and a wise guy opposites?
- Wise men were from biblical times and prefered to freely give away gifts to any new-born they saw at
Christmas time, whereas Wise guys were from America and prefered to sit on their ass all day and watch
repeats of 'The 3 Stooges' and so called named by the famous line 'Wise guys ,eh ?'. The Differences are quite
obvious.
Why do overlook and oversee mean opposite things?
- The two words overlook and oversee did have the same meaning [supervise] until the 1870's when many
construction site supervisors were turning blind eyes to malpractice on the site which risked their job. These
fore-men were then known as 'over-lookers' while the remaining men were known as the 'over-seers' where
from today's meanings evolved.
If horrific means horrible, does terrific mean terrible?
- Erm, yes it does. Both words terrific and terrible come from the same latin word, terrere, which means frighten.
Why isn't 11 pronounced onety-one?
- Onety-one became redundant when the wristwatch became widely popular. The word 'eleven' was introduced
to help the confusion when asked the time by another person, 11 o'clock or 'onety-one' was always
misunderstood as 'one to one'.
Do Roman paramedics refer to IVs as 4s?
- Quite by coincidence, the IVs [intravenous drip] used then were very similar this modern day and the length of
delivery tube to the vein was four feet.
If lawyers are disbarred and clergymen defrocked, doesn't it follow that electricians can be delighted,
musicians denoted, cowboys deranged, models deposed, tree surgeons debarked and dry cleaners
depressed?
- And I dare say porn stars are denuded, wine makers are deported, portrait artists are defaced and hens are
delayed.
Why do croutons come in airtight packages? It's just stale bread to begin with.
- And why does sour cream have a use-by date ?
When cheese gets its picture taken, what does it say?
- "Humans!"
If you mixed vodka & orange juice with milk of magnesia, would you get a Philip's Screw Driver?
- I dunno, but if you had too many, you'd vomit half back up and the other half out the rear end!!!
If a pig loses his voice, is it disgruntled?
- If a pig has lost its voice, it would have therefore been slaughtered. I think being disgruntled would be the last
thing on its mind.
'I am' is reportedly the shortest sentence in the English language. Could it be that 'I do' is the longest
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (3 of 18) [23/03/2005 05:43:19 p.m.]
sentence?
- Although the average marriage length has fallen over the last century, it is still a lot longer than just saying 'I
am".
If love is blind, why is lingerie so popular?
- Because men may be blind when it comes to love, but they know what's underneath it.
Why do women wear evening gowns to nightclubs? Shouldn't they be wearing nightgowns?
- A nightgown is a loose undergarment which women wear to bed. I should hope no female wishes to go out in
her nightgown [or maybe I should be hoping]
Why do they say something is out of whack? What is a whack?
- Term usually only used by junkies, where, they are in a coma are said to be 'out of whack'. A second term
coined by the junkies has a more literal meaning where 'whack', which of course means - hit. 'Out of whack' was
also out of drugs.
When someone asks you, A penny for your thoughts, and you put your two cents in, what happens to
the other penny?
- This was all part of the government's harsh "50% Two Cent Thought Tax" where after you have given your two
cents, the recipient must then remit 50% [one cent] to the tax department before the end of the month.
If you throw a cat out of the car window, does it become kitty litter?
- Only say, if another cat came up to it in the street, did it's business on its head, covered it with some gravel,
and then some-one chased you down to tell you to change it more often because it still stinks.
If you choke a Smurf, what color does it turn?
- Erm... blue.
Is it OK to use the AM radio after noon?
- Although the radio station owners find it cheaper not to, seeing people know its after midday, some stations
still can be found and listened to safely.
What do people in China call their good plates?
- Roughly, it translates to "a luxury"
What do you call a male ladybird?
- Mr. Ladybird.
What hair color do they put on the driver's license of a bald man?
- Most say 'none', but the modest ones say 'transparent'.
When dog food is new and improved tasting, who tests it?
- Erm... dogs.
Why do they sterilise the needle for lethal injections?
- So the dead person's lawyer cannot sue for negligence.
Why doesn't glue stick to the inside of the bottle?
- Erm... it does.
Why is it called tourist season if we can't shoot at them?
- The liberationists and greenies would be up in arms over the culling of poor, defenceless tourists.
Have you ever imagined a world without hypothetical situations?
- I would imagine that I wouldn't have to see a psychiatrist.
How does the guy who drives the snowplough get to work?
- Special underground cave networks that only classified people are allowed to know about.
If the 7 11 is open 24 hours a day, 365 days a year, why does it have locks on the door?
- For when it closes every 4 years on Feb. 29, the 366 day in a leap year.
If a fire-fighter fights fire and a crime fighter fights crime, what does a freedom fighter fight?
- Erm... freedom.
If they squeeze olives to get olive oil, how do they get baby oil?
- Of course, they only very gently squeeze them.
Why don't sheep shrink when it rains?
- The sheep themselves do not shrink, but the wool fibres on them shrink up to 10%.
What do chickens think we taste like?
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (4 of 18) [23/03/2005 05:43:19 p.m.]
- Firstly, they wonder how to get us in the oven.
Why didn't Noah swat those two mosquitoes?
- Swatters were not invented until post-biblical times.
Why do you need a driver's license to buy liquor when you can't drink and drive?
- Back in the days of alcohol prohibition, some retailers found a loop-hole in the law. The found it was not illegal
to sell liquor if it was to only be drunk in the vehicle whilst stationery, where they needed proof that the buyer did
own a car by having them show their licence. The tradition remains today.
Why are there flotation devices in the seats of planes instead of parachutes?
- We all know dead bodies in orange floaties are easier to see than dead bodies under parachutes.
Why are cigarettes sold at gas stations where smoking is prohibited?
- They used to sell guns, but they were considered dangerous. Go figure.
Why is a bra singular and panties plural?
- Both words have evolved over their years of use. Bra, of course, short for 'brassiere' is actually plural [from
Latin 'clothing hard to get off in dark by male']. Whereas, panties is a more feminine word for 'pant' which is
singular [from Latin 'male breathing heavy, as she hasn't got them off yet']
You know that indestructible black box that is used on airplanes? Why don't they make the whole plane
out of that stuff?
- Would you want to fly in a big, black, rectangular box which taped each conversation you had during your flight
and could only be opened by special secret-service agents ?
If you are driving at the speed of light and you turn your headlights on, what happens?
- The particles of light, or 'photons' they are called, are so abrasive at that as they slow down and you continue
your speed, it wears away at your car until of course, you crash and die.
Why do they put Braille dots on the keypad of a drive-up ATM?
- Erm... in case the blind person is behind in the back seat.
Why is it that when you transport something by car it is called shipment, but when you transport
something by ship it's called cargo?
- 'Shipment' by car was coined when people carting goods by car on a ferry was still called by ship, even when it
reached land, to tell where it came from. Ship's 'cargo' is from the French when the primary use of boats in
France was to ship snails for consumption [or as its called 'escargot'].
What would Geronimo say if he jumped out of an airplane?
- "What the fuck am I doing out of the plane ???"
Why are they called apartments when they are all stuck together?
- 'Apartments' were first built in the 1700's by the Scots, where they were apart from each other in the rural
country areas, some up to 3 miles apart. But fashionable Scots found moving them into cities required them to
be built next to each other.
If con is the opposite of pro, is Congress the opposite of progress?
- If you are the minority in the Congress, it certainly would.
If flying is so safe, why do they call the airport the terminal?
- Terminal is Latin for 'boundary', which is only a reference to the perimeter fence around to airport to stop
way-ward car-drivers getting on the runway.
If nothing sticks to teflon, how does it stick to the pan?
- Only the top surface of the 'Teflon' is non-stick, which is why the workers in the factory have to be very careful
putting the Teflon on the pan.
If you tickled a cow, would milk come out of its' nose?
- No. Only snot out its nose and a kick in your groin is all you will get.
Woman: Is there a problem, Officer?
Officer: Ma'am, you were speeding.
Woman: Oh, I see.
Officer: Can I see your license please?
Woman: I'd give it to you but I don't have one.
Officer: Don't have one?
Woman: Lost it 4 times for drunk driving.
Officer: I see...Can I see your vehicle registration papers please.
Woman: I can't do that.
Officer: Why not?
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (5 of 18) [23/03/2005 05:43:19 p.m.]
Woman: I stole this car.
Officer: Stole it?
Woman: Yes, and I killed and hacked up the owner.
Officer: You what?
Woman: His body parts are in plastic bags in the trunk if you want to see.
The Officer looks at the woman and slowly backs away to his car and calls for back up. Within minutes 5
police cars circle the woman and a senior officer slowly approaches the car, clasping his half drawn
gun.
Officer 2: Ma'am, could you step out of your vehicle please!
Woman: Is there a problem sir?
Officer 2: The officer told me that you stole this car and murdered the owner.
Woman: Murdered the owner?
Officer 2: Yes, could you open the trunk of your car, please.
The woman opens the trunk, revealing nothing but an empty trunk.
Officer 2: Is this your car, ma'am?
Woman: Yes, here are the registration papers.
The officer is quite stunned.
Officer 2: The officer claims that you do not have a driver's license.
The woman digs into her handbag and pulls out a clutch purse and hands it to the officer. The officer
snaps open the clutch purse and examines the license. He looks quite puzzled.
Officer 2: I must admit, ma'am, that I'm confused; the officer told me you didn't have a license, that you
stole this car, and that you murdered the owner.
Woman: I suppose the lying bastard told you I was speeding, too.
I heard today that Iraq had developed a special weapon for use against the Canadian Navy. It was called
a rust-seeking missile.
===========
In Iraq, I believe that they're replacing 100,000 Desert Marines with 1,000 women with PMS.
They're meaner, and they can retain water for 7 days
===========
What was Saddam Hussein's wife telling neighbors who asked why she's leaving the country?
a) "We're having some remodeling done."
b) "The exterminators are coming."
c) "We're getting the carpets bombed."
d) All of the above.
===========
Adviser: "Well, Mr. President, the deadline's expired. What shall we do?"
Bush: "Send in Colin Powell!"
Adviser: "Isn't that rather a limited strike, sir?"
Bush: "No, I mean send him in to my office!"
Powell: "Sir!"
Bush: "What would be the result of an air strike on Wednesday night?"
Powell: "Millions of innocent civilians killed and the city razed to the ground, Sir!"
Bush: "You know I don't understand that military jargon! Give it to me in words I can understand."
Powell: "Personnel density adjustment and strategic collateral upheaval, Sir!"
Bush: "That bad?!"
===========
Q. What is common between Saddam and Dukakis?
A. They both couldn't believe they lost to Bush.
===========
I can't quite call anything that drops off a plane traveling several hundred miles an hour and few
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (6 of 18) [23/03/2005 05:43:19 p.m.]
thousand feet in the air to dive nose first into a concrete wall just to explode "smart."
===========
How do you play Iraqi bingo?
B-52...F-16...B-52
===========
What is the Iraqi air force motto?
I came, I saw, Iran.
---------------------------------------------------------------------------------
Have you heard about the new Iraqi Air Force exercise program?
Each morning you raise your hands above your head and leave them there.
---------------------------------------------------------------------------------
What's the five-day forecast for Baghdad?
Two days.
---------------------------------------------------------------------------------
What do Miss Muffet and Saddam Hussein have in common?
They both have Kurds in their way.
---------------------------------------------------------------------------------
What is the best Iraqi job?
Foreign ambassador.
---------------------------------------------------------------------------------
Did you hear that it is twice as easy to train Iraqi fighter pilots?
You only have to teach them to take off.
---------------------------------------------------------------------------------
What is Iraq's national bird?
Duck.
---------------------------------------------------------------------------------
What do Saddam Hussein and General Custer have in common?
They both want to know where the hell those Tomahawks are coming from!
---------------------------------------------------------------------------------
Why does the Iraqi Navy have glass bottom boats?
So they can see their air force.
Stanley stops by to visit his friend who is paralyzed from the waist down.
They talk for a while and then the friend asks, "My feet are cold.
Would you be so kind as to go get me my house slippers please?"
Stanley obliges and goes upstairs.
There he sees his friend's daughters, both very good looking.
Being the adventurous and quick thinking kind, he says.....
"Hi, ladies! Your daddy sent me here to have sex with you!"
They stare at him and say, "That can't be!"
He replies, "OK, let's check!"
He shouts at his friend down the stairs, "Both of them?"
......"Yes, both of them!"
New Technology
An American, a Japanese and an Irishman were sitting naked in a sauna. Suddenly, there was a beeping
sound. The American pressed his forearm and the beep stopped. The others looked at him
questioningly. "That was my pager," he said, "I have a microchip under the skin of my arm." A few
minutes later a phone rang. The Japanese fellow lifted his palm to his ear. When he finished he
explained "That was my mobile phone, I have a microchip in my hand." The Irishman felt decidedly low
tech, but not to be outdone he decided he had to do something just as impressive. He stepped out of
the sauna and went to the toilet. He returned with a piece of toilet paper hanging from hisbehind. The
others raised their eyebrows and stared at him.
The Irishman finally said Well, will you look at that, I'm getting a fax.
Top 10 Historical uses of the 'F' word...
1 - "Scattered f___ing showers, my ass!" - Noah, 4314 BC
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (7 of 18) [23/03/2005 05:43:19 p.m.]
2 - "How the f___ did you work that out?" - Pythagoras, 126 BC
3 - "You want THAT on the f___ing ceiling?" - Michelangelo, 1566
4 - "Where did all those f___ing Indians come from?" - Custer,1877
5 - "It does so f___ing look like her!" - Picasso, 1926
6 - "Where the f___ are we?" - Amelia Earhart, 1937
7 - "Any f___ing idiot could understand that." - Einstein, 1938
8 - "What the f___ was that?" - Mayor Of Hiroshima, 1945
9 - "I need this parade like I need a f___ing hole in the head!" -
JFK,1963
10 - "Aw c'mon. Who the f___ is going to find out?" - Bill Clinton,1997
SOMETHING TO OFFEND EVERYONE PART I
What do you call two Mexicans playing basketball?
Juan on Juan.
What is a Yankee?
The same as a quickie, but a guy can do it alone.
What is the difference between a Harley and a Hoover?
The position of the dirt bag.
Why is divorce so expensive?
Because it's worth it.
What do you see when the Pillsbury Dough Boy bends over?
Doughnuts.
Why is air a lot like sex?
Because it's no big deal unless you're not getting any.
SOMETHING TO OFFEND EVERYONE PART II (JUST WARMING UP!)
What do you call a smart blonde?
A golden retriever.
What do attorneys use for birth control?
Their personalities.
What's the difference between a girlfriend and wife?
45 lbs.
What's the difference between a boyfriend and husband?
45 minutes.
What's the fastest way to a man's heart?
Through his chest with a sharp knife.
Why do men want to marry virgins?
They can't stand criticism.
Why is it so hard for women to find men that are sensitive, caring, and good-looking?
Because those men already have boyfriends.
What's the difference between a new husband and a new dog?
After a year, the dog is still excited to see you.
What makes men chase women they have no intention of marrying?
The same urge that makes dogs chase cars they have no intention of driving.
Why don't bunnies make noise when they have sex?
Because they have cotton balls.
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (8 of 18) [23/03/2005 05:43:19 p.m.]
What's the difference between a porcupine and BMW?
A porcupine has the pricks on the outside.
What did the blonde say when she found out she was pregnant?
"Are you sure it's mine?"
Why does Mike Tyson cry during sex?
Mace will do that to you.
Why did OJ Simpson want to move to West Virginia?
Everyone has the same DNA.
Why do men find it difficult to make eye contact?
Breasts don't have eyes.
Did you hear about the dyslexic Rabbi?
He walks around saying "Yo."
Why do drivers' education classes in Redneck schools use the car only on Mondays, Wednesdays and
Fridays?
Because on Tuesday and Thursday, the Sex Ed class uses it.
SOMETHING TO OFFEND EVERYONE, PART III (Just Great Stuff)
Where does an Irish family go on vacation?
A different bar.
Did you hear about the Chinese couple that had a retarded baby?
They named him "Sum Ting Wong"
What would you call it when an Italian has one arm shorter than the other?
A speech impediment.
What does it mean when the flag at the Post Office is flying at half-mast?
They're hiring.
What's the difference between a southern zoo and a northern zoo?
A southern zoo has a description of the animal on the front of the cage along with... "a recipe".
How do you get a sweet little 80-year-old lady to say the F word?
Get another sweet little 80-year-old lady to yell *BINGO*!
What's the difference between a northern fairytale and a southern fairytale?
A northern fairytale begins "Once upon a time..."
A southern fairytale begins "Y'all ain't gonna believe this shit..."
Why is there no Disneyland in China?
No one's tall enough to go on the good rides.
What did the guitarist do when his teacher told him to turn his amplifier on?
He caressed it softly and told it that he loved it.
Why do bagpipe players walk while they play?
To get away from the noise.
How many country & western singers does it take to change a light bulb?
Three. One to change the bulb and two to sing about the old one.
What does it say on a blues singer's tombstone?
"I didn't wake up this morning..."
What's the difference between a bull and an orchestra?
The bull has the horns in the front and the asshole in the back.
What would a musician do if he won a million dollars?
Continue to play gigs until the money ran out.
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (9 of 18) [23/03/2005 05:43:19 p.m.]
A man was walking down the street when he was accosted by a particularly dirty and shabby-looking
homeless man who asked him for a couple of dollars for dinner. The man took out his wallet, extracted
two dollars and asked, "If I gave you this money, will you buy some beers with it instead?"
"No, I stopped drinking years ago," the homeless man said.
"Will you use it to gamble instead of buying food?" the man asked.
"No, I don't gamble," the homeless man said. "I need everything I can get just to stay alive."
"Will you spend the money on greens fees at a golf course instead of food?" the man asked.
"Are you NUTS!" replied the homeless man. "I haven't played golf in 20+ years!"
"Well," said the man, "I'm not going to give you two dollars. Instead, I'm going to take you home for a
terrific dinner cooked by my wife."
The homeless man was astounded. "Won't your wife be furious with you for doing that? I know I'm dirty,
and I probably smell pretty bad."
The man replied, "Hey, man, that's okay! I just want her to see what a man looks like who's given up
beer, gambling, and golf!
Five men were bragging about how smart their dogs were. One was an
engineer, the second man was an accountant, the third man was a chemist,
the fourth was a computer tech, and the fifth was a government worker.
To show off, the engineer called his dog."T-square, do your stuff."
T-square trotted over to a desk, took out some paper and a pen and
promptly drew a circle, a square and a triangle. Everyone agreed that was
pretty incredible.
But the accountant said his dog could do better. He called to his dog
and commanded "Spreadsheet, do your stuff."
Spreadsheet went out into the kitchen and returned with a dozen
cookies. He divided them into 4 equal piles of 3 cookies each. Everyone
agreed that was good.
But the chemist said his dog could do better. He called to his dog
and said,"Measure, do your stuff. " Measure got up, walked over to
the fridge, took out a quart of milk, got a 10 ounce glass from the
cupboard and poured exactly 8 ounces without spilling a drop. Everyone
agreed that was
more than a little impressive.
The computer tech knew he could top them all."Hard Drive' have at
it." Hard Drive crossed the room and booted the computer, checked for
viruses, upgraded the operating system, sent an email, and installed a cool
new game.
Everyone knew that was a tough act to follow.
Then the four men turned to the government worker and said, "What can
your dog do?"
The government worker called to his dog and said, "Coffee Break, do
your stuff, Boy."
Coffee Break jumped to his feet, ate the cookies, drank the milk,
erased all the files on the computer, screwed the other four dogs, claimed
he injured his back while doing so, filed a grievance report for
unsafe working conditions, put in for workers compensation and went
home for six-month sick leave.
A man walks into a pharmacy and wanders up and down the aisles.
The salesgirl notices him and asks him if she can help him.
He answers that he is looking for a box of tampons for his wife.
She directs him down the correct aisle.
A few minutes later, he deposits a huge bag of cotton balls and a ball of string on the counter.
She says, confused, "Sir, I thought you were looking for some tampons for your wife?"
He answers, "You see, it's like this. Yesterday, I sent my wife to the store to get me a carton of
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (10 of 18) [23/03/2005 05:43:19 p.m.]
cigarettes, and she came back with a tin of tobacco and some rolling papers.... 'cause it's
sooooooooooo much cheaper. So....I figure if I have to roll my own... so does she...."
Things I Hate, by Billy Connolly..
1. People who point at their wrist while asking for the time....I know where my watch is pal, where the
f*ck is yours? Do I point at my crotch when I ask where the toilet is?
2. People who are willing to get off their arse to search the entire room for the TV remote because they
refuse to walk _to the TV and change the channel manually.
3. When people say "Oh you just want to have your cake and eat it too"
F*cking right! What good is a cake if you can't eat it?
4. When people say "it's always the last place you look". Of course itis. Why the f*ck would you keep
looking _after you've found it? Do people do this? Who and where are they?
5. When people say while watching a film "did you see that?". No tosser,
I paid 10 quid to come to the cinema _and stare at the f*cking floor.
6. People who ask "Can I ask you a question?". Didn't really give me a choice there, did you sunshine?
7. When something is 'new and improved!'. Which is it? If it's new, then there has never been anything
_before it. If it's an improvement, then there must have been something before it.
8. When people say "life is short". What the f*ck?? Life is the longest damn thing anyone ever f*cking
does!! What can you do that's longer?
9. When you are waiting for the bus and someone asks, "Has the bus come yet?".
If the bus came would I be standing here, Knobhead?
10. People who say things like 'My eyes aren't what they used to be'.
So what did they used to be? ears, _Wellington boots?
11. When you're eating something and someone asks 'Is that nice? 'No it's really revolting - I always eat
stuff I hate.
12. People who announce they are going to the toilet. Thanks that's an image I really didn't need.
13. McDonalds staff who pretend they don't understand you unless you insert the 'Mc' before the item
you are ordering.....It's has to be a McChicken Burger, just a Chicken Burger get blank looks. _Well I'll
have a McStraw and jam it in your McEyes you _f*cking McTosser.
14. When you involved in a accident and someone asks 'are you alright?'Yes fine thanks, I'll just pick up
my _limbs and be off - See Ya.
The Drinkers Prayer
(Author Unknown)
Starkle, starkle, little twink,
Who the hell are you I think.
I'm not under what you call
The alcofluence of incohol.
I'm just a little slort of sheep,
I'm not drunk like thinkle peep.
I don't know who is me yet,
But the drunker I stand here the longer I get.
So just give me one more fink to drill my cup,
'Cause I got all day sober to Sunday up.
Age
(Authors Unknown)
Three old men are walking on the sidewalk.
First one says, "Windy, isn't it?"
Second one says, "No, its Thursday!"
Third one says, "So am I. Let's go get a beer."
------------------------------------
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (11 of 18) [23/03/2005 05:43:19 p.m.]
A man was telling his neighbor, "I just bought a new hearing aid. It cost me four thousand dollars, but
it's state of the art. It's perfect."
"Really," answered the neighbor. "What kind is it?"
"Twelve thirty."
------------------------------------
Morris, an 82 year-old man, went to the doctor to get a physical.
A few days later the doctor saw Morris walking down the street with a gorgeous young lady on his arm.
A couple of days later the doctor spoke to Morris and said, "You're really doing great, aren't you?"
Morris replied, "Just doing what you said, Doc: 'Get a hot mamma and be cheerful.' "
The doctor said, "I didn't say that. I said, 'You got a heart murmur. Be careful.'"
------------------------------------
As a senior citizen was driving down the freeway, his car phone rang.
Answering, he heard his wife's voice urgently warning him, "Herman, I just heard on the news that
there's a car going the wrong way on Interstate 280. Please be careful!"
"It's not just one car," said Herman. "It's hundreds of them!"
----------------------------------------
An elderly gent was invited to his old friends' home for dinner one evening.
He was impressed by the way his buddy preceded every request to his wife with endearing terms -
Honey, My Love, Darling, Sweetheart, Pumpkin, etc...
The couple had been married almost 70 years, and clearly they were still very much in love.
While the wife was in the kitchen, the man leaned over and said to his host,
"I think it's wonderful that, after all these years, you still call your wife those loving pet names."
The old man hung his head. "I have to tell you the truth," he said, "I forgot her name
about 10 years ago."
So, you think you are clever do you?
(Kenny Ramage - March 2003)
So, you think you are clever do you?
Well, let me burst your bubble!!!!
There are some of you that know that I am a "Rock Super Star".
There are maybe still a few that still need to learn that!!
If so, you are one of the uninformed. Pay a visit here:
BedRock -The Band In The Sand
Okay, feel better now?
===================
Aside from my "musical" pastime, I've been heavily involved with coding and websites for many a year.
My main claim to fame though, is that I am a professional drawing office manager. I spent over 15 post
apprenticeship years on "the board" before moving into the realms of management. I know all the buzz
words. In fact, I wrote most of them, purely to piss the upper management off - I failed - they liked them.
Next time they ask you for a "balanced score card", blame me. I started it all by claiming that our pilots
should be the perfect example of one. Same number of landings as take-offs!
Anyway, what I was getting around to was this.
Do you want to be a professional coder?
Do you want to be a professional draughtsman/designer/whateveryoucallitinyourcountry?
Then you more than likely need to put in a bit of work and money.
Example from me in regards to my musical pastime:
Personal cost to me to produce the new CD, $3000 US (remember, there's 4 in the band). We've now
moved into the realms of Video/DVD - my share so far, $500 US - and we've just started on this project.
This does not include personal time, leave from work, personal equipment costs such as guitar strings,
amp blowing up, etc. Oh, and my beer bill is horrendous and my wife often doesn't speak to me.
We will recover most of it within a month - maybe two, but the point I'm trying to make is this! To
succeed - or should I get to basics here - to make a living out of something you do, takes a great deal of
investment in yourself.
I read nearly every post on VB Expresso, and I must say one thing - there are some really talented
people within this forum. BUT................ a lot of you have not got a clue of how to market yourself or
your talents. How can you say that Kenny? We are the elite of the CAD coding world. We can answer
any question that is thrown at us. We are the best!
Humbug. I say!!
First lesson:
You must learn how to sell yourself.
Don't do or give anything for free unless you receive some sort of payment, no matter how indirectly, in
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (12 of 18) [23/03/2005 05:43:19 p.m.]
return.
Example: I run AfraLisp and have spent many hours and "given" away lot's of ideas. True, but in my part
of the world, my marketability is way above my peers. And so is my salary and other perks.
Second Lesson:
You must learn how to communicate.
Example: Why do you have a strange handle such as "butlicker" or "womanizer"? Use your name. If
you're afraid of being recognized and your words don't carry the courage of your convictions, then don't
bother posting. You cannot use your participation on the web in your CV if you use a strange name.
Remember, this is business. It is not a teenage chat room. Check your spelling and your grammar. Hey,
your next boss could be reading your last post.
Third lesson: Make friends.
It's easy to criticise someone else's coding. It's even easier to do it in a nasty way. Don't!! Be a
gentleman or a lady at all times.
Example: I get all sorts of correspondence in regards to AfraLisp and Cad Encoding. The majority is
good, some downright rude. Each and every one receives a reply varying from friendly to polite, polite
being the key word here. Yes, you do have to put up with shit. Hey, it's a tough world. Don't dish it back,
learn how to deal with it. The web makes it very easy to hide behind an electronic screen. Don't do it!
Handle it like the professional that you profess to be. I work day to day with people that I don't
particularly like. So what? Must I slag them off because they do things I don't like. No I don't, I work with
them. The same goes when communicating on the web.
Fourth lesson: Spend money. Yes, YOUR money.
Not on a new car or house - at least not yet. Spend it on such things as professionally designed and
printed business cards. Or a professionally produced CV. Did you notice how the word "professional"
kept on rearing it's ugly head? Okay fine, you can produce the "same" thing at home on your computer.
YOU CANNOT!! And for one simple reason. You are not a professional graphics designer or printer
that's why. Spend some money and pay the experts. The same goes for software. Buy the software.
Stop copying the bloody stuff from your friends and then searching the web for a crack. You cannot run
a business using unlicensed, illegal software. And remember, the business is you. So if your software is
dodgy then maybe you are. Another thing. Keep books. Yes, every cent should be accounted for. How
else can you get yourself a line of credit if you don't keep account of the money? If your business does
take off you will need to first employ other people and then, more than likely, borrow money. Strangely
enough, when you employ someone they expect to be paid - on time. If you do not know exactly where
your money is going, how will you know if you have enough to pay them come pay day. In regards to
borrowing money, all bank managers will require a business plan before letting go of one cent. Your
books are your business plan.
Example: My wife is an ex-trainee accountant. She is now a librarian. Heather looks after all the money.
We don't have much, but every cent is accounted for. ALL my software is licensed. Some of it I paid for -
some I was given 'cos I'm nice.
Fifth lesson: Honesty and integrity.
You can makes lots of money, but in my eyes, if you lose these two then you lose life.
What Were You Doing 10 Years Ago?
(Kenny Ramage February 2003)
Me, well I was in exactly the same place as I am now - Oranjemund, Namibia. In those long lost days
though, I was a lowly design draughtsman with a year to go before I hit the big time and got the
promotion I so richly deserved. My oldest son was 12, my second 10, and my daughter still a wee mite
of 8 years. At this time of the year, we were getting all prepared to send off my oldest to boarding school
in Cape Town. He wanted to take a puppy. I said no!!
Programming - If memory serves me correctly, this was just about the time that we received our
upgrades from R12 to R13. We were still working in DOS, and I had no idea about such things as dialog
boxes, especially designing your own. Until that point, I'd been modifying the AutoCAD pull down
menus to run macros and AutoLisp routines. When R13 hit me, partial menus had come into play and
the buggers at AutoDesk had changed the whole format of the menu system. Just like that, everything
I'd written became null and void. Not that my programs were wrong and didn't work anymore. No, they
were more devious than that! I now couldn't trigger the bloody things.
This was my slow painful entry into the world of DCL. You may laugh now, but remember, in those days
we had no choice. VBA didn't exist. AutoLisp or nothing!!
To make matters worse, email and the Internet didn't exist, and being stuck in the middle of the desert I
had no access to any of the few AutoCAD magazines that were published in those days. I was stuck
with the AutoCAD reference manuals. Never, ever, ever do I want to repeat that exercise again and I
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (13 of 18) [23/03/2005 05:43:19 p.m.]
wouldn't wish it upon my worst enemy. How did I work it all out? Pure bloody trial and error that's how.
(Randall claims I still work the same way).
Bur, persist I did and maybe it did me a lot of good. It helped a lot in that I was in a working drawing
office and sort of "HAD" to make things work. (I made it work and a year later was promoted.)
Political - In Namibia, we'd gone through our independence a couple of years previously so things had
pretty well settled down. Our neighbour South Africa though - whom we rely on to a large degree - was
busy going through the birth pains of a change of government and the end of apartheid. Mandela was
about to be released, and there was a lot of concern over civil war breaking out. Thank the Lord it didn't.
People were hoarding food and fuel, rumours were flying around and everyone - white, black, pink and
green - were worried. Turmoilous times.
Music - I was "retired" from music at that time and to keep myself busy had got heavily involved with
the local amateur theatre on the directing and production side. Good fun. Pantomimes, Variety Shows,
even one or two "serious" productions. Some times I miss it. Mostly I don't. Why? Well in a band you've
got maybe 4 or 5 egos to contend with. In the theatre there's bloody hundreds - including the person
who takes the tickets. Never again - well, maybe once.
Other Hobbies - well I build two wooden ships from scratch with just the plans, and a few bits of
wood. (Honest). In fact my son Daniel said to his Mum today that when Dad dies he would like my ships.
Mmm - is that good or bad.
I also started playing Lawn Bowls - go on laugh. Great game and better than bloody golf 'cos at least
you don't lose your balls - or your temper.
(By the way - I ended up being Namibian Open Singles Champion and I've got the medals and photo's to
prove it. So there).
So, what were you doing 10 years ago? Care to share??
Insulting Humour
(Just replace the names with those of your enemies.)
(Authors Unknown)
If I offend anybody here, hey life's tough -----------------------
Kenny died in a fire and was burnt pretty badly and the morgue needed someone to identify the body. Of
course, his two best friends, Cornbread and Kinat, were sent for.
Cornbread went in and the mortician pulled back the sheet.
He said "Yup, he's burnt pretty bad. Roll him over". So the mortician rolled him over and Cornbread
looked and said "No, that ain't Kenny."
The mortician thought that was rather strange and then he brought Kinat in to identify the body. He took
a look at him and said, "Yup, he's burnt real bad, roll him over" The mortician rolled him over and Kinat
looked down and said, "No, that ain't Kenny"
The mortician asked, "How can you tell?"
Cornbread said, "Well, Kenny had two arseholes."
"What? He had two arseholes?" said the mortician.
"Yup, everyone knew he had two arseholes. Every time we went into town, folks would say........
"Here comes Kenny with them two arseholes...."
-------------
Randall walks into a bar, orders three pints of Guinness and sits in the back of the room, drinking a sip
out of each one in turn. When he finishes them, he comes back to the bar and orders three more.
The bartender asks him, "You know, a pint goes flat after I draw it; it would taste better if you bought
one at a time."
Randall replies, "Well, you see, I have two brothers. One is in Africa, and the other in Australia, and I'm
here in the US of A. When we all left home, we promised that we'd drink this way to remember the days
when we drank together."
The bartender admits that this is a nice custom, and leaves it there.
Randall becomes a regular in the bar, and always drinks the same way: He orders three pints and drinks
them in turn.
One day, he comes in and orders two pints. All the other regulars notice and fall silent.
When he comes back to the bar for the second round, the bartender says, "I don't want to intrude on
your grief, but I wanted to offer my condolences on your great loss."
Randall looks confused for a moment, then a light dawns in his eye and he laughs, "Oh, no" he says,
"everyone's fine. I've just quit drinking."
---------------
Dear Marie:
I have been engaged for almost a year. I am to be married next month.
My fiancee's mother is not only very attractive but really great and understanding. She is putting the
entire wedding together and invited me to her place to go over the invitation list because it had grown a
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (14 of 18) [23/03/2005 05:43:19 p.m.]
bit beyond what we had expected it to be.
When I got to her place we reviewed the list and trimmed it down to just under a hundred...then she
floored me. She said that in a month I would be a married man and that before that happened, she
wanted to have sex with me.
Then she just stood up and walked to her bedroom and on her way said that I knew where the front door
was if I wanted to leave. I stood there for about five minutes and finally decided that I knew exactly how
to deal with this situation. I headed straight out the front door...
There, leaning against my car was her husband, my father-in-law to be.
He was smiling. He explained that they just wanted to be sure I was a good kid and would be true to
their little girl. I shook his hand and he congratulated me on passing their little test. Marie, should I tell
my fiance what her parents did, and that I thought their "little test" was asinine and insulting to my
character?
Or should I keep the whole thing to myself including the fact that the reason I was walking out to my car
was to get a condom?
Dirty Howi
------------
Stig Madesen feeling very depressed walked into a bar and ordered a triple scotch. As the bartender
poured him the drink he remarked, "That's quite a heavy drink. Is something wrong?" After quickly
downing his drink Stig replied, "I got home and found my wife in bed with my best friend."
"Wow", exclaimed the bartender as he poured the man a second triple scotch, "No wonder you needed a
stiff drink. This one's on the house."
As Stig finished the second scotch, the bartender asked him, "So what did you do?"
"I walked over to my wife", Stig replied, "looked her straight in the eye and told her that we were
through. I told her to pack her bags and get the hell out."
"That makes sense", said the bartender, "but what about your best friend?"
"I walked over to him, looked him right in the eye and said 'Bad dog!'"
----------
Sherko walks into a bar and says "Gimme twenty shots of your best bourbon." The bartender pours the
shots, and Sherko immediately pounds them all down like a madman.
The bartender says "Man, I've never seen anybody drink like that before."
Sherko says "You'd drink like that too if you had what I have."
"What do you have?" asks the bartender.
Sherko says "Fifty cents."
Engineers Rules For When Dealing With The Drawing Office
Kindly donated by Andy Canfield (Cornbread)
Never give me work in the morning. Always wait until 4:00 and then bring it to me. The challenge
of a deadline is refreshing.
G
If it's really a rush job, run in and interrupt me every 10 minutes to inquire how it's going. That
helps. Or even better, hover behind me, advising me at every keystroke.
G
Always leave without telling anyone where you're going. It gives me a chance to be creative when
someone asks where you are.
G
If my arms are full of papers, boxes, books, or supplies, don't open the door for me. I need to
learn how to function as a paraplegic and opening doors with no arms is good training in case I
should ever be injured and lose all use of my limbs.
G
If you give me more than one job to do, don't tell me which is priority. I am psychic. G
Do your best to keep me late. I adore this office and really have nowhere to go or anything to do. I
have no life beyond work.
G
If a job I do pleases you, keep it a secret. If that gets out, it could mean a promotion. G
If you don't like my work, tell everyone. I like my name to be popular in conversations. I was born
to be whipped.
G
If you have special instructions for a job, don't write them down. In fact, save them until the job is
almost done. No use confusing me with useful information.
G
Never introduce me to the people you're with. I have no right to know anything. In the corporate
food chain, I am plankton. When you refer to them later, my shrewd deductions will identify them.
G
Be nice to me only when the job I'm doing for you could really change your life and send you
straight to Engineers' hell.
G
Tell me all your little problems. No one else has any and it's nice to know someone is less
fortunate. I especially like the story about having to pay so much taxes on the bonus check you
received for being such a good Engineer.
G
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (15 of 18) [23/03/2005 05:43:19 p.m.]
Wait until my yearly review and THEN tell me what my goals SHOULD have been. Give me a
mediocre performance rating with a cost of living increase. I'm not here for the money anyway.
G
Tell me to hurry up and finish so you can tell me about the changes you decided on at a meeting
yesterday.
G
Benchmark Test
(Kenny Ramage - November 2002)
AutoCAD VV-Lite
Recently, I received an unusual request from AutoDesk :
"Hi Kenny," it said, "Knowing that you are a man of high intellect, have a good understanding of the
AutoDesk range of products, and have never been found guilty of anything as charges were always
dropped, we would like you to benchmark and test our latest product namely - "AutoCAD VV-Lite" or, to
reveal it's true name, "AutoCAD Very, Very Lite."
Being a strong upstanding citizen (whilst standing,) I decide to give it a go.
AutoCAD VV-Lite is a brand new product aimed primarily at the person who has difficulty in
producing/reading a drawing. The major selling point of this package is that it is a state of the art,
seventh generation, ONE DIMENSIONAL Cad package. AutoDesk, after major research, identified the
need that a lot of draughtspersons/engineerpersons have in producing and or reading 2D drawings -
never mind 3D solid models or wire frames.
This was the niche that AutoDesk had been looking for!
Following are a couple of major features I picked up on whilst testing this truly unique software package
:
The first step is to select your mode of drawing. AutoCAD VV-Lite provides 3 modes - Horizontal
Mode, Vertical Mode and Angular Mode. Only one Mode at a time can be active. This exciting and
revolutionary feature removes all confusion and difficulty from having to remember what type and
orientation of entity you are drawing. A simple 3-way toggle switch, as used on the Space Shuttle,
allows you to cycle between modes.
An added bonus is that only one of the "Mode" types is displayed. This drastically reduces regen
time. e.g. If you are in "Horizontal Mode," only Horizontal entities are displayed.
G
Pull Down, Screen and Toolbar Menu's have been totally eliminated. In their place, a "stick on"
screen menu has been provided. This new menu type comes in all screen sizes and resolutions to
suit your VDU. (TV screens, drive-in screens and ice creams are not yet supported.)
G
All text is entered as normal, but appear on your screen in Lower Case Pittman's Shorthand. In
addition, all numeric characters are converted to binary code (1 and 0.)
Both these enhancements greatly help in reducing the pressure on system resources.
G
Blocks and Xref's are not inserted. Hieroglyphics are used instead. They are fully customisable. G
Every entity automatically snaps to all other entities within the drawing to avoid confusion of
which snap to use.
G
No scaling is necessary as "Not To Scale" is automatically applied to the drawing in the way of a
water mark.
G
When you draw an entity or insert a block, and if the system doesn't like what you are doing, or if
you take to long, the entity is deleted and your immediate supervisor is informed via e-mail.
G
AutoLisp is present in the form of a stripped version known as "AutoLisp VV-Lite."
The need for brackets has been eliminated.
G
These are just a few of the more powerful features present in this new, vastly improved package of
goodies from the AutoDesk stable. Keep your eye out for AutoCAD VV-Lite. It should hit the shelves
around about the last quarter of this year.
Tested on : Commodore 64 with 12 inch portable TV screen. G
Program Size (installed) : 53Kb G
Suggested retail price : $57- 36c US G
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (16 of 18) [23/03/2005 05:43:19 p.m.]
Platforms Supported : Windows, Doors and Ceiling. G
Rating : 4 peanuts and a keg. G
AutoCAD Training
(Kenny Ramage - November 2002)
I don't hate training, I detest it. How I ever ended up with the responsibility of training people on
AutoCAD I don't know. Well I do really. It's 'cos of my big mouth and having a tendency to "volunteer"
for what I think will be an interesting experience. Silly me! I'll never learn. I don't mind workshops, in fact
I quite enjoy that aspect of training. A workshop is different. At most workshops you're dealing with
people that want to be there and want to learn. Straight forward training is a totally different matter.
There you're dealing with people who have all sorts of reasons and agendas for having to attend the
course. Here's a couple of my pet hates :
The Absolute Total Executive Beginner.
They often arrive in a suit and tie and have normally been newly promoted. Many of them are on a "fast
track" career path and have decided (and there boss) that a half day "Introduction to the PC" followed
by a one day AutoCAD course is all that will be necessary to run a 20 seat CAD office. Of course, these
are the people who hold the purse strings and decide on new software. They normally leave just after
lunch to attend an important meeting.
The Quiet as a Mouse Invisible Man.
This person never says a word. He hides behind his computer screen ducking his head every time you
look at him. He never asks a questions and when asked if he understands gives a meek smile and
cleans his glasses. Half way through the session you normally discover that he got lost within the first
quarter of an hour and has just been pretending to go along with the lessons. You normally spend the
first tea break sitting with him to allow him to catch up with the rest of the class. At the end of the day
he's never finished and you end up pulling out the PC plug and pretending that there's been a major
power failure to get rid of him. He phones your every day for the next 6 months with questions
regarding the first lesson.
The Know it all Expert
This guy has normally finished the whole days syllabus before morning tea time. He doesn't listen to
word you say and does his own thing. When you do ask him a question he can't answer but shrugs it off
by telling his neighbour that he doesn't do it that way anyway. His way is quicker. He spends most of
the day rearranging his toolbars and doesn't need to learn AutoLisp or VBA because he doesn't have
time for coding. He has an extensive library of macros which he claims does the same as any program.
He normally wears a Bon Jovi World Tour 96 t-shirt and drives a VW Beetle. He claims he built his own
PC.
So, have you done any training? Have you got student types that you hate? Let me know and we'll add
them to the list.
The Atoms Family
(Kenny Ramage - October 2002)
A Never Ending Story
The rest of the Atoms Family were already having breakfast by the time Mr Atom, the Global Variable,
made his way down to the kitchen. As he was a long, he had to duck his head to get through the kitchen
door.
"Morning everyone," he setq'd.
"Morning Dad," the rest of the family chorused.
He defined himself on his chair and proceeded to tablesearch.
"I can't findfile my newspaper. Who set_tiled the table?" he setq'd.
"I did Dad," setq'd his son, "I must have errored and left it on the tblnext in the xroom. I'll getfiled it for
you now."
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (17 of 18) [23/03/2005 05:43:19 p.m.]
Mrs Atom, another Global Long, was busy entmaking breakfast.
"How should I defun your tiles dear?" she setq'd.
I'd like them well set," he menucmded, "Without a trace of lsh."
His son returned with his newspaper and xunloaded to his father who put on his vports, opened the
newspaper and proceeded to readline.
"Dad," his daughter prompted, trying to entmake conversation. "Could I go to the function tonight?"
Father was immediately alert. Slowly he turned the textpage of his newspaper.
Where is it being held?" he setq'd.
"In Paper Space," she replied.
"Well you are a double," he evaled. "How will you get there as it's quite a distance and the weather is so
bad that it's almost polar."
"We'll be transported by car," she setq'd.
"In that old Ascii your boyfriend constructed?" Dad said. "It's a wonder that it hasn't been picked up
during garbage collection. Okay, you can go, but on one condition. Do not mix with any of the local
variables. If they cause any arguments, do not stay, exit immediately."
"Can I go as well Dad?" setq'd his son.
"Getreal," his Dad replied, "You're still an integer. Anyway, I've got a list of commands and sub routines
for you."
"Oh Dad," his son wailed.
Now, now, foreach task you complete I will pay you one dollar.
First I want you to feed the strcat.
Then you can help me reverse the car out the garage, and while I'm out you can chop a log and then
progn the VCR."
To be continued, hopefully by a VBA version.
Would you like the AfraLisp Newsletterdelivered to your desktop?
If so, then just enter your email address in the box below and press the "Submit" button.
Subscribe Unsubscribe
Powered by YourMailinglistProvider.com

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Utter Rubbish
http://www.afralisp.com/utterrubbish.htm (18 of 18) [23/03/2005 05:43:19 p.m.]
Submit
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp's Tips 'n Tricks
Page II Page III

Entity Length
This will display the length of most entities :
;Coding starts here
(defun c:lg ( / x_object x_length)
(vl-load-com)
(setq x_object (entsel))
(setq x_object (vlax-Ename->Vla-Object (car x_object)))
(setq x_length (vlax-curve-getdistatparam x_object
(vlax-curve-getendparam x_object )))
(alert (strcat "Length = " (rtos x_length)))
(princ)
);defun
(princ)
;Coding ends here
Rtext
Have you had a good look at the Express Tools yet? Under the Text sub-menu there is a little gem of a routine called
"Rtext." Using this application you can insert Diesel expressions anywhere in your drawing. This is great for Plot
Stamps and much easier to setup and maintain than other Plot Stamp applications. Just insert it into your template
drawings and away you go.
Here's the one that I use :
Date Plotted : $(edtime, 0, Mon DD"," YYYY - H:MMam/pm)
Plotted By : $(upper, $(getvar, "loginname"))
This "stamps" the Plotted Date and Time as well as the users Login name.
Check out the "Rtext" help for more details and more uses.
AutoLisp Comments
Do you know that you can write block comments in your AutoLisp files like this :
;| This is the start of the comments.
You can carry your comments to multiple lines.
This will end your comments |;
Tips 'n Tricks Page I
http://www.afralisp.com/tips.htm (1 of 6) [23/03/2005 05:43:21 p.m.]

Lwpolyline
This AutoLISP function returns the vertex of a lwpolyline (print in this case). You can use this function
in AutoLISP routines to treat lwpolylines as AutoCAD Release 13 2D polylines.
;Coding starts here
(defun c:POINTS ()
(setq a (entget (car (entsel))) b a)
(while (/= (assoc 10 b) nil)
(print)
(princ (assoc 10 b))
(princ "\n")
(setq b (subst (cons 0 "SUBSTITUTE" (assoc 10 b) b))
)
(setq b nil)
(princ)
)
;Coding ends here
Model Tab
Have you ever wanted to want to view information about the Model tab or a Layout tab; for example,
such as the current output device and paper size.
The information for layout settings is now stored in the drawing dictionary.
Following is an example of how you would access the entity information for the Model tab in AutoLISP.
;;Begining of Sample code
(setq layList (dictsearch (namedobjdict) "ACAD_LAYOUT"))
(setq Index 0)
(while (and (/= (cdr (nth Index layList)) "Model")
(/= (nth Index layList) nil))
(setq Index (+ Index 1))
(if (nth (+ Index 1) layList)
(setq modelList (entget (cdr (nth (+ Index 1) layList))))
;;End of Sample Code
This code sets the "modelList" value equal to the entity information for the Model tab as they are stored
in the drawing dictionary. After running this routine, type !modelList on the command line and press
ENTER. The contents of modelList will be displayed on the command line.
Tips 'n Tricks Page I
http://www.afralisp.com/tips.htm (2 of 6) [23/03/2005 05:43:21 p.m.]
ARX Applications
When using certain AutoCAD commands in AutoLISP that are called from ARX applications (for
example, ROTATE3D and MIRROR3D), the following error message is displayed:
UNKNOWN Command
This error occurs because the ARX application was not already loaded into memory. To work around
this you must first determine what ARX application the command is from.
The following example AutoLISP routine uses the ROTATE3D command and determines if the
associated ARX application is loaded, and loads the application if it is not already loaded.
;;Start AutoLISP code
(defun c:drawsyl ( / acadObject Arxlist strArx)
(vl-load-com)
(setq acadObject (vlax-get-acad-object))
(setq Arxlist (vla-listarx acadObject))
(setq strArx (vlax-safearray->list (vlax-variant-value arxlist)))
(if (= (member '"geom3d.arx" strArx) nil)
(arxload "geom3d.arx")
);if
(command "cylinder" "0,0,0" "5" "20")
(command "rotate3d" "last" "" "x" "0,0,0" "19")
(princ)
);defun
(princ)
;;End AutoLISP code
Vertex Coordinates
You try to obtain the vertex coordinates of a 3D polyline using the following AutoLISP expression.
(entget (car (entsel)))
However, this expression only returns basic information about the 3D polyline; it does not return the
vertex coordinates, which are stored as a sub-entity of the 3D polyline.
Copy and paste the following coding into Notepad and save it as "ListVertex.lsp."
To run the routine, type ListVertex on the command line and press ENTER.
;Start of AutoLisp Coding
(defun c:ListVertex ( / ename n elist )
(setq ename (entsel))
(setq n 0)
(setq elist (entget (car ename)))
(setq ename (cdr (assoc -1 elist)))
(while (/= (cdr (assoc 0 elist)) "SEQEND")
(progn
(setq elist (entget (setq ename
(entnext ename))))
(if (assoc 10 elist)
(progn
(princ "\n ****** Vertex number ")
(princ n)
(princ "\n X = ")
(princ (cadr (assoc 10 elist)))
(princ " Y = ")
(princ (caddr (assoc 10 elist)))
(princ " Z = ")
(princ (cadddr (assoc 10 elist)))
(setq n (+ 1 n))
);progn
);if
);progn
);while
Tips 'n Tricks Page I
http://www.afralisp.com/tips.htm (3 of 6) [23/03/2005 05:43:21 p.m.]
(princ)
);defun
(princ)
;End AutoLisp Coding
A list of all loaded ARX applications will be created. If the geom3d.arx file is not listed, it will be loaded,
and a 3D cylinder will be created and rotated.
Drawing Path
To get the full path, you append the DWGPREFIX system variable (which stores the path) to the
DWGNAME system variable (which stores the file name).
Use code such as the following example to retrieve and assign the values of DWGNAME and
DWGPREFIX to variables in AutoLISP :
(setq DN (getvar "DWGNAME"))
(setq DP (getvar "DWGPREFIX"))
Use the AutoLISP function (strcat), to concatenate the results and assign them to a variable, for
example :
(setq TM (strcat DP DN))
In this example, the variable TM contains the full path including the file name.
Acad.lsp
Can anybody remember the Acad.lsp file? Now that there are MNL files and Acaddoc.Lsp, Acad.Lsp
would seem to be redundant. Well not really. The Acad.Lsp file is great for ensuring that partial menu's
are loaded.
So, want to ensure your custom menu/menu's, including pulldowns, are loaded
everytime AutoCAD is opened? Copy and paste this into your Acad.Lsp file
substituting your menu name where applicable :
;;;Start Coding Here
(defun MYSTARTUP ( );;;replace this line with the following if you are using R2000
;;;(defun-q MYSTARTUP ( )
;first set the flag
(setq flag1 T)
;check for the existence of the menu
(setq loaded (menugroup "MYMENU"))
;if it's not loaded
(if (= loaded nil)
;do the following
(progn
;find the menu
(setq temp (findfile "MYMENU.MNU"))
;if you find it
(if temp
;do the following
(progn
;suppress dialogues
(setvar "FILEDIA" 0)
;load the menu
(command "menuload" "MYMENU")
Tips 'n Tricks Page I
http://www.afralisp.com/tips.htm (4 of 6) [23/03/2005 05:43:21 p.m.]
;un-suppress dialogues
(setvar "FILEDIA" 1)
;load the first pulldown
(menucmd "P11=+MYMENU.POP1")
;load the second
(menucmd "P12=+MYMENU.POP2")
;tell them what you are doing
(prompt "\nLoading MyMenu Custom Utilities....\n")
);progn
;if you cannot find the menu, do this
(progn
;tell the it's missing
(alert "Cannot Locate MyMenu Menu. \n
Blame Randall Raath.")
;clear the flag
(setq flag1 nil)
);progn
);if
);progn
);if
;if the flag is set
(if flag1
;inform the user
(prompt "\nMyMenu Custom Utilities Loaded....\n")
);if
;finish clean
(princ)
);defun
;append your startup function to any other startup function
(setq S::STARTUP (append S::STARTUP MYSTARTUP))
;;;End Coding Here
Please ensure that all "MYMENU" menu files are in your AutoCAD search path.
Listing Symbols
The following will give you a list of all entries in a symbol table. This is
great for creating a list to populate a list box in DCL.
;;;Start Coding Here
(defun tablelist (s / d r)
(while
(setq d (tblnext s (null d)))
(setq r (cons (cdr (assoc 2 d)) r))
);while
);defun
;;;End Coding Here
Tips 'n Tricks Page I
http://www.afralisp.com/tips.htm (5 of 6) [23/03/2005 05:43:21 p.m.]
For example, if you would like a list of all layers in a specific drawing,
use this :
(setq all_layers (tablelist "LAYER"))
AutoLisp should return something like this :
("7" "6" "5" "4" "3" "2" "0")
To populate a list box with the key of "selections," use this :
(start_list "selections")
(mapcar 'add_list all_layers)
Command Line VBA
Did you know that you can run VBA statements from the command line?
Try this :
From AutoCAD's Command line
VBASTMT <enter> G
ThisDrawing.PurgeAll <enter> G
Page II Page III

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Tips 'n Tricks Page I
http://www.afralisp.com/tips.htm (6 of 6) [23/03/2005 05:43:21 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp Links
If you would like to have an AutoCAD or AutoLisp Link added
to this site, then please send details using the Contribution Form.
AutoCAD & AutoLISP
Autodesk H
Cadalog. H
Cadalyst. H
Cadence. H
The CAD Depot. H
Autolisper H
Gari's CAD Pages H
Reini Urban H
AutoLISP in Japan. H
Lintang Lives Here. H
AutoLisp Page H
@Acad+ H
BedRock H
Hurricane PowerTool H
DSXCad H
Asuni CAD H
Firehouse Designs H
Contract CADD Group H
3D Drafting H
kitoX.com H
G AutoCAD & AutoLISP
CadUser. H
The Cadshack. H
Custom Hatch Patterns H
CADesigner H
Acad Piping and Steel H
CadINFO.Net H
Cad Nauseam. H
upFront.eZine. H
EaglePoint Software. H
Australian CAD Links. H
Cadopolis H
Cad Code H
The Mech of Cad H
CADLandia (Italian) H
Gr-Acad (Portugese) H
Viking CAD H
MecaniCAD H
QnA~Tnt H
CADmechanic H
G

Tutorials/Forums
AfraLisp Tutorials. H
VBA Expresso H
CAD Encoding H
AutoCAD/AutoLisp Tutorials. H
Cadd Standards. H
AutoLisp Programming. H
Intervision H
AUGI H
AugAfrica H
AutoCAD User Groups H
G VBA/VB
Vbcad. H
VB Design. H
ActiveCAD. H
Contract CADD Group. H
AcadX.Com H
VB Free Code H
VB Code H
CopyPaste Code H
G
Links
http://www.afralisp.com/links.htm (1 of 2) [23/03/2005 05:43:23 p.m.]
Would you like to link to AfraLisp?
Here's an AfraLisp button designed by Michael deMott that you can use.
http://www.afralisp.com
Would you like the AfraLisp Newsletterdelivered to your desktop?
If so, then just enter your email address in the box below and press the "Submit" button.
Subscribe Unsubscribe
Powered by YourMailinglistProvider.com

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Links
http://www.afralisp.com/links.htm (2 of 2) [23/03/2005 05:43:23 p.m.]
Submit
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
The AfraLisp Privacy Statement
I promise that nobody will get your email address from me.

AutoCAD Tutorial Books


http://www.afralisp.com/privacy.htm (1 of 2) [23/03/2005 05:43:24 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD Tutorial Books
http://www.afralisp.com/privacy.htm (2 of 2) [23/03/2005 05:43:24 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Daily Cartoon
by Ted Goff
www.newslettercartoons.com
This license grants non-exclusive electronic rights to the use of Ted Goff's daily cartoon at no charge to
Kenny Ramage for use on http://www.afralisp.com or any web page on that domain.
Ted Goff
PO Box 22679
Kansas City, MO 64113
18/08/2003
See cartoons about:
Cartoons for your Presentations and Newsletters.

Daily Cartoon
http://www.afralisp.com/cartoon-a-day.htm (1 of 2) [23/03/2005 05:43:26 p.m.]
Yesterday's cartoon go
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Daily Cartoon
http://www.afralisp.com/cartoon-a-day.htm (2 of 2) [23/03/2005 05:43:26 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
The AfraLisp Tutorial Books
The three books below contain most of the AutoLisp/Visual Lisp/DCL Tutorials published on this
site. They are in a special PDF format in the sense that they will self destruct within one week and
reformat your hard drive unless you make a large donation to AfraLisp.
New!! You can now download all 3 books PLUS the AfraLisp Newsletters in one installation file. To
do so, just click here. ( 5227 kb)
AutoLisp Tutorials
785 kb
DCL Tutorials
1056 kb
Visual Lisp Tutorials
1566 kb
And here's something a little EXTRA (619 kb)
Now am I not nice to y'all?

AutoCAD Tutorial Books


http://www.afralisp.com/books.htm (1 of 2) [23/03/2005 05:43:28 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD Tutorial Books
http://www.afralisp.com/books.htm (2 of 2) [23/03/2005 05:43:28 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp Routines
Click Here for some Other AutoLisp Routines
These routines are provided as Un-Encoded Freeware
You are welcome to use them but please give me credit.
All Tutorials and Code are provided "as-is" for purposes of instruction and
utility and may be used by anyone for any purpose entirely at their own risk.
Please respect the intellectual rights of others.
All material provided here is unsupported and without warranty of any kind.
No responsibility will be taken for any direct or indirect consequences
resulting from or associated with the use of these Tutorials or Code.

Metric Steel Section Tool Palettes.


For use with AutoCAD 2004 and AutoCAD LT 2004
Note : All files must be unzipped to C:/AFRALISP/STEEL/ and all directory structures must be
maintained.
Contents :
C_PFC
Parallel Flange Channels PFC G
C_RSC
Tapered Flange Channels RSC G
E_Angle
Equal Angle Legs EA G
U_Angle
Unequal Angle Legs UA G
U_Beam
Universal Beams UB G
U_Col
Universal Columns UC G
Joist
Tapered Flange Joists RSJ G
H_Sect_C
Circular Hollow Sections CHS G
H_Sect_R
Rectangular Hollow Sections RHS G
AutoLisp Files
http://www.afralisp.com/mylisp.htm (1 of 5) [23/03/2005 05:43:29 p.m.]
Form_C
Formed Channels FC G
Form_CL
Formed Lipped Channels FLC G
Form_A
Formed Angles FA G
Form_AL
Formed Lipped Angles FLA G
DDSTEEL (265 Kb) UPDATED FOR AutoCAD 2002+
This set of routines, draws 2D Metric Structural Steel Sections.
Sections available are :-
Universal Beams
Universal Columns
Tapered Flange Channels
Parallel Flange Channels
Joists
Equal Leg Channels
Unequal Leg Channels
Circular Hollow Sections (User Input Only)
Rectangular/Square Hollow Sections (User Input Only)
All Section Properties are based on the South African Steel Construction Handbook.
DDPIPE (274 Kb) UPDATED FOR AutoCAD 2002+
This set of routines, draws 2D Metric Piping Sections.
Sections available are :-
Pipes
Flanges
Flanges in Elevation
90 Degree Elbows
45 Degree Elbows
Concentric Reducers
Eccentric Reducers
Lobster Back Bends
All Section Properties are based on British Standards.
Panzoom (4Kb)
One technique used for fast viewing of drawings is to divide the drawing into regions.
You can then quickly zoom into those regions. This application uses an AutoLisp routine
and a toolbar to automate the viewing of your drawing in four regions. The four regions
are always based on the current limits of the drawing.
1. Copy the files Panzoom.lsp, Panzoom.mnu and Panzoom.dll to any directory within the
AutoCad support path.
2. Open AutoCad.
3. Load the partial menu file Panzoom.mnu.
The toolbar is displayed after you complete the procedure.
AutoLisp Files
http://www.afralisp.com/mylisp.htm (2 of 5) [23/03/2005 05:43:29 p.m.]
The four directional arrows represent each quarter of the drawing. The AutoLisp routine
will automatically be loaded and run when you select one of the directional arrows.
Lisp Manager(16 Kb)
This application will allow you to view the first 10 lines
of any AutoLisp file. It will then give you the choice between
loading or editing the relevant AutoLisp file.
You can also download the VBA version here.
SuperCP - Batch Convert and Purge (3 Kb)
This routine will Batch Convert/Purge a directory of drawings AND all it's
sub-directories.
It will Batch Convert to:
R12, R13, R14, Template, DWF, DXF, BMP, and WMF.
It will Batch Purge :
All, Blocks, Dimstyles, Layers, Linetypes, Shapes,
Styles and Multilines.
Change to Reference Layer.(4 Kb)
Quite often you need to change a group of objects to a Reference Layer.
This allows you to distinguish between reference objects and new objects
and also allows you to plot the reference objects using a lighter pen.
Unfortunately, when you change these objects to the reference layer,
their linetype changes to the Reference Layers default linetype as well
as to the Reference Layers default colour.
This routine changes all objects to the Reference Layer but retains
their original linetype. You can also select a different colour from that
of the layers default colour if you so wish.
The routine also allows you to filter out selected layers that will not
be changed to the Reference layer.
Break Circle.(1 Kb)
This routine will break a circle and change either of the broken
sections to a different layer. I have it preset to layer 2 (Hidden Line),
but this can easily be changed to suit your needs. You will need to have
a line bisecting the circle at the two points where you want the circle to
be broken. The routine will snap to these two points and then ask you which
portion you wish to change.
Architectural Doors and Windows.(6 Kb)
This is a series of routines for parametrically drawing Doors and Windows.
It comes with a partial menu (Arch.mnu) containing an Architectural
Toolbar. Please note that both doors and windows will require a
AutoLisp Files
http://www.afralisp.com/mylisp.htm (3 of 5) [23/03/2005 05:43:29 p.m.]
reference line crossing the wall at the insertion point.
The Doors will be inserted at the hinge point and the Windows
at the centre of the window. The routines will automatically
break and trim the openings.
Item Symbol (10 Kb)
This draws an Item symbol with annotation.
USERR1 must be set to drawing scale.
Section Symbols (26 Kb)
This draws section symbols with annotation.
USERR1 must be set to drawing scale.
Level Symbols (15 Kb)
This draws vertical or horizontal level symbols with annotation.
USERR1 must be set to drawing scale.
Metric Conveyor Idlers (11 Kb)
This routine draws metric Conveyor Idlers using a
dialogue box interface.
Metric Nuts and Bolt (10 Kb)
This routine draws metric nuts and bolts using a
dialogue box interface.
Metric Bolt Holes (17 Kb)
This routine draws metric bolt holes using a dialogue
box interface.
Change Layer or Colour (2 Kb)
This routine allows you to change any objects layer
or colour by choosing from a dialogue box.
Conveyor Trajectory (3 Kb)
This routine plots the trajectory of material leaving
a conveyor Head Pulley.
Click Here for some Other AutoLisp Routines
AutoLisp Files
http://www.afralisp.com/mylisp.htm (4 of 5) [23/03/2005 05:43:29 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoLisp Files
http://www.afralisp.com/mylisp.htm (5 of 5) [23/03/2005 05:43:29 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA Quick Tips.
VBA Hyperlink
Would you like to create a hyperlink to your favourite website on a form using VBA? Thought so!
Open a new project in VBA and insert a new Userform.
Add a label to the form and change the Caption to the URL of your website.
e.g. http://www.afralisp.com
Change the colour of the label to Blue - Underlined.
e.g. http://www.afralisp.com

Now add the following coding to the click event of the label :
'<- Coding Starts Here
Private Sub Label1_Click()
Dim nFile As Integer
'Write a temp file URL
nFile = FreeFile
Open "\TEMP.URL" For Output As #nFile
Print #nFile, "[InternetShortcut]"
Print #nFile, "URL=http://www.afralisp.com"
Close #nFile
'Launch the browser
Shell "rundll32.exe shdocvw.dll,OpenURL " & "\temp.url", vbNormalFocus
'Delete the temp file
Kill "\TEMP.URL"
End Sub
' Coding Ends Here
Voila, you have a hyperlink on your form.
Control Template
Ever get tired of making an exit button over and over? Do you use the same set up for multi
page (or any control) over and over? Save time, save effort. Make a control template!
1) Start with a New VBA Project in AutoCAD (or any VBA enabled application)
2) Add a UserForm to the project
VBA Quick Tip's
http://www.afralisp.com/vbaa/vbatips.htm (1 of 6) [23/03/2005 05:43:31 p.m.]
3) Draw a command button on the form
4) If the properties window is not visible, click properties on the View Menu
5) Make sure that the properties for the command button are being listed in the properties
window, then change the following items:
6) Caption = Exit
7) Font = Arial (example, use your favorite font)
8) From the file menu choose close and return to AutoCAD (or whatever application you are
setting up).
9) Close AutoCad, when prompted to save the changes to Global1 say "yes" (save it under
any name, you will open it right back up).
10) Restart AutoCAD and load the dvb file saved in step 7.
11) Drag the command button you customized in step 5 onto the controls tab of the Toolbox.
Command Line VBA
Did you know that you can run VBA statements from the command line?
Try this:
From AutoCAD's Command line
1. VBASTMT <enter>
2. ThisDrawing.PurgeAll <enter>
CD Rom Drive
Let VB determine if the CD Rom drive contains media.
To quickly determine if the CD Rom drive contains media, use the Scripting Runtime library's IsReady
property for the Drive object.
For CD Rom drives, this property returns True only if the drive contains the appropriate media. To
take advantage of this handy property, add a Reference to Microsoft Scripting Runtime library
(scrrun.dll). Next, create a Drive variable based on the CD Rom drive, and test the IsReady property, as
shown below :
Dim FSO As FileSystemObject
Dim CDDrive As Drive
Set FSO = New FileSystemObject
Set CDDrive = FSO.GetDrive("E:")
If CDDrive.IsReady Then
MsgBox CDDrive.VolumeName
Else
MsgBox "Please enter a CD."
End If
Set CDDrive = Nothing
Set FSO = Nothing
Type-Declaration Characters
In addition to declaring a variable as its explicit data type,VB also lets you declare certain
data types using a single type-declaration character.
For example, instead of using :
Dim MyString As String
you can use:
VBA Quick Tip's
http://www.afralisp.com/vbaa/vbatips.htm (2 of 6) [23/03/2005 05:43:31 p.m.]
Dim MyString$
Here's a complete list of the data-types and their corresponding characters :
String ($)
Integer (%)
Long (&)
Single (!)
Double (#)
Currency (@)
Of course, you should use these characters with caution, as they do reduce your code's readability.
Add Controls to a VB Control Array at Run-time.
As you probably know, a control array lets you create controls that share the same name and
events. They also use fewer resources than do the same number of controls not part of a
control array. Often, you may want to add a control, such as a button, to a control array at
runtime. To do so, you use the Load statement, which takes the following syntax :
Load object(index)
where object is the name of the control array, and index is the index number of the new control you
want to add. In order to add controls to a control array at runtime, however, you must have at least one
control already in the array, (with it's index property set-most likely to 0). VB only allows 32,767
controls in an array.
For example, suppose you have a form with a button control array named cmdBtn. On the button's
Click event, you want to add another button to the form. To illustrate, open a new project and add a
command button to the default form. In the Properties Window, enter 0 for the control's Index. When
you do, VB transforms the button into a control array. Now, add the following code to the form:
Private Sub cmdBtn_Click(Index As Integer)
Dim btn As CommandButton
Dim iIndex As Integer
iIndex = cmdBtn.Count
If iIndex <= 32767 Then
Load cmdBtn(iIndex)
Set btn = cmdBtn(iIndex)
With btn
.Top = cmdBtn(iIndex - 1).Top + 620
.Caption = "Command" & iIndex + 1
.Visible = True
End With
Set btn = Nothing
End If
End Sub
When you run the form, and click the button, the procedure adds a new button to the form.

Listbox - Deleting Items.


To delete selected items from a multiselect listbox, loop backwards through the items, then
remove those where the Selected property tests True. For example, suppose you have a list
box with item1, item2, item3, item4, item5. You've set the control's MultiSelect property to
Extended or Simple and have selected item1, item3, and item5. To remove them from the
listbox use code similar to the
following:
VBA Quick Tip's
http://www.afralisp.com/vbaa/vbatips.htm (3 of 6) [23/03/2005 05:43:31 p.m.]
Private Sub cmdDeleteListItems_Click()
Dim i As Integer
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then List1.RemoveItem i
Next i
End Sub
Extending the Timer Control.
As you know, the Timer control provides a great way to schedule events in a VB project.
When you enable the control, it fires off its Timer event every n milliseconds, as determined
by the TimeInterval property. However, the TimeInterval property only accepts numbers up to
65,535, or just over one minute. As a result, you may have wondered how to use this control
for periods longer than that.
To do so, use a form, or project level, variable to keep track of how many times the Timer event fires.
Then, in the Timer event, re-enable the control if enough time hasn't passed. For example, consider the
code below that we attached to a standard form.
Option Explicit
Dim iElapsedMin As Integer
Const cMax_Min As Integer = 2
Private Sub Form_Load()
Timer1.Enabled = True
iElapsedMin = 1
End Sub
Private Sub Timer1_Timer()
lblText.Visible = (iElapsedMin = cMax_Min)
Timer1.Enabled = (iElapsedMin < cMax_Min)
iElapsedMin = iElapsedMin + 1
End Sub
Here, the iElapsedMin variable maintains the elapsed minutes. We also created a constant to hold the
maximum time we want to wait before turning the lblText control visible, (in this case 2 minutes). After
one minute, the Timer event fires and disables the Timer control. However, if the elapsed time is less
than the maximum time, then the procedure enables the control once more, starting
the process all over again.
Create an Excel object in VB.
First, assign a new reference to your VB app, "Microsoft Excel 8.0 Object Library" -
Excel8.olb
Dim objExcel As New Excel.Application
'-- Display Excel Application
objExcel.Visible = True
'-- Add new Workbook
objExcel.Workbooks.Add
'-- Set Text
objExcel.ActiveCell(1, 1) = "Row 1 Col 1"
objExcel.ActiveCell(1, 3) = "Row 1 Col 3"
VBA Quick Tip's
http://www.afralisp.com/vbaa/vbatips.htm (4 of 6) [23/03/2005 05:43:31 p.m.]
'-- Release the object variable
Set objExcel = Nothing
Be sure to check out the Object Browser in VB for more properties/methods
of the Excel object.

Performing the Windows shutdown operation


Ever wondered how programs that you install automatically perform the Windows shutdown
operation? Well, it's actually a simple API call to do this. Add the following API Declares and
Constants to a BAS Module:
Declare Function ExitWindowsEx& Lib "user32" (ByVal uFlags&, ByVal
wReserved&)
Global Const EWX_FORCE = 4 'constants needed for exiting Windows
Global Const EWX_LOGOFF = 0
Global Const EWX_REBOOT = 2
Global Const EWX_SHUTDOWN = 1
Then you Shutdown/reboot/logoff windows with the following call:
lresult = ExitWindowsEx(EWX_SHUTDOWN, 0&) 'shut down the computer
Note: Replace the first parameter of the ExitWindowsEx function call with the appropriate
CONSTANT.
A new Format function.
VB 5 has the Format command that almost works the same as Print.
The difference is that Format shortens the output string length if all the format characters are
not used. To work around this I wrote a Public Function called FormatNum.
Public Function FormatNum(MyNumber As Double, FormatStr As String)
'This Function returns number formated as a string with the desired
'minimum number of characters
'MyNumber - Use CDbl(MyNumber) in the function call to prevent type
'mismatch error.
FormatNum = Format(MyNumber, FormatStr)
If Len(FormatNum) < Len(FormatStr) Then FormatNum = Space(Len(FormatStr) _
- Len(FormatNum)) & FormatNum
End Function
Use this function like this:
Print #FileNumber, FormatNum(CDbl(MyVariable), " #### ")
Highlight Text.
When you display a form, it's nice to highlight the text in a particular text box
so that the user does not have to delete the existing text before typing in his
new text string. Here's the coding :
**************************************************************************
VBA Quick Tip's
http://www.afralisp.com/vbaa/vbatips.htm (5 of 6) [23/03/2005 05:43:31 p.m.]
Private Sub UserForm_Initialize()
UserForm1.TextBox1.SetFocus
'set focus to the textbox
UserForm1.TextBox1.SelStart = 0
'start at the first character
UserForm1.TextBox1.SelLength = Len(UserForm1.TextBox1.Text)
'highlight the text string
End Sub
*********************************************************************
Double Click a List Box.
How do you create a double-click event for a list box?
Easy. From the Double-click event procedure of the list box, simply call the click event
procedure of the OK button :
*******************************************************************
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CommandButton1_Click
End Sub
*******************************************************************
Private Sub CommandButton1_Click()
'Your coding goes here..............
End Sub
********************************************************************
Format Numbers.
Here's a quick tip that allows you to set the number of leading zeros, or to round to a certain
decimal point. Let's say you want to print '1.234000' in '001.234' format. To do this, use :
format(1.234000,"000.######")

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Quick Tip's
http://www.afralisp.com/vbaa/vbatips.htm (6 of 6) [23/03/2005 05:43:31 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Some Other Lisp Files.
The products referenced in this site are provided by parties other than AfraLisp.
AfraLisp makes no representations regarding either the products or any information about the products.
Any questions, complaints, or claims regarding the products must be directed to the appropriate Author.
File Listing.
Watson. (116 kb).
Written By : Aaron J. Strom.
Watson is an Experimental Artificial Intelligence Program.
Try This if You Dare!!

Re-number Text (2 kb)


Written by Jarvis Fosdick
Have you ever wanted to sort text items by there point values in AutoCad?
This lisp re-numbers text objects. it works well if you have some general notes, say 1 through 15, on
your drawing and you want to add a new note between 5 and 6. With this lisp you select all of the
numbers and it will reorder them starting with 1.
Format Solview Layers (4 kb)
Written by Andrew Levan
The downloadable LISP is called Format Solview Layers or FSL. For those of you using AutoCAD
R14 - 2002 to do 3D, the solview command is critical to this process. However, it creates layers "on
the fly". This creates a problem from a standardization point of view for a company, because you
cannot use pre-defined templates for standard layer colors, linetypes, etc. This program will search
for the created layers and format them to predefined or custom standards.
I welcome any comments about the program. I know it's a little rough around the edges (especially
in the interface and error handling areas) but I took it as far as I could in the time I had.
-----------------------------
Andrew Levan
Project Engineer
Marsden, Inc.
Email: alevan@marsdeninc.com
External AutoLisp Files
http://www.afralisp.com/olisp.htm (1 of 7) [23/03/2005 05:43:34 p.m.]
Web: http://www.marsdeninc.com
Visual Lisp Functions (12 kb)
Written By Michel Loftus
Below is a list of general purpose routines that I have written over the past year or so, most have
been written as part of other, more specific routines that I have written, I have included all of the
routines that are contained in the VLX file, although some may be similar to routines already
featured on this site.
These functions should all work correctly, but containing only minimal error checking
There are five Trigonometric functions :
1 (deg->rad angle): input angle in degrees as a real or int, returns angle in radians as real
eg (setq a (deg->rad 180)) = 3.14
2 (rad->deg angle): input angle in radians as a real or int, returns angle in degrees as real
eg (setq a (rad->deg (/ pi 2.0))) = 90
3 (tan angle): input angle in radians, returns tangent of angle as real
eg (setq a (tan (/ pi 4))) = 1.0
4 (asin real): input real, returns arcsine of number in radians
eg (setq a (asin 0.5)) = 0.523
5 (acos real): input real, returns arcosine of number in radians
eg (setq a (acos 0.5)) = 10.0472
G
nine general AutoCAD functions :
6 (3d->2d 3d point) returns a 2d point
eg (setq a (3d->2d '(0 0 0))) = (0 0)
7 (2d->3d 2d point level) returns a 3d point with z value equal to level or 0.0 if nil
eg (setq a (2d->3d '(0 0) 0)) = (0 0 0)
8 (stringp val): input a value, returns true if value is a string else nil
eg (stringp "Hello") = true
9 (intp atom): returns T if atom is an integer
eg (intp 1) = true
10 (realp atom): returns T if atom is a real number
eg (realp 1.0) = true
11 (c:lbo): changes layer of select object to objects colour
12 (c:ca): like the align command but copies the object(s)
13 (c:blktxt): converts text representing a number into a block
G
Nine list manipulation tools :
14 (vl-remove-last list): input list, removes last element from list
eg (setq a (vl-remove-last '(1 2 3))) = (1 2)
G
External AutoLisp Files
http://www.afralisp.com/olisp.htm (2 of 7) [23/03/2005 05:43:34 p.m.]
15 (strl_sort list): input list of strings, similar to (acad_strlsort) but sorts numbers
numerically
eg (strl_sort '("b" "a" "10" "1")) = ("1" "10" "a" "b")
16 (remove atom list): similar to (vl-remove) but only removes first occurance of atom in list
eg (remove 1 '(1 1 2 1)) = (1 2 1)
17 (nth-remove nth list): removes nth element from list
eg (nth-remove (0 '(1 2 3))) = (2 3)
18 (vl-add atom nth list): adds atom as nth element of list
eg (vl-add 2 1 '(3 3)) = (3 2 3)
19 (sublist start length list): returns a number of elements after start position from a list
eg (sublist 1 2 '(1 2 3 4 5)) = (2 3)
20 (remlist start length list): removes a number of elements after start position from a list
eg (remlist 1 2 '(1 2 3 4 5)) = (1 4 5)
21 (list->string delim list): input deliminator as string, list, converts elements of list to a
deliminated string
eg (list->string "*" '("1" "2")) = "1*2"
22 (strconv list): converts elements of list into strings
eg (strconv '(1 2.5 "h")) = ("1" "2.5" "h")
Eleven String functions :
23 (ltrim string): input string, removes any spaces from the beginning of the string
eg (ltrim " trim ") = "trim "
24 (rtrim string): input string, removes any spaces from the end of the string
eg (rtrim " trim ") = " trim"
25 (trim string): input string, removes spaces from beginning and end of string
eg (trim " trim ") = "trim"
26 (string->list string): input string, returns the string a list using spaces a delimineater
eg (string->list "Hello World") = ("Hello" "World")
27 (mid string string): input two strings, returns first string if it is found within second string
else nil
eg (mid "to" "AutoCAD") = "to"
28 (replace oldstring newstring string): replaces occurrences of oldstring in string with
newstring
eg (replace "\t" " " "Line one\tLine two") = "Line one Line two"
29 (stringtype string): returns data type of contents of the string
eg (strtype "1.5") = "REAL"
30 (right string int): returns number of characters from right of string
eg (right "AutoCAD" 3) = "CAD"
31 (left string int): returns number of characters from left of string
eg (left "Hello" 4) = "Hell"
G
External AutoLisp Files
http://www.afralisp.com/olisp.htm (3 of 7) [23/03/2005 05:43:34 p.m.]
32 (multiline string int): returns string as a list of strings, each element being no longer than
int but finishing with a full word if possible
eg (multiline "Hello New World" 3) = ("Hel" "lo " "Wor" "ld")
33 (stringcase string int): changes string case 0 or nil Upper Case, 1 Lower Case, 2 Initail
Character Upper Case rest Lower
eg (stringcase "hello world" 2) = "Hello World"

Two Selection Set Functions :


34 (sslist pickset): input selectionsel, returns list of selected entities
eg (sslist (ssget)) = (<Entity name: 40061d70> <Entity name: 40061d68>)
35 (foreachss string quoted function): iterates through entities in a selection set
eg (foreachss "i" (ssget) '(entdel i)) - this will delete all of the selected entities
G
If you have any comments or suggestions as to improvements please contact me - Michel Loftus
Bike Lisp (198 kb)
Written By : Alan - ksa@ksa-architects.com
Would you like to design your own custom bicycle?
Not only is this very clever, it's also good fun.
IDeclare.exe (28 kb).
Written By : rplaird@earthlink.net
IDECLARE searches given LISP source file(s) for undeclared local variables and declares any such
found. Any new declares made are flagged with a comment.
Global variables are recognized by having a '#' (number sign) as the first
character. The original LISP input file will be renamed with the file extension
ORG. Wildcard characters '*' and '?' can be used in the LISP input file name.
The global variable identifying character can be changed by giving the new
identifying character as the second parameter on the command line, after the
file name. A new file extension for the original LISP input to be saved under
can be given as the third command line argument.
Test DCL Lisp (1 kb).
Written By : M.P. Saju.
Testing DCL files becomes a necessity when developing a good sized lisp
application for easy input and understanding. This routine in lisp was
written for just such a necessity.
Usage is very simple... Just type "Testdcl" in Autocad text screen and press
"Enter". A file selection dialog box will open up to select the DCL file.
On entering, the DCL under test will open. This application works under
the assumption that there is an active "accept" or "cancel" button.
ISO Hole Base Tolerances. (8 kb).
Written By : Peter Best.
External AutoLisp Files
http://www.afralisp.com/olisp.htm (4 of 7) [23/03/2005 05:43:34 p.m.]
This routine will display and print ISO hole base tolerances.
Roughen (4 kb).
ROUGHEN.LSP: AutoLISP program to "roughen" a polyline.
Written By Mark Middlebrook.
Use ROUGHEN when you want to turn a polyline or line into an
irregularly zigzaggy line. For example, you can use roughened lines
to designate existing concrete surfaces that have been roughened
for better adhesion with new concrete.
This version of ROUGHEN works with AutoCAD R12 through 2000.
It roughens the newer AutoCAD R14 lwpolyline objects ("lightweight
polylines"), as well as older "heavyweight" polyline objects.
Flatten (4 kb).
FLATTEN sets the Z-coordinates of these types of objects to 0
in the World Coordinate System:
"3DFACE" "ARC" "ATTDEF" "CIRCLE" "DIMENSION"
"ELLIPSE" "HATCH" "INSERT" "LINE" "LWPOLYLINE"
"MTEXT" "POINT" "POLYLINE" "SOLID" "TEXT"
Written By Mark Middlebrook.
FLATTENing is useful in at least two situations:
You receive a DXF file created by another CAD program and discover
that all the Z coordinates contain small round-off errors. These
round-off errors can prevent you from object snapping to
intersections and make your life difficult in other ways as well.
1.
In a supposedly 2D drawing, you accidentally create one object with
a Z elevation and end up with a drawing containing objects partly
in and partly outside the Z=0 X-Y plane. As with the round-off
problem, this situation can make object snaps and other procedures
difficult.
2.
Warning: FLATTEN is not for flattening the custom objects created by
applications such as Autodesk's Architectural Desktop. ADT and similar
programs create "application-defined objects" that only the
application really knows what to do with. FLATTEN has no idea how
to handle application-defined objects, so it leaves them alone.
Hot Blocks v1.2 (120 kb).
A block manager with an INI style customization file and a dialog box, performing
collection-grouping, file path display, and slide previews as 'hot thumbnails'.
Build your own dwg block library with it, and make them ready to be inserted
easily, anytime.
Created by Lintang Darudjati :
...Lintang Lives Here...
lintangd@geocities.com
Slide Factory v1.0 (10 kb).
Automates the process of creating multiple slides and slide-libraries. It creates
External AutoLisp Files
http://www.afralisp.com/olisp.htm (5 of 7) [23/03/2005 05:43:34 p.m.]
slide files for all DWG files found in a user-selected folder. It also creates
a slide library file (SLB) if desired. Just select a folder containing one or
more DWG files, and the rest of process is in Slide Factory's hands.
Created by Lintang Darudjati :
...Lintang Lives Here...
lintangd@geocities.com
Layer Color Fixer v1.0 (17 kb).
A small program for AutoCAD users. It fixes layer colors for plotting purposes
(via a dialog box) by assigning layer colors to an INI-style config file that
matches specific pen settings.
Created by Lintang Darudjati :
...Lintang Lives Here...
lintangd@geocities.com
Visual Basic Functions Version 1.0. (5 kb).
Written by : Roger Farley, cgL Services - Cincinnati, Ohio.
Vbfunc1.Lsp contains Visual Basic type functions for the Autolisp programming language.
There are quite a few useful functions in VB, which are not available in Autolisp that would come
in rather handy, especially if you are a VB programmer working in Autolisp.
So far, this program contains only a few functions, but will be upgraded on a regular basis as the
functions are developed.
Function Catalog
1.0 LTRIM: Trims spaces from leading end of text.
e.g. (setq a (ltrim " text")) sets variable 'a' to "text".
2.0 RTRIM: Trims spaces from trailing end of text.
e.g. (setq a (rtrim "text ")) sets variable 'a' to "text".
3.0 TRIM: Trims spaces from leading and trailing end of text.
e.g. (setq a (trim " text ")) sets variable 'a' to "text".
4.0 STRICHR: Finds character in string and returns position as integer
index from left.
e.g. (setq a (strichr "text" "x")) sets variable 'a' to 3.
5.0 STRCNT: Counts number of occurrences of character in string and
returns count as integer.
e.g. (setq a (strcnt "abracadabra" "a")) sets variable 'a' to 5.
6.0 LCASE: Changes case of string to all lower case.
e.g. (setq a (lcase "TEXT" )) sets variable 'a' to "text".
7.0 UCASE: Changes case of string to all upper case.
e.g. (setq a (ucase "text" )) sets variable 'a' to "TEXT".
8.0 FCASE: Changes case of first character of string to upper case.
e.g. (setq a (fcase "text" )) sets variable 'a' to "Text".
For comments, suggestions or special requests Roger can be reached via
e-mail at rfarley@cglscvs.com.
Flanges. (10 kb).
Written By : Peter Best.
External AutoLisp Files
http://www.afralisp.com/olisp.htm (6 of 7) [23/03/2005 05:43:34 p.m.]
This programme draws Pipe Flanges using a dialogue
interface. Various flange specifications are included.
Very Good.......
Accumalative Distance. (1 kb).
Written By : Don Jacobsen.
This routine is pretty much like the Distance command with the
exception that it allows you to pick more than two points.
The routine displays the cumulative distance of all those
points picked. As you are picking the points it also displays a
running total and the distance between the last two points picked.
Metric Fasteners. (8 kb).
Written By : Peter Best.
This program will calculate standard lengths of bolts. It allows for 2 washers,
nut, and 4 pitches of thread after the nut.
Spring washer is optional. It will draw the bolt assy and individual components
as polylines after picking 2 points.
Fastener.dcl and Fastener.lst are used with this program.
Well done Peter, you're where the first on this page...

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
External AutoLisp Files
http://www.afralisp.com/olisp.htm (7 of 7) [23/03/2005 05:43:34 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
The AutoCAD API's When and Why
Written by Andrew Canfield
There are three major API's with which you can extend AutoCAD. They are respectively: a C/C++ api called
objectARX, a VB/VBA api, and an AutoLisp/VisualLisp api. Every developer has their favorite but all partiality
aside people often wonder which is better, which should I use? The answer to those questions is: "It depends on
what you need to accomplish". Each API has different things, which make it better in given situations. When
deciding on which API to use there are 4 things you need to ask yourself. What language am I most comfortable
in? How much time do I have? Who is the target user and how much AutoCAD experience do they have? How
much control over AutoCAD and possibly Windows do I need to accomplish the task quickly? After I address
some of the functionality of the different API's you will see why these are relevant. I am only going to deal with
these API's as they apply internally to AutoCAD not as stand alone applications.
The objectARX API:
Out of the three API's this one has the most control over AutoCAD and Windows. You can register its commands
with AutoCAD. The user needs to know very little about AutoCAD to run your program. The drawbacks to it are it
takes longer to develop in it for most developers than VBA or Lisp, and often it is overkill especially for simple
drafting tools. To get anything done in this API you should already be very familiar with C and C++. On a personal
level this API is my favorite but that is because I do 99% of all my development in C and C++ so when I do
something for AutoCAD it's easier for me not to have to switch languages. For me it falls into the category of
"what language am I most comfortable with?". There are things within AutoCAD that this API can access that the
other API's cannot. This is the major reason for most developers who use this API. They need to do something
and it literally cannot be done using the other two API's. This is also the only API to which you can secure your
code from having others read and copy your source. If you need to develop custom objects, work with spatial
filtering, expose functionality to an application using another API, are developing third party tools for sale, or a
host of other things to which VBA and Lisp cannot access without great difficulty or at all then this is the API you
should use.
The VBA API:
If this is your first time extending the functionality of AutoCAD than this is most likely the API for you. This API is
very friendly towards new developers. The Visual Basic language reads in such a way that many times new
developers can work out simple questions by just reading the names of the functions. This API does not have as
much access to AutoCAD as the C++ or Lisp API's do however you can construct and execute Lisp commands to
give yourself access to the few things that Lisp can do which VBA cannot natively. If you are very good with VBA
you can subclass the AutoCAD command line and then there really isn't anything Lisp has access to which you
wouldn't using VBA. The major drawback to the VBA API is that it doesn't natively register your functionality with
AutoCAD. It must first be loaded as a dvb in any of the various ways you can load applications into AutoCAD and
then executed via the tools menu or by a custom button or menu item. Depending on your user base this can be a
big issue. I have worked on contracts where the drafters are all used to commands and don't want to use anything
else. In this case VBA can be a difficult sell. If the user group isn't that stuck in there ways then VBA is usually a
very easy sell. Especially after they see how fast you can create tools with it. As with Lisp this is primarily an
internal developer's tool to extend AutoCAD within your company, or if you have been contracted to work on site
to write custom tools. Out of all the API's this is the one, which can create applications the most quickly
especially applications, which require graphic dialogs. It also has the most support from AutoDesk.
The Lisp API:
When I am speaking of Lisp I am specifically referring to AutoLisp and VisualLisp I am not talking about ANSI
Common Lisp. First a quick description of AutoLisp. "AutoLisp: it combines the RAD features of iX86 with the
flexibility of COBOL". All kidding aside the major reason the Lisp API gets used is because for many developers it
satisfies the question "What language am I most comfortable in?". For many people this is where they started and
it is what they are fastest developing in. Another reason to use this API is, if the environment in which you work
has large legacy libraries of Lisp routines. Lisp is harder than VBA to learn yet still far easier than C or C++. Until
AutoCAD 2000, VBA was not very well implemented inside of AutoCAD and left a great deal to be desired. Lisp
was the primary choice for rapid in house development of macro's. Large libraries of Lisp functions exist in many
places. Re-writing these in VBA is often not cost effective in the short term. If this is the case then Lisp is the tool
for you and may God have mercy upon your soul. Kidding sort of. There are some very serious downsides to
using Lisp so if you are new to developing for AutoCAD or need to interface your functionality with any other
Windows programs or the Windows operating system you may want to look into VBA instead. On the upside if
you are interfacing with a program written for the objectARX API it is a lot easier for the objectARX developer to
AutoCAD API's
http://www.afralisp.com/vba/api.htm (1 of 4) [23/03/2005 05:44:02 p.m.]
expose their functionality to Lisp than VBA but a good developer should be able to do either so it really depends
on who is writing the C++ side of things as to which they expose their functionality to.

Here is a simple checklist for determining which API may be right for your project:
ObjectARX:
You are most comfortable working in C or C++ G
You need the absolute maximum amount of control over AutoCAD and Windows G
You need to write custom objects G
You need access to things which are not exposed to VBA or Lisp G
You require more speed than can be had using VBA or Lisp G
Your workplace requires applications be developed in C or C++ G
You need to use libraries external to AutoCAD which are only available to C or C++ G
VBA:
You are most comfortable working in VBA G
You need to use a dialogs G
You need to interface with Windows or one of the Microsoft office programs like Excel G
You are new to developing for AutoCAD or are new to developing period G
You require maximum speed of development time yet are not overly worried about application speed G
You know you are going to need a lot of help from Autodesk getting your application written G
Lisp:
The world ended and there are no other tools available G
You are most comfortable working in Lisp G
You are working with an AutoCAD version prior to 2000 G
You are working in one of those gray areas in AutoCAD where Lisp can do something that would require a
huge amount of VB knowledge to accomplish the same thing.
G
Your workplace requires it G
Your workplace may need to interface existing Lisp libraries with your tool G
You enjoy pain G
You don't need any dialogs or graphical user interaction other than the command line/screen pics in your
application
G
Parens make you happy (oh look here come the men in white coats for you now) G
Now I will provide what you all come here for really. Free code. Yes, that's right we know that's why you really
read this stuff isn't it. So since you suffered through the above I suppose I shall have to reward you with free code
so that you come back. In each of the three API's I show a way to edit the first editable attribute in a block
reference. The use of "command" will not be seen here as that is a huge pet peeve of mine. If you are using
"command" you are not programming you are scripting and they are two completely separate things.
AutoCAD API's
http://www.afralisp.com/vba/api.htm (2 of 4) [23/03/2005 05:44:02 p.m.]
ObjectARX:
void chngAtt()
{
ads_name entres;
ads_point ptres;
AcDbObjectId _Id, _attId;
AcDbObjectIterator *pIttr = NULL;
if(acedEntSel("Select a Block Reference", entres, ptres) != RTNORM )
{
//Selection failed
return;
}
acdbGetObjectId(_Id, entres);
AcDbObjectPointer pRef(_Id,AcDb::kForRead);
if(pRef.openStatus()!=Acad::eOk)
{
//Open failed
return;
}
pIttr = pRef->attributeIterator();
while(!pIttr->done())
{
_attId = pIttr->objectId();
AcDbObjectPointer pAtt(_attId,AcDb::kForWrite);
if(pAtt.openStatus()==Acad::eOk)
{
pAtt->setTextString("We changed this");
break;
}
pIttr->step();
}
delete pIttr;
}

VBA:
Option Explicit
Sub chngAtt()
Dim objEnt As AcadObject
Dim objRef As AcadBlockReference
Dim varAtts As Variant
Dim objAtt As AcadAttributeReference
Dim emptyPt As Variant
ThisDrawing.Utility.GetEntity objEnt, emptyPt, "Select Block: "
If objEnt.ObjectName = "AcDbBlockReference" Then
Set objRef = objEnt
If objRef.HasAttributes Then
varAtts = objRef.GetAttributes
Set objAtt = varAtts(0)
objAtt.TextString = "We changed this"
End If
End If
End Sub

AutoCAD API's
http://www.afralisp.com/vba/api.htm (3 of 4) [23/03/2005 05:44:02 p.m.]
Lisp:
(defun C:chngAtt ()
(setq Mainent (entsel))
(setq entList (entget (car Mainent)))
(setq entAtt (entget (entnext (cdr (assoc -1 entList)))))
(setq entNewAttVal
(subst (cons 1 "We changed this") (assoc 1 entAtt) entAtt)
)
(entmod entNewAttVal)
(entupd (car Mainent))
(princ)
)

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD API's
http://www.afralisp.com/vba/api.htm (4 of 4) [23/03/2005 05:44:02 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
An Introduction to VB and VBA.
Visual Basic is a descendant of the BASIC programming language first developed in the
1960's. BASIC (which is short for 'Beginner's All-purpose Symbolic Instruction Code') is
probably well known to most computer programmers.
Microsoft Visual Basic allowed programmers to create stand-alone Windows
applications which previously required the use of complex C programming
languages. Visual Basic for Applications is a subset of Visual Basic, designed
specifically for certain applications such as MS Word, Excel, Access, etc.
With the release of AutoCAD R14, AutoCAD has included VBA as part of the
AutoCAD package. VBA for AutoCAD includes most of the functions and controls
available in the stand-alone version of Visual Basic alongwith specific functions and
controls specifically designed for AutoCAD.
If Visual Basic is the first experience you, as a programmer, have had with 'event driven'
programming, then read on and enter the world of Visual Basic..........
Event Driven Applications.
An event is an action recognized by a form or control. Event driven applications execute
Visual Basic code in response to an event. Each form and control in VBA has a
predefined set of events. If one of these events occurs, VBA invokes the code in the
associated event procedure.
Although objects in VBA automatically recognize a predefined set of events, you determine if and
how they respond to a particular event. When you want a control to respond to an event, you write
code called an event procedure for that event.
Many objects recognize the same event, although different objects can execute
different event procedures when the event occurs. For example, if a user clicks
a userform, the Userform_Click event procedure executes; if a user clicks a command button
named CommandButton1, the CommandButton1_Click event procedure executes.
Here's what happens in a typical event driven application:

The application starts and a form or control receives an event. The event can be caused by the
user (for example a keystroke), or by the system (for example a timer), or indirectly by your
code (for example, a Load event procedure when your code loads a form.
1.
If there is an event procedure corresponding to that event, it executes. 2.
The application waits for the next event. 3.
Note : Many events occur in conjunction with other events. For example, when the DblClick event
occurs, the MouseDown, MouseUp and Click events also occur.
Event Driven vs Traditional Programming.
In a traditional or 'procedural' application, the application itself rather than
an event controls the portions of code that execute. Execution starts with the first line of
executable code and follows a predefined path through the application, calling
procedures as needed.
An Introduction to VB and VBA
http://www.afralisp.com/vbaa/vbatut2.htm (1 of 3) [23/03/2005 05:44:03 p.m.]
In event driven programmes, a user action or system event executes an event procedure.
Thus, the order in which your code executes depends on which events occur, which in turn depends
on what the user does. This is the essence of graphical user interfaces and event driven
programming: The user is in charge, and your code responds.
Because you can't predict what the user will do, your code must make a few assumptions about 'the
state of the world' when it executes. When you must make assumptions (for example, that a text box
has text in it before a command button is pressed), you should try to structure your application so
those assumptions are always valid (for example, disabling the command button and enabling it
only in the Change event procedure for the text box).
Your code might trigger additional events as it performs additional operations. For example,
loading a Userform causes the Userforms Load event to occur, and changing the Text property of a
text box causes the text box's Change event to occur.
Objects.
Each object in VBA is defined by a 'class'. To understand the relationship between an
object and it's class, think of cookie cutters and cookies. The cookie cutter is the class. It
defines the characteristics of each cookie - for instance, size and shape. The class is
used to create objects. The objects are the cookies.
Two examples of the relationship between classes and objects in VBA may make this clearer.
The controls on the Toolbox in VBA represent classes. The object known as a control doesn't
exist until you draw it on a Userform. When you create a control, you're creating a copy or
'instance' of the control class. That instance of the class is the object you refer to in your
application.
G
The Userform you work with at design time is a class. At runtime, VBA creates an instance of
the Userforms class.
G
All objects are created as identical copies of their class. Once they exist as
individual objects, their properties can be changed. For example, if you draw three command
buttons on a Userform, each command button object is an instance of the CommandButton class.
Each object shares a common set of characteristics and capabilities (properties, methods and
events), defined by the class. However, each has it's own name, can be separately enabled and
disabled, can be placed in a different location on the form, and so on.
Working with Objects.
Visual Basic objects support properties, methods, and events. In Visual Basic,
an object's data (settings or attributes) are called 'properties', while the
various procedures that can operate on an object are called it's 'methods'.
An 'event' is an action recognized by an object, such as clicking a mouse or
pressing a key, and you can write code to respond to that event.
You can change an object's characteristics by changing it's properties.
Consider a radio: One property of a radio is its volume. In Visual Basic,
you might say that a radio has a 'Volume' property that you can adjust by
changing its value. Assume you can set the volume of a radio from 0 to 10.
If you could control a radio with Visual Basic, you might write code in a
procedure that changes the value of the 'Volume' property from 3 to 5 to
make it play louder :
Radio.Volume = 5
In addition to properties, objects have methods. Methods are part of objects
just as properties are. Generally, methods are actions you want to perform,
An Introduction to VB and VBA
http://www.afralisp.com/vbaa/vbatut2.htm (2 of 3) [23/03/2005 05:44:03 p.m.]
while properties are the attributes you set or retrieve. For example, you dial
a telephone to make a call. You might say that telephones have a 'Dial' method,
and you could use this syntax to dial a seven digit number 3334444:
Phone.Dial 3334444
Objects also have events. Events are triggered when some aspect of the object is changed. For
example, a radio might have a 'VolumeChange' event. A telephone might have a 'Ring' event.
As it would be an impossibility for me to try and explain to you all the characteristics of VB, I
strongly urge you to invest in a good VB reference book. There are many on the market and it
would make your life a whole lot easier.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
An Introduction to VB and VBA
http://www.afralisp.com/vbaa/vbatut2.htm (3 of 3) [23/03/2005 05:44:03 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page II. Page III. Page IV.
VBA Primer.
I have had numerous requests from people asking for a tutorial on Visual Basic
for Applications. Well here it is. This tutorial will take you from the very basics
of opening the Visual Basic Editor to building a simple application.
I must stress though, that Visual Basic is a language with thousands of built in functions
and numerous custom modules and controls available. I strongly recommend that you
invest in a good Visual Basic book as I cannot possibly take you through the whole VB
language. Also, remember that AutoCAD Visual Basic for Applications is a subset of the
Visual Basic language with it's own build in functions and controls.
Anyway, enough warbling for now, let's get started with our application.
This application called, Change Layer, will allow you to change the layer of
any entity within your drawing. It will display a dialogue box with a list box
listing all of the available layers in your drawing. After you have selected
a layer to change to, it will prompt you to select the entities you would like
to change to that layer and then change them. Sound's good hey! Here we go...
Fire up AutoCAD and choose 'TOOLS-MACRO-VISUAL BASIC EDITOR' from the pull-down
menu.
The Visual Basic Editor should appear and will look like this:
Don't worry about the various windows that appear in the editor. We will go through each one as
we progress through this tutorial.
VBA Primer
http://www.afralisp.com/vbaa/vbatutor.htm (1 of 4) [23/03/2005 05:44:05 p.m.]
Now choose 'INSERT-USERFORM' from the pull down menu bar.
The following should appear :
This is the form that we will use to create our dialogue box from.
Now look in the top left hand corner of the screen. There you will find the Project dialogue. This
basically lists all the Forms, Modules, etc. that are part of your VBA project.
As you can see, because we haven't named our project yet, AutoCAD gives our
project the name Project.dvb. Before we go any further let's save our project
and give it a name. Select 'FILE-SAVE' from the menu bar and name the project
'Chlayer.dvb'. Also you will be able to see the form that we created listed
under Forms and given the default name of UserForm1. All forms, modules and
controls that you insert into your project will be given a default name. (You
can, if you wish change it later but, in this exercise we will only work with
the default names.)
Now, let's have a look at the Properties dialogue box. This you will find in
the lower left-hand corner of the Editor and should look like this:
VBA Primer
http://www.afralisp.com/vbaa/vbatutor.htm (2 of 4) [23/03/2005 05:44:05 p.m.]
This dialogue lists all the properties that an object has. The dialogue should
show all the properties available for the form, UserForm1 that you inserted.
If it doesn't, click on the form to select it.
The first property listed is (Name) - UserForm1. This is the property that
you would change if you wanted to change the name of the form. Please remember, that this is the
name that you use to programatically refer to this particular form. If you change this name once
you have written code referring to this form, you will have to manually change all the instances of
that name in your code.
Let's change the caption of the form. Select the caption property and change it
from 'UserForm1' to 'Change Layer'. Your form should now look like this :
VBA Primer
http://www.afralisp.com/vbaa/vbatutor.htm (3 of 4) [23/03/2005 05:44:05 p.m.]
Notice how the caption has changed. On the next page we will have a look at
adding controls to our form. See you there.........
Home. Page II. Page III. Page IV.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Primer
http://www.afralisp.com/vbaa/vbatutor.htm (4 of 4) [23/03/2005 05:44:05 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Page I. Home. Page III. Page IV.
VBA Primer - Page II.
When you insert the form you might have noticed that another dialogue popped up.
This is the Control Dialogue ToolBox. It look's like this :
To add a control to your form, select the desired control and click on the form
in the position that you would like the control to be. Select the CommandButton control (2nd row,
far right) and place it on your form.
Your form should now look like this :
Now, change the properties of the command button to the following :
(Name) CommandButton1
Caption OK
Default True
Font Arial - Bold - Size 8
Accelerator O
VBA Primer II
http://www.afralisp.com/vbaa/vbatutor2.htm (1 of 3) [23/03/2005 05:44:07 p.m.]
Your button should now look like this :
The Caption property is, of course, the text that appears within the button.
The Default property means that if Enter is selected the event procedure asSigned to this control is
triggered.
The Accelerator property is the letter of the caption that needs to be selected,
along with the Ctrl key, to select this control.
Now add the following controls to your form and changed the properties to the
values listed below :
Command Button
(Name) CommandButton2
Cancel True
Caption Cancel
Accelerator C
Font Arial - Bold - Size 8
The Cancel property means that if Esc is selected the event procedure assigned to this control is
triggered.
Label
(Name) Label1
Caption Choose Layer:
Font Arial - Bold - Size 8
List Box
(Name) Listbox1
Font Arial - Bold - Size 8
BackColor Yellow
You can move a control by simply dragging and dropping it. To re-size it, just
grip the re-size boxes at the edges and corners of the control.
Now move and re-size your controls and the form until the dialogue box looks
similar to this :
VBA Primer II
http://www.afralisp.com/vbaa/vbatutor2.htm (2 of 3) [23/03/2005 05:44:07 p.m.]
Note: Do you see how easy it is to create dialogue boxes in VBA compared
to DCL. "What a pleasure!!!"
Now that we have got our basic dialogue box we need to make it do something.
Page III, look out, here we come...........
Page I. Home. Page III. Page IV.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Primer II
http://www.afralisp.com/vbaa/vbatutor2.htm (3 of 3) [23/03/2005 05:44:07 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Page I. Page II. Home. Page IV.
VBA Primer - Page III.
O.K. we now have our basic dialogue box and would like it to do something.
Firstly, we need to code the cancel button so that we can exit the application
while we are still testing. We also need to create a Module so that we can run
the application from within AutoCAD.
Let's create the Module first.
Select INSERT - MODULE.
A new window will open looking like this:
This is the code window were you will be writing all of your Visual Basic Code.
If you look at the Project window you will find that a new Module has been created and has been
given the default name of Module1.
Now enter the following code into the module :
sub chlayer ()
'name of function
UserForm1.Show
'display the dialogue box
'UserForm1
End Sub
Thw code window should look like this :
VBA Tutor III
http://www.afralisp.com/vbaa/vbatutor3.htm (1 of 3) [23/03/2005 05:44:09 p.m.]
As you have probably worked out for yourself, any line starting with a ' is a comment. (The same as
the ; in AutoLISP).
Visual Basic also colour codes the coding but I am not going to get into that
at this time.
Next, double click on the Cancel button on UserForm1. The code window will open again,
displaying the Click Event procedure for that control.
Type in the following code :
Private Sub CommandButton2_Click()
End
'end the programme

End Sub
The code window should look like this :
This sub-routine simply ends the programme if the Cancel button is selected.
Now, let's test our dialogue box.
(This would be a good time to save your project......)
Return to AutoCAD and select TOOLS - MACROS - RUN MACRO from the menu bar.
The following dialogue should appear:
VBA Tutor III
http://www.afralisp.com/vbaa/vbatutor3.htm (2 of 3) [23/03/2005 05:44:09 p.m.]
Choose 'Module1' from the list box and 'chlayer' from the drop down list box.
Now select 'Run'. Your dialogue should appear in all it's glory.
(Thunderous applause from the audience.)
Once you have finished admiring your handywork select 'Cancel'.
We still have a couple of problems though. Firstly, there is nothing in the
list box and the OK button doesn't work.
On the next page we'll show you how to populate the list box with all the
layer names in your drawing and then we'll write the main event procedure for
the O.K. button.
While you are waiting for the next page you might as well grab yourself a beer.
I've got one.......
Page I. Page II. Home. Page IV.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Tutor III
http://www.afralisp.com/vbaa/vbatutor3.htm (3 of 3) [23/03/2005 05:44:09 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Page I. Page II. Page III. Home.
VBA Primer - Page IV.
To populate our list box we need to first find a list of all the layers in our drawing. Double
click on the form. (The form, not a control.)
The code window will open. From the Event Procedure drop-down list box in the right
hand corner of the code window choose 'Initiliaze'.
Now add the following code to this event procedure:
Private Sub UserForm_Initialize()
Dim AllLayers As Object
Dim Layer As Object
'declare local variables
Set AllLayers = ThisDrawing.Layers
'get the layers from the layers collection
For Each Layer In AllLayers
'for every layer listed
ListBox1.AddItem Layer.Name
'add the layer name to the list box

Next
'carry on looping

End Sub
A list of all the layers in any drawing are kept in the Layers collection.
This coding is telling Visual Basic that when the form is initialized, get all of the layer names from
the layers collection, and add them to the list box.
Run the program again. Your dialogue should now look like this :
Now let's look at the coding for the OK button event procedure.
VBA Tutor IV
http://www.afralisp.com/vbaa/vbatutor4.htm (1 of 3) [23/03/2005 05:44:10 p.m.]
Double click the OK button and enter the following code under the click event procedure of the
button :
Private Sub CommandButton1_Click()
Dim Entity As Object
'declare variable as local
Me.Hide
'hide the dialogue box
Set ss = ThisDrawing.SelectionSets.Add("NEWSS")
'create a selection set reference
ss.SelectOnScreen
'select the objects to change
For Each Entity In ss
'for every entity in the selection set
Entity.Layer = ListBox1.Text
'change the layer to the layer name
'selected in the list box

Next
'process the next entity
End
'end the programme
End Sub
Now run the programme again. Select a layer from the list box and then select
some objects on your drawing. They should change to your selected layer.
Well I hope this has given you a bit more of an idea what VBA is all about.
The application is far from perfect. There is no error checking and the items
in the list box have not been sorted. Maybe that is something that you could
work on now that you have had a taste of VBA. Have a look at the other sample
applications in this section. They cover large areas of VBA and all come complete with source
coding. All the best and good luck with VBA......
If you would like to download this VBA Primer, stand on your head, say 'Yes Please' in
French, place your mouse here and Click. Enjoy.......
Page I. Page II. Page III. Home.

VBA Tutor IV
http://www.afralisp.com/vbaa/vbatutor4.htm (2 of 3) [23/03/2005 05:44:10 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Tutor IV
http://www.afralisp.com/vbaa/vbatutor4.htm (3 of 3) [23/03/2005 05:44:10 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Userforms.
If you have programmed with AutoLisp and the Dialogue Control Language (DCL), you will
be familiar with designing dialogue boxes. Compared to DCL though, designing dialogue
boxes in VBA is a breeze. The basis of all dialogue boxes in VBA is the Userform. This
Tutorial will show you how to display and manipulate Userforms.
A Userform is a container that holds all the controls such as labels, textboxes,
pictures, etc. that make up part of your applications interface.
A Userform has it's own Properties, Methods and Events. Let's have a look at some of them :
Displaying a Userform
The syntax for displaying a Userform is as follows :
UserFormName.Show
So, to display a Userform named Userform1, you would use the following code:
Userform1.Show
If you want to, you can preload the Userform into memory without actually displaying it. This can be
useful as it can sometimes take a few seconds for a complex Userform to appear. The ability to
preload the Userform allows you to decide when you would like this operation to take place. To
preload a Userform you would use the following code :
Load Userform1
Hiding/Unloading a Userform
To temporarily hide a Userform, you would use the Hide method. This is a very good example of how
dialogue boxes in VBA are so much simpler than in AutoLisp. To hide a Userform you would use the
following code:
Userform1.Hide
To Unload a Userform from memory use the following code :
Unload Userform1
You could also use the 'Me' keyword :
Unload Me
Useform Events
Userforms support many predefined events. Among the most commonly used events are Initiliaze,
Click and Terminate events.
Note A VBA module that contains an event procedure can be called a module
'behind' the Userform. A module that contains event procedures is not visible in the Modules
collection of the Projects window of the VBA Editor. You must double-click the body of the Userform
to view the Userform Code Module.
Let's have a look at some Userform Events. Start your VBA Editor and insert a
Userform into a new Project. Double-Click the Userform and type in the following code:
Private Sub UserForm_Click()
Me.Height = Int(Rnd * 500)
Me.Width = Int(Rnd * 750)

UserForms
http://www.afralisp.com/vbaa/vbatut1.htm (1 of 3) [23/03/2005 05:44:12 p.m.]
End Sub
Private Sub UserForm_Initialize()
Me.Caption = "Userform Events"
Me.BackColor = RGB(10, 25, 100)

End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
msg = "Now Unloading " & Me.Caption
MsgBox prompt:=msg, Title:="QueryClose Event"

End Sub
Private Sub UserForm_Resize()
msg = "Width: " & Me.Width & Chr(10) & "Height : " & Me.Height
MsgBox prompt:=msg, Title:="Resizing Event"

End Sub
Private Sub UserForm_Terminate()
msg = "Now Unloading " & Me.Caption
MsgBox prompt:=msg, Title:="Terminate Event"

End Sub
Now run the Userform.
This is what happens when you run the project:
Firstly, The Intialize event procedure changes the Caption property to "Userform Events" and the
Backcolor property to dark Blue.
When you click the Userform the Click Event procedure is initiated and the Userform is re-sized.
Also, because you created a resize event procedure, you receive 2 message boxes. The resize event
occurs twice because your code behind the click event changed both the Width and Height properties
of the Userform.
When you close the Userform, the QueryClose event procedure is triggered. This displays a message
box with the caption you gave the Userform in the code for the Initialize event. The QueryClose event
is useful when you want to perform a certain set of actions when the Userform is closed by the user.
The Terminate Event then triggers a message box which states that the Caption of the Userform is
Userform1. The Terminate Event occurs after the Userform is removed from memory and the
Caption of the Userform returns to it's original state.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
UserForms
http://www.afralisp.com/vbaa/vbatut1.htm (2 of 3) [23/03/2005 05:44:12 p.m.]
Search
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
UserForms
http://www.afralisp.com/vbaa/vbatut1.htm (3 of 3) [23/03/2005 05:44:12 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Lisp to VBA.
To demonstrate the use of VBA in AutoCAD, I've taken a few of the more common
AutoLisp routines, and converted them to VBA Applications.
This will hopefully help the AutoLisper who is trying to migrate from AutoLisp To VBA.
These routines should be familiar to most AutoLispers and by having a good
understanding of how the routine is written in AutoLisp, you should find it very easy to
follow and undestand the VBA logic and coding.
Note:
I have presumed that you know how to load and run a VBA Application, work with User Forms
and controls, and know how to set the basic Properties of UserForms and Controls. The only
Properties that I have listed are those that are out of the norm.
I have NOT included any error checking for the sake of readability.
Lisp to VBA Applications.
Slotted Holes. - Draws Slotted Holes. G
Moffset. - Multiple Offset. G
Import/Export Data. - Import and Export Layer Names. G
Filter Layers. - Filtering User Defined Layers. G
Edit Text. - Edit Line Text. G
Change Text. - Change Text Height, Layer, Style or Colour. G

Lisp to VBA.
http://www.afralisp.com/vbaa/vbatut3.htm (1 of 2) [23/03/2005 05:44:12 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Lisp to VBA.
http://www.afralisp.com/vbaa/vbatut3.htm (2 of 2) [23/03/2005 05:44:12 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Slotted Holes.
This application will draw slotted holes as per the above diagram.
It begins by asking the user for an insertion point, the slot length, and then the slot diameter using
the VBA Get functions.
It then uses the PolarPoint function to calculate the other points required to draw the slot. Then,
using the AddLine and AddArc command, it draws the
slotted hole.
Note how we declare 'pi' as a Constant and construct a function to convert Degrees to Radians.
Open a new module and add this coding to it :
Const pi = 3.14159
'create Pi as a constant
'This function converts Degrees to Radians Function dtr(a As Double) As Double dtr = (a / 180) * pi
End Function
Sub Slot() 'define the function Dim InsertPoint As Variant Dim SlotLength As Double Dim SlotDia
As Double Dim Prompt1 As String Dim Prompt2 As String Dim Prompt3 As String Dim pt1 As
Variant Dim pt2 As Variant Dim pt3 As Variant Dim pt4 As Variant Dim pt5 As Variant Dim pt6
As Variant Dim pt7 As Variant Dim LineObj As AcadLine Dim ArcObj As AcadArc 'declare all
variables Prompt1 = vbCrLf & "Insertion Point : " 'store the prompt InsertPoint =
ThisDrawing.Utility.GetPoint(, Prompt1) 'get the insertion point Prompt2 = vbCrLf & "Slot
Length : " 'store the prompt SlotLength = ThisDrawing.Utility.GetReal(Prompt2) 'get the slot
length Prompt3 = vbCrLf & "Slot Diameter : " 'store the prompt SlotDia =
ThisDrawing.Utility.GetReal(Prompt3) 'get the slot diameter pt1 = ThisDrawing.Utility. _
PolarPoint(InsertPoint, dtr(270#), SlotDia / 2) pt2 = ThisDrawing.Utility. _ PolarPoint(pt1,
dtr(180#), SlotLength / 2) pt3 = ThisDrawing.Utility. _ PolarPoint(pt2, dtr(90#), SlotDia) pt4 =
ThisDrawing.Utility. _ PolarPoint(pt3, dtr(0#), SlotLength) pt5 = ThisDrawing.Utility. _
PolarPoint(pt4, dtr(270#), SlotDia) pt6 = ThisDrawing.Utility. _ PolarPoint(InsertPoint, dtr(180#),
SlotLength / 2) pt7 = ThisDrawing.Utility. _ PolarPoint(InsertPoint, dtr(0#), SlotLength / 2)
'calculate all the points using the PolarPoint Function Set LineObj = ThisDrawing.ModelSpace. _
AddLine(pt1, pt2) Set LineObj = ThisDrawing.ModelSpace. _ AddLine(pt3, pt4) Set LineObj =
ThisDrawing.ModelSpace. _ AddLine(pt5, pt1) Set ArcObj = ThisDrawing.ModelSpace. _
AddArc(pt6, SlotDia / 2, dtr(90), dtr(270)) Set ArcObj = ThisDrawing.ModelSpace. _ AddArc(pt7,
SlotDia / 2, dtr(270), dtr(90)) 'Draw the Slotted Hole End Sub

Now, let's add a dialogue box to our application to streamline the user input :
Slotted Holes
http://www.afralisp.com/vbaa/vbatut31.htm (1 of 4) [23/03/2005 05:44:14 p.m.]
ScrollBar Properties :

Max = 100 G
Min = 1 G
Value = 50 G
SmallChange = 1 G
LargeChange = 5 G
TextBox1 :

Value = 50 G
TextBox1 :

Value = 20 G

Open a new module and add this coding to it :


Const pi = 3.14159
'create Pi as a constant
'This function converts Degrees to Radians Function dtr(a As Double) As Double dtr = (a / 180) * pi
End Function
Sub Slot1() 'define the function UserForm1.Show 'display the dialogue box End Sub

Now, under the Click Event for CommandButton1, add this coding :
Private Sub CommandButton1_Click()
Dim InsertPoint As Variant
Dim SlotLength As Double
Dim SlotDia As Double
Dim Prompt1 As String
Dim pt1 As Variant
Dim pt2 As Variant
Dim pt3 As Variant
Dim pt4 As Variant
Dim pt5 As Variant
Dim pt6 As Variant
Dim pt7 As Variant
Dim LineObj As AcadLine
Dim ArcObj As AcadArc
'declare all variables
Slotted Holes
http://www.afralisp.com/vbaa/vbatut31.htm (2 of 4) [23/03/2005 05:44:14 p.m.]

SlotLength = TextBox1.Value
'retrieve the Slot Length

SlotDia = TextBox2.Value
'retrieve the Slot Diameter

UserForm1.Hide
'hide the dialogue box

Prompt1 = vbCrLf & "Insertion Point : "
'store the prompt

InsertPoint = ThisDrawing.Utility.GetPoint(, Prompt1)
'get the insertion point

pt1 = ThisDrawing.Utility. _
PolarPoint(InsertPoint, dtr(270#), SlotDia / 2)
pt2 = ThisDrawing.Utility. _
PolarPoint(pt1, dtr(180#), SlotLength / 2)
pt3 = ThisDrawing.Utility. _
PolarPoint(pt2, dtr(90#), SlotDia)
pt4 = ThisDrawing.Utility. _
PolarPoint(pt3, dtr(0#), SlotLength)
pt5 = ThisDrawing.Utility. _
PolarPoint(pt4, dtr(270#), SlotDia)
pt6 = ThisDrawing.Utility. _
PolarPoint(InsertPoint, dtr(180#), SlotLength / 2)
pt7 = ThisDrawing.Utility. _
PolarPoint(InsertPoint, dtr(0#), SlotLength / 2)
'calculate all the points using the PolarPoint Function

Set LineObj = ThisDrawing.ModelSpace. _
AddLine(pt1, pt2)
Set LineObj = ThisDrawing.ModelSpace. _
AddLine(pt3, pt4)
Set LineObj = ThisDrawing.ModelSpace. _
AddLine(pt5, pt1)
Set ArcObj = ThisDrawing.ModelSpace. _
AddArc(pt6, SlotDia / 2, dtr(90), dtr(270))
Set ArcObj = ThisDrawing.ModelSpace. _
AddArc(pt7, SlotDia / 2, dtr(270), dtr(90))
'Draw the Slotted Hole
End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub ScrollBar1_Change()
TextBox1.Value = ScrollBar1.Value
'set the value of the text box
'to the value of the scrollbar

End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Slotted Holes
http://www.afralisp.com/vbaa/vbatut31.htm (3 of 4) [23/03/2005 05:44:14 p.m.]
ScrollBar1.Value = TextBox1.Value
'set the value of the scrollbar
'to the value of the text box

End Sub
If you would like to download the source code for this Application/s, Then click Here

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Slotted Holes
http://www.afralisp.com/vbaa/vbatut31.htm (4 of 4) [23/03/2005 05:44:14 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Muliple Offset.
This application will offset an entity multiple times. Just select the entity, enter an offset
distance, (enter a negative number if you want to offset the other way), and then enter the
number of times you would like to offset it.
Enter this coding into a new module :
Option Explicit
Public Sub Moffset()
Dim objPicked As Object
Dim BasePnt As AcadPoint
Dim returnDist As Double
Dim nuOffsets As Integer
Dim i As Integer
Dim accumDist As Double
Dim offsetObj As Variant
'declare variables
ThisDrawing.Utility.GetEntity objPicked, BasePnt, "Select A Line"
'select the object
returnDist = ThisDrawing.Utility.GetDistance(, "Enter distance: ")
'get the distance to offset
nuOffsets = ThisDrawing.Utility.GetInteger("Number of Offsets : ")
'get the number of offsets
offsetObj = objPicked.Offset(returnDist)
'offset the object
For i = 1 To nuOffsets
'set up the loop
accumDist = returnDist + accumDist
'calculate the new offset distance
offsetObj = objPicked.Offset(accumDist)
'multiple offset the object
Next i
'loop
End Sub
Now run the macro 'Moffset'. Works fine Hey!. Now run it again but this time select an empty
space on the screen when prompted to select an object.
Oh, Crikey, an error??? Re-run it once more but this time select an object.
Now press the Escape key. Oh No, another error!!!
Multiple Offset
http://www.afralisp.com/vbaa/vbatut32.htm (1 of 2) [23/03/2005 05:44:15 p.m.]
I think this application is screaming out for some error control.
Start a new application and enter this coding. I've colour coded the coding that
has been added :
Option Explicit
Public Const VK_ESCAPE = &H1B
Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
Function checkkey(lngKey As Long) As Boolean If GetAsyncKeyState(lngKey) Then checkkey =
True Else checkkey = False End If End Function
Public Sub Moffset1() Dim objPicked As Object Dim BasePnt As AcadPoint Dim returnDist As
Double Dim nuOffsets As Integer Dim i As Integer Dim accumDist As Double Dim offsetObj As
Variant 'declare variables Start: On Error GoTo errControl 'if there is an error
ThisDrawing.Utility.GetEntity objPicked, BasePnt, "Select A Line" 'select the object returnDist =
ThisDrawing.Utility.GetDistance(, "Enter distance: ") 'get the distance to offset nuOffsets =
ThisDrawing.Utility.GetInteger("Number of Offsets : ") 'get the number of offsets offsetObj =
objPicked.Offset(returnDist) 'offset the object For i = 1 To nuOffsets 'set up the loop accumDist =
returnDist + accumDist 'calculate the new offset distance offsetObj = objPicked.Offset(accumDist)
'multiple offset the object Next i 'loop Exit Sub 'exit the sub routine errControl: 'define the error
control If Err.Description = "Method 'GetEntity' of object _ 'IAcadUtility' failed" Then 'if the
error matches these.. If checkkey(VK_ESCAPE) = True Then 'if the escape key is selected End 'end
Else 'or else Resume 'repeat "Select Object" End If Else MsgBox Err.Description 'it must be
another type of error End If End Sub

Now load and run Macro 'Moffset1'. Much better, Hey?


Thanks to Randall Raath for the error checking in this application.
If you would like to download the source code for this Application/s, Then click Here

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Multiple Offset
http://www.afralisp.com/vbaa/vbatut32.htm (2 of 2) [23/03/2005 05:44:15 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Import/Export File Data.
This application will show you how to Import and Export Data to and from external text
files. The dialogue box contains two list boxes.
The first contains a list of all the layers contained in the current drawing.
By selecting the Export Layers button, the layer names will be written to file ExLayers.txt.
Selecting the Layers Import button will bring in a list of layers contained
in the file InLayers.txt.
Note : Please ensure that all the files are in the same directory and within
your AutoCAD support path. Thanks :-))
You will need to create a new form with 2 list boxes and 3 buttons.
Keep the default names. Now create a new form and add this coding :
Option Explicit
Private Sub CommandButton1_Click()
Dim objLayer As AcadLayer
Dim Lname As String
'declare variables
Open "Exlayer.txt" For Output As #1
'open text file
For Each objLayer In ThisDrawing.Layers
'start looping thru' the layer names
Lname = objLayer.Name
'get the layer name
Print #1, Lname
'print it to the file
Import Export/File Data
http://www.afralisp.com/vbaa/vbatut33.htm (1 of 3) [23/03/2005 05:44:17 p.m.]
Next
Close #1
'close the file
Unload Me
'unload dialogue
End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub CommandButton3_Click()
Dim sTemp As String
'declare variable
ListBox2.Clear
'clear the listbox
Open "Inlayer.txt" For Input As #1
'open the external file
While Not EOF(1)
'until the end of file is reached
Line Input #1, sTemp
'get a layer name
ListBox2.AddItem sTemp
'add it to the list box

Wend
Close #1
'close the file
End Sub
Private Sub UserForm_Initialize()
Dim objLayer As AcadLayer
'declare variables
For Each objLayer In ThisDrawing.Layers
'get the layer names and loop thru' them
ListBox1.AddItem objLayer.Name
'add them to the list box
Next
End Sub
Import Export/File Data
http://www.afralisp.com/vbaa/vbatut33.htm (2 of 3) [23/03/2005 05:44:17 p.m.]

Now create a new module and add this coding :

Sub EILayer()
UserForm1.Show
End Sub

Now run the macro "EILayer.....Good Hey!!!


If you would like to download the source code for this Application/s, then click Here

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Import Export/File Data
http://www.afralisp.com/vbaa/vbatut33.htm (3 of 3) [23/03/2005 05:44:17 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Filtering Layers.
Ever wondered how to filter your drawing for specific layers?
Well here's how. This application will filter your drawing for a specific layer using the
criteria that you will provide from within a sub-routine.
First of all the Function. Open a new module and add this coding :
Option Explicit
Public Function LayerSelection(strLayerName As String, strSSName) _
As AcadSelectionSet
Dim ssObjects As AcadSelectionSet
Dim intCode(0) As Integer
Dim varData(0) As Variant
Dim objCheck As AcadSelectionSet
'declare variables
intCode(0) = 8
'set variable for the dxf code for layer
varData(0) = strLayerName
'set variable for the layer name
Set ssObjects = ThisDrawing.SelectionSets.Add(strSSName)
'create a selection eset
ssObjects.Select acSelectionSetAll, , , intCode, varData
'select all entities on the specified layer
Set LayerSelection = ssObjects
'create a reference to the selection
End Function
Now add the sub-routine to run the function to the same module :
Public Sub FilterLayer()
Dim ssLayrObj As AcadSelectionSet
'declare variables
Set ssLayrObj = LayerSelection("0", "vbdset")
'get the entities on the layer "0"
Dim obj As Object
For Each obj In ssLayrObj
'for each of the entities
obj.Highlight True
'highlight them
Next
Filtering Layers
http://www.afralisp.com/vbaa/vbatut34.htm (1 of 2) [23/03/2005 05:44:19 p.m.]
ThisDrawing.SelectionSets.Item("vbdset").Delete
'delete the selection set
End Sub
Run the macro "FilterLayer". All the entities on Layer 0 should be highlighted.
Now you've got them, you can do anything you like with them.
But that, I will leave to your imagination.......
I would just like to thank Randall Raath for allowing me to 'steal' this.
(Saved me a lot of typing!!!!).
If you would like to download the source code for this Application/s, then click Here

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Filtering Layers
http://www.afralisp.com/vbaa/vbatut34.htm (2 of 2) [23/03/2005 05:44:19 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Edit Line Text.
Here's a good one for you. This will allow you to select any line of text, and then edit it
using a dialogue box.
Note : This will only work with Line Text. Sorry :-(
First of all you need a Module with this coding in it :
Option Explicit
Public objPicked As AcadObject
Public Const VK_ESCAPE = &H1B
Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer
Function checkkey(lngKey As Long) As Boolean If GetAsyncKeyState(lngKey) Then checkkey =
True Else checkkey = False End If End Function
Public Sub textedit() Dim BasePnt As AcadPoint 'declare variables Start: On Error GoTo
errControl 'if there is an error ThisDrawing.Utility.GetEntity objPicked, BasePnt, _ "Select Line
Text" 'select the object UserForm1.TextBox1.Text = objPicked.TextString 'get the existing
textstring and put it in 'the text box UserForm1.Show 'display the dialogue Exit Sub 'exit the sub
routine errControl: 'define the error control If Err.Description = "Method 'GetEntity' of object _
'IAcadUtility' failed" Then 'if the error matches these.. If checkkey(VK_ESCAPE) = True Then 'if
the escape key is selected End 'end Else 'or else Resume 'repeat "Select Object" End If Else
MsgBox Err.Description 'it must be another type of error End If End Sub

Now insert a userform with a text box and two buttons. Keep the default
names and add this coding to the form :

Private Sub CommandButton1_Click()


If TextBox1.Text = "" Then
'if all text is deleted
TextBox1.Text = " "
'put in a space

End If
objPicked.TextString = TextBox1.Text
Edit Line Text
http://www.afralisp.com/vbaa/vbatut35.htm (1 of 2) [23/03/2005 05:44:21 p.m.]
'get the text string from the text box
objPicked.Update
'update the text
End
End Sub
Private Sub CommandButton2_Click() End End Sub
Private Sub UserForm_Activate() UserForm1.TextBox1.SetFocus 'set focus to the textbox
UserForm1.TextBox1.SelStart = 0 'start at the first character UserForm1.TextBox1.SelLength =
Len(UserForm1.TextBox1.Text) 'highlight the text string End Sub

Now run the macro "TextEdit" and select some line text when prompted.
Change the text and select O.K. Crikey, I'm good hey!!!!
If you would like to download the source code for this Application/s, then click Here

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Edit Line Text
http://www.afralisp.com/vbaa/vbatut35.htm (2 of 2) [23/03/2005 05:44:21 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Change Text.
This application will change the Height, Layer, Style or Colour of selected text within a
drawing. You can use the 'Select Objects' button to select any objects on screen by
using any of the standard AutoCAD selection methods, or you can choose 'Select All' to
select all text entities. The application will automatically filter out all non-text entities.
Create a form with controls as above and add this coding :
Option Explicit
Private Sub CheckBox1_Click()
If TextBox1.Enabled = False Then

TextBox1.Enabled = True

UserForm1.TextBox1.SetFocus
'set focus to the textbox
UserForm1.TextBox1.SelStart = 0
'start at the first character
UserForm1.TextBox1.SelLength = Len(UserForm1.TextBox1.Text)

Else
TextBox1.Enabled = False

End If
End Sub
Change Text
http://www.afralisp.com/vbaa/vbatut36.htm (1 of 6) [23/03/2005 05:44:23 p.m.]
Private Sub CheckBox2_Click()
If ComboBox1.Enabled = False Then

ComboBox1.Enabled = True

Else
ComboBox1.Enabled = False

End If
End Sub
Private Sub CheckBox3_Click()
If ComboBox2.Enabled = False Then

ComboBox2.Enabled = True

Else
ComboBox2.Enabled = False

End If
End Sub
Private Sub CheckBox4_Click()
If ComboBox3.Enabled = False Then

ComboBox3.Enabled = True

Else
ComboBox3.Enabled = False

End If
End Sub
Private Sub CommandButton1_Click()
Dim pt1(0) As Double
Dim pt2(0) As Double
Dim FilterSet As Object
Dim gpCode(0) As Integer
Dim gpValue(0) As Variant
'declare variables
UserForm1.Hide
'hide the dialogue
Set FilterSet = ThisDrawing.SelectionSets.Add("TEMP")
Change Text
http://www.afralisp.com/vbaa/vbatut36.htm (2 of 6) [23/03/2005 05:44:23 p.m.]
'create a selection set
gpCode(0) = 0
'set the filter DXF code
gpValue(0) = "TEXT"
'set the filter DXF value
FilterSet.Select acSelectionSetAll, pt1, pt2, gpCode, gpValue
'select all text in the drawing
Dim FilterEnt As Object
For Each FilterEnt In FilterSet
'start the loop
If CheckBox1.Value = True Then
FilterEnt.Height = TextBox1.Text
End If
'retrieve the height
If CheckBox2.Value = True Then
FilterEnt.Layer = ComboBox1.Text
FilterEnt.Color = acByLayer
End If
'retrieve the layer
If CheckBox3.Value = True Then
FilterEnt.StyleName = ComboBox2.Text
End If
'retrieve the style
If CheckBox4.Value = True Then
FilterEnt.Color = ComboBox3.Text
End If
'retrieve the color
FilterEnt.Update
'update the entity
Next FilterEnt
ThisDrawing.SelectionSets("TEMP").Delete
'delete the selection set
End
End Sub
Change Text
http://www.afralisp.com/vbaa/vbatut36.htm (3 of 6) [23/03/2005 05:44:23 p.m.]
Private Sub CommandButton2_Click()
End
End Sub
Private Sub CommandButton3_Click()
Dim pt1 As Variant
Dim pt2 As Variant
Dim FilterSet As Object
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
'declare variables
Set FilterSet = ThisDrawing.SelectionSets.Add("TEMP")
'create a selection set
FilterType(0) = 0
'set the filter DXF code
FilterData(0) = "TEXT"
'set the filter DXF type
UserForm1.Hide
'hide the dialogue
FilterSet.SelectOnScreen FilterType, FilterData
'select text on screen
Dim FilterEnt As Object
For Each FilterEnt In FilterSet
'start the loop
If CheckBox1.Value = True Then
FilterEnt.Height = TextBox1.Text
End If
'retrieve the height
If CheckBox2.Value = True Then
FilterEnt.Layer = ComboBox1.Text
FilterEnt.Color = acByLayer
End If
'retrieve the layer
If CheckBox3.Value = True Then
FilterEnt.StyleName = ComboBox2.Text
End If
'retrieve the style
If CheckBox4.Value = True Then
FilterEnt.Color = ComboBox3.Text
End If
'retrieve the colour
FilterEnt.Update
Change Text
http://www.afralisp.com/vbaa/vbatut36.htm (4 of 6) [23/03/2005 05:44:23 p.m.]
'update the entity
Next FilterEnt
ThisDrawing.SelectionSets("TEMP").Delete
'delete the selection set
End
End Sub
Private Sub UserForm_Initialize()
Dim objLayer As AcadLayer
Dim i As Integer
'declare variables
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
'switch off all checkboxes
TextBox1.Text = ThisDrawing.GetVariable("TextSize")
'retrieve the current text height
ComboBox1.Text = ThisDrawing.GetVariable("CLayer")
'retrieve the current text style
ComboBox2.Text = ThisDrawing.GetVariable("TextStyle")
'retrieve the current text style
For Each objLayer In ThisDrawing.Layers
'get the layer names and loop thru' them
ComboBox1.AddItem objLayer.Name
'add them to the list box
Next
Dim objStyle As AcadTextStyle
'declare variables
For Each objStyle In ThisDrawing.TextStyles
'get the layer names and loop thru' them
ComboBox2.AddItem objStyle.Name
'add them to the list box
Next
For i = 1 To 255
'start the loop
ComboBox3.AddItem i
Change Text
http://www.afralisp.com/vbaa/vbatut36.htm (5 of 6) [23/03/2005 05:44:23 p.m.]
'add colour number to combo box
Next i
End Sub
Now open a new module and add this coding :

Sub Chtext1()
UserForm1.Show
End Sub
To run this application run the macro "Chtext1".
There is one thing wrong with this application. The list of Layers and Styles are not sorted. I didn't
include the coding for this as it would have complicated the issue. Therefore, I have included
another version of this application within the zip file that includes the sort coding. (Many thanks to
Randall Raath.)
If you would like to download the source code for this Application/s, then click Here

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Change Text
http://www.afralisp.com/vbaa/vbatut36.htm (6 of 6) [23/03/2005 05:44:23 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoCAD and Customizable Support Files
Table of Customizable Support Files G
Order of support file loading when starting AutoCAD G
Automatically Load and Execute AutoLISP Routines G
Automatically Load ObjectARX Applications G
acad.lspAutomatically Load AutoLISP G
acaddoc.lspAutomatically Load AutoLISP G
Menu File Types G
Load Menu Files G
acad.mnlAutomatically Load AutoLISP Menu Functions G
S::STARTUP FunctionPost-Initialization Execution G
Tips for Coding AutoLISP Startup Files G
Command Autoloader G
acadvba.arxAutomatically Load VBA G
acad.dvbAutomatically Load a VBA Project G
Automatically Loading a VBA Project G
Automatically Running a VBA Macro G
Table of Customizable Support Files
AutoCAD uses support files for purposes such as storing menu definitions, loading AutoLISP and
ObjectARX applications, and describing text fonts. Many support files are text files that you can modify
with a text editor.
The following is a list of AutoCAD support files that can be edited. The support files are listed in
alphabetical order by file extension. Please make backup copies of these files before modifying them.
Customizable support files
File Description
asi.ini Database connectivity link conversion mapping file.
*.dcl AutoCAD Dialog Control Language (DCL) descriptions of dialog boxes.
*.lin AutoCAD linetype definition files.
acad.lin The standard AutoCAD linetype library file.
acadiso.lin The standard AutoCAD ISO linetype library file.
*.lsp AutoLISP program files.
acad.lsp A user-defined AutoLISP routine that loads each time you start AutoCAD.
acaddoc.lsp A user-defined AutoLISP routine that loads each time you start a drawing.
*.mln A multiline library file.
*.mnl
AutoLISP routines used by AutoCAD menus. A MNL file must have the same file
name as the MNU file it supports.
acad.mnl AutoLISP routines used by the standard AutoCAD menu.
*.mns
AutoCAD generated menu source files. Contains the command strings and macro
syntax that define AutoCAD menus.
acad.mns Source file for the standard AutoCAD menu.
*.mnu
AutoCAD menu source files. Contain the command strings and macro syntax that
define AutoCAD menus.
acad.mnu Source file for the standard AutoCAD menu.
*.pat AutoCAD hatch pattern definition files.
acad.pat The standard AutoCAD hatch pattern library file.
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (1 of 8) [23/03/2005 05:44:28 p.m.]
acadiso.pat The standard AutoCAD ISO hatch pattern library file.
acad.pgp
The AutoCAD program parameters file. Contains definitions for external commands
and command aliases.
acad.psf
AutoCAD PostScript Support file; the master support file for the PSOUT and PSFILL
commands.
acad.rx Lists ObjectARX applications that load when you start AutoCAD.
*.scr
AutoCAD script files. A script file contains a set of AutoCAD commands processed
as a batch.
*.shp
AutoCAD shape/font definition files. Compiled shape/font files have the extension
.shx.
acad.unt
AutoCAD unit definition file. Contains data that lets you convert from one set of
units to another.

Order of support file loading when starting AutoCAD


You can understand the effects that one file may have on another if you know the order in which files
are loaded when you start the software. For example, you have defined a function in an AutoLISP
routine that is loaded from the acad.lsp file, but the function does not work when you start AutoCAD.
This occurs because the function has been redefined by the acaddoc.lsp file, which is loaded after
acad.lsp.
Following is a list of AutoCAD, Express Tools, and user-defined files in the order they are loaded when
you first start the program.
File For use by:
acad2000.lsp AutoCAD
acad.rx User
acad.lsp User
acad2000doc.lsp AutoCAD
acetutil.fas Express Tools
acaddoc.lsp User
mymenu.mnc User
mymenu.mnl User
acad.mnc AutoCAD
acad.mnl AutoCAD
acetmain.mnc Express Tools
acetmain.mnl Express Tools
s::startup User
Note: If the user-defined function S::STARTUP is included in the acad.lsp or acaddoc.lsp file or a MNL
file, the function is called when you enter a new drawing or open an existing drawing. Thus, you can
include a definition of S::STARTUP in the LISP startup file to perform any setup operations.

Automatically Load and Execute AutoLISP Routines


As you build a library of useful AutoLISP routines, you may want to load them each time you run
AutoCAD. You may also want to execute certain commands or functions at specific times during a
drawing session.
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (2 of 8) [23/03/2005 05:44:28 p.m.]
AutoCAD loads the contents of four user-definable files automatically: acad.rx, acad.lsp, acaddoc.lsp,
and the .mnl file that accompanies your current menu. By default, the acad.lsp loads only once, when
AutoCAD starts, while acaddoc.lsp loads with each individual document (or drawing). This lets you
associate the loading of the acad.lsp file with application startup, and the acaddoc.lsp file with document
(or drawing) startup. The default method for loading these startup files can be modified by changing the
setting of the ACADLSPASDOC system variable.
If one of these files defines a function of the special type S::STARTUP, this routine runs immediately
after the drawing is fully initialized. The S::STARTUP function is described in S::STARTUP
FunctionPost-Initialization Execution. As an alternative, the APPLOAD command provides a Startup
Suite option that loads the specified applications without the need to edit any files.
The acad.lsp and acaddoc.lsp startup files are not provided with AutoCAD. It is up to the user to create
and maintain these files.
Automatically Load ObjectARX Applications
The acad.rx file contains a list of the ObjectARX program files that are loaded automatically when you
start AutoCAD. You can edit this file with a text editor or word processor that produces files in ASCII text
format. You can customize this file as you want, adding to or deleting from its contents and making the
appropriate ObjectARX programs available for use. As an alternative, the APPLOAD command provides
a Startup Suite option that loads the specified applications without the need to edit any files.
Because AutoCAD searches for the acad.rx file in the order specified by the library path, you can have a
different acad.rx file in each drawing directory. This makes specific ObjectARX programs available for
certain types of drawings. For example, you might keep 3D drawings in a directory called
AcadJ obs/3d_dwgs. If that directory is set up as the current directory, you could copy the acad.rx file
into that directory and modify it in the following manner:
myapp1
otherapp
If you place this new acad.rx file in the AcadJ obs/3d_dwgs directory and you start AutoCAD with that as
the current directory, these new ObjectARX programs are then loaded and are available from the
AutoCAD prompt line. Because the original acad.rx file is still in the directory with the AutoCAD program
files, the default acad.rx file will be loaded if you start AutoCAD from another directory that does not
contain an acad.rx file.
You can load ObjectARX programs from an .mnl file using the arxload function. This ensures that an
ObjectARX program, required for proper operation of a menu, will be loaded when the menu file is
loaded.
You can also autoload many ObjectARX-defined AutoCAD commands (see Command Autoloader and
"autoarxload" in the AutoLISP Reference).
acad.lspAutomatically Load AutoLISP
The acad.lsp file is useful if you want to load specific AutoLISP routines every time you start AutoCAD.
When you start AutoCAD, the program searches the library path for an acad.lsp file. If it finds one, it
loads the file into memory.
The acad.lsp file is loaded at each drawing session startup when AutoCAD is launched from the
Windows desktop. Because the acad.lsp file is intended to be used for application-specific startup
routines, all functions and variables defined in an acad.lsp file are only available in the first drawing. You
will probably want to move routines that should be available in all documents from your acad.lsp file into
the new acaddoc.lsp file.
The recommended functionality of acad.lsp and acaddoc.lsp can be overridden with the
ACADLSPASDOC system variable. If the ACADLSPASDOC system variable is set to 0 (the default
setting), the acad.lsp file is loaded just once; upon application startup. if ACADLSPASDOC is set to 1,
the acad.lsp file is reloaded with each new drawing.
The ACADLSPASDOC system variable is ignored in SDI (single document interface) mode. When the SDI
system variable is set to 1, the LISPINIT system variable controls reinitialization of AutoLISP between
drawings. When LISPINIT is set to 1, AutoLISP functions and variables are valid in the current drawing
only; each time you start a new drawing or open an existing one, all functions and variables are cleared
from memory and the acad.lsp file is reloaded. Changing the value of LISPINIT when the SDI system
variable is set to 0 has no effect.
The acad.lsp file can contain AutoLISP code for one or more routines, or just a series of load function
calls. The latter method is preferable, because modification is easier. If you save the following code as
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (3 of 8) [23/03/2005 05:44:28 p.m.]
an acad.lsp file, the files mysessionapp1.lsp, databasesynch.lsp, and drawingmanager.lsp are loaded
every time you start AutoCAD.
(load "mysessionapp1")
(load "databasesynch")
(load "drawingmanager")
Note: Do not modify the reserved acad2000.lsp file. Autodesk provides the acad2000.lsp file, which
contains AutoLISP defined functions that are required by AutoCAD. This file is loaded into memory
immediately before the acad.lsp file is loaded.

acaddoc.lspAutomatically Load AutoLISP


The acaddoc.lsp file is intended to be associated with each document (or drawing) initialization. This file
is useful if you want to load a library of AutoLISP routines to be available every time you start a new
drawing (or open an existing drawing). Each time a drawing opens, AutoCAD searches the library path
for an acaddoc.lsp file. If it finds one, it loads the file into memory. The acaddoc.lsp file is always loaded
with each drawing regardless of the settings of ACADLSPASDOC and LISPINIT.
Most users will have a single acaddoc.lsp file for all document-based AutoLISP routines. AutoCAD
searches for an acaddoc.lsp file in the order defined by the library path; therefore, with this feature, you
can have a different acaddoc.lsp file in each drawing directory, which would load specific AutoLISP
routines for certain types of drawings or jobs.
The acaddoc.lsp file can contain AutoLISP code for one or more routines, or just a series of load
function calls. The latter method is preferable, because modification is easier. If you save the following
code as an acaddoc.lsp file, the files mydocumentapp1.lsp, build.lsp, and counter.lsp are loaded every
time a new document is opened.
(load "mydocumentapp1")
(load "build")
(load "counter")
AutoCAD searches for an acaddoc.lsp file in the order defined by the library path; therefore, you can
have a different acaddoc.lsp file in each drawing directory. You can then load specific AutoLISP routines
for certain types of drawings or jobs.
Note: Do not modify the reserved acad2000doc.lsp file. Autodesk provides the acad2000doc.lsp file,
which contains AutoLISP-defined functions that are required by AutoCAD. This file is loaded into
memory immediately before the acaddoc.lsp file is loaded.
Menu File Types
The term menu file actually refers to the group of files that work together to define and control the
appearance and functionality of the menu areas. The following table describes the AutoCAD menu file
types.
AutoCAD menu files
File type Description
MNU Template menu file.
MNC
Compiled menu file. This binary file contains the command strings and menu syntax
that defines the functionality and appearance of the menu.
MNR Menu resource file. This binary file contains the bitmaps used by the menu.
MNS Source menu file (generated by AutoCAD).
MNT
Menu resource file. This file is generated when the MNR file is unavailable, for example,
read-only.
MNL
Menu LISP file. This file contains AutoLISP expressions that are used by the menu file
and are loaded into memory when a menu file with the same file name is loaded.
Load Menu Files
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (4 of 8) [23/03/2005 05:44:28 p.m.]
Use the MENU command to load a new menu. Use the MENULOAD and MENUUNLOAD commands to
load and unload additional menus (called partial menus) and to add or remove individual menus from the
menu bar.
AutoCAD stores the name of the last loaded menu in the system registry. Thisname is also saved with
the drawing, but it is used only for backward compatibility. When you start AutoCAD, the last menu used
is loaded. As of Release 14, AutoCAD no longer reloads the menu between drawings.
AutoCAD finds and loads the specified file according to the following sequence. (This sequence is also
used when AutoCAD loads a new menu with the MENU command.)
AutoCAD looks for a menu source file (MNS) of the given name, following the library search
procedure.
G
If an MNS file is found, AutoCAD looks for a compiled menu file (.mnc) of the same name in the
same directory. If AutoCAD finds a matching MNC file with the same or later date and time as the
MNS file, it loads the MNC file. Otherwise, AutoCAD compiles the MNS file, generating a new MNC
file in the same directory, and loads that file.
G
If an MNS file is not found, AutoCAD looks for a compiled menu file (.mnc) of the given name,
following the library search procedure. If AutoCAD finds the MNC file, it loads that file.
G
If AutoCAD doesn't find either a MNS or a MNC file, it searches the library path for a menu
template file (.mnc) of the given name. If this file is found, it compiles an MNC and MNS file, then
loads the MNC file.
G
If AutoCAD doesn't find any menu files of the given names, an error message is displayed and you
are prompted for another menu file name.
G
After finding, compiling, and loading the MNC file, AutoCAD looks for a menu LISP file (.mnl),
using the library search procedure. If AutoCAD finds this file, it evaluates the AutoLISP
expressions within that file.
G
The acad.mnl file contains AutoLISP code used by the standard menu file, acad.mnu. The acad.mnl file is
loaded each time the acad.mnu file is loaded.
Each time AutoCAD compiles an MNC file it generates a menu resource file (MNR) which contains the
bitmaps used by the menu. The MNS file is an ASCII file that is initially the same as the MNU file (without
comments or special formatting). The MNS file is modified by AutoCAD each time you make changes to
the contents of the menu file through the interface (such as modifying the contents of a toolbar).
Although the initial positioning of the toolbars is defined in the MNU or MNS file, changes to the
show/hide and docked/floating status or changes to the toolbar positions are recorded in the system
registry. After an MNS file has been created, it is used as the source for generating future MNC, and MNR
files. If you modify the MNU file after an MNS file has been generated, you must use the MENU command
to explicitly load the MNU file so that AutoCAD will generate new MNS and MNC files and your changes
will be recognized.
Note: If you use the interface to modify the toolbars, you should cut and paste the modified portions of
the MNS file to the MNU file before deleting the MNS file.
The MENU command initially requests the MNS or MNC file. To reload a modified MNU file, choose the
Menu Template item from the file type list, and then choose the MNU file from the list of files. Doing so
protects the MNS file from accidentally being rebuilt, thus losing any toolbar or partial menu
modifications done through the interface. While building and testing a menu file, you may find this
procedure awkward. The following AutoLISP routine defines a new command, MNU, which reloads the
current MNU file without going through all the prompts.
(defun C:MNU ()
(command "_menu" (strcat (getvar "menuname") ".mnu"))
(princ)
)
If you add this code to your acad.lsp file, the MNU command is automatically defined when you restart
AutoCAD.
acad.mnlAutomatically Load AutoLISP Menu Functions
The other type of file that AutoCAD loads automatically accompanies your current menu file and has the
extension .mnl. When AutoCAD loads a menu file, it searches for an MNL file with a matching file name.
If it finds the file, it loads the file into memory.
This function ensures that AutoCAD loads the AutoLISP functions that are needed for proper operation
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (5 of 8) [23/03/2005 05:44:28 p.m.]
of a menu. As an example, the standard AutoCAD menu, acad.mnu, relies on the file acad.mnl being
loaded properly. This file defines numerous AutoLISP functions used by the menu. The MNL file is
loaded after the acaddoc.lsp file.
Note: If a menu file is loaded with the AutoLISP command function (with syntax similar to (command
"menu" "newmenu") ), the associated MNL file is not loaded until the entire AutoLISP routine has run.
For example, if you create a custom menu called newmenu.mnu and you need to load three AutoLISP
files (new1.lsp, new2.lsp, and new3.lsp) for the menu to work properly, you should create an ASCII text
file named newmenu.mnl as follows:
(load "new1")
(load "new2")
(load "new3")
(princ "\nNewmenu utilities... Loaded.")
(princ)
In this example, calls to the princ function can be used to display status messages. The first use of princ
displays the following on the command line:
Newmenu utilities... Loaded.
The second call to princ exits the AutoLISP function. Without this second call to princ, the message
would be displayed twice. As mentioned previously, you can include the onfailure argument with calls to
the load function as an extra precaution.
S::STARTUP FunctionPost-Initialization Execution
The startup LISP files (acad.lsp, acaddoc.lsp, and .mnl) all load into memory before the drawing is
completely initialized. Typically, this does not pose a problem, unless you want to use the command
function, which is not guaranteed to work until after a drawing is initialized.
If the user-defined function S::STARTUP is included in an acad.lsp, acaddoc.lsp or a .mnl file, it is called
when you enter a new drawing or open an existing drawing. Thus, you can include a definition of
S::STARTUP in the LISP startup file to perform any setup operations.
For example, if you want to override the standard HATCH command by adding a message and then
switching to the BHATCH command, use an acaddoc.lsp file that contains the following:
(defun C:HATCH ( )
(alert "Using the BHATCH command!")
(princ "\nEnter OLDHATCH to get to real HATCH command.\n")
(command "BHATCH")
(princ)
)
(defun C:OLDHATCH ( )
(command ".HATCH")
(princ)
)
(defun-q S::STARTUP ( )
(command "undefine" "hatch")
(princ "\nRedefined HATCH to BHATCH!\n")
)
Before the drawing is initialized, new definitions for HATCH and OLDHATCH are defined with the defun
function. After the drawing is initialized, the S::STARTUP function is called and the standard definition of
HATCH is undefined.
Note: To be appended, the S::STARTUP function must have been defined with the defun-q function
rather than defun.
Because an S::STARTUP function can be defined in many places (an acad.lsp, acaddoc.lsp, .mnl file, or
any other AutoLISP file loaded from any of these), it's possible to overwrite a previously defined
S::STARTUP function. The following example shows one method of ensuring that your start-up function
works with other functions.
(defun-q MYSTARTUP ( )
... your start-up function ...
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (6 of 8) [23/03/2005 05:44:28 p.m.]
)
(setq S::STARTUP (append S::STARTUP MYSTARTUP))
The previous code appends your start-up function to that of an existing S::STARTUP function, and then
redefines the S::STARTUP function to include your start-up code. This works properly regardless of the
prior existence of an S::STARTUP function.
Tips for Coding AutoLISP Startup Files
If an AutoLISP error occurs while you are loading a startup file, the remainder of the file is ignored and is
not loaded. Files specified in a startup file that do not exist or that are not in the AutoCAD library path
generally cause errors. Therefore, you may want to use the onfailure argument with the load function.
The following example uses the onfailure argument:
(princ (load "mydocapp1" "\nMYDOCAPP1.LSP file not loaded."))
(princ (load "build" "\nBUILD.LSP file not loaded."))
(princ (load "counter" "\nCOUNTER.LSP file not loaded."))
(princ)
If a call to the load function is successful, it returns the value of the last expression in the file (usually
the name of the last defined function or a message regarding the use of the function). If the call fails, it
returns the value of the onfailure argument. In the preceding example, the value returned by the load
function is passed to the princ function, causing that value to be displayed on the command line. For
example, if an error occurs while AutoCAD loads the mydocapp1.lsp file, the princ function displays the
following message and AutoCAD continues to load the two remaining files:
MYDOCAPP1.LSP file not loaded.
If you use the command function in an acad.lsp, acaddoc.lsp or MNL file, it should be called only from
within a defun statement. Use the S::STARTUP function to define commands that need to be issued
immediately when you begin a drawing session. The S::STARTUP function is described in S::STARTUP
FunctionPost-Initialization Execution.
Command Autoloader
When you automatically load a command using the load or command functions, the command's
definition takes up memory whether or not you actually use the command. The AutoLISP autoload
function makes a command available without loading the entire routine into memory. Adding the
following code to your acaddoc.lsp file automatically loads the commands CMD1, CMD2, and CMD3 from
the cmds.lsp file and the NEWCMD command from the newcmd.lsp file.
(autoload "CMDS" '("CMD1" "CMD2" "CMD3"))
(autoload "NEWCMD" '("NEWCMD"))
The first time you enter an automatically loaded command at the Command prompt, AutoLISP loads the
entire command definition from the associated file. AutoLISP also provides the autoarxload function for
ObjectARX applications. See "autoload" and "autoarxload" in the AutoLISP Reference.
acadvba.arxAutomatically Load VBA
You cannot load VBA until an AutoCAD VBA command is issued. If you want to load VBA automatically
every time you start AutoCAD include the following line in the acad.rx file:
acadvba.arx
You can automatically run a macro in the acad.dvb file by naming the macro AcadStartup. Any macro in
your acad.dvb file called AcadStartup automatically executes when VBA loads.
acad.dvbAutomatically Load a VBA Project
The acad.dvb file is useful if you want to load a specific VBA project that contains macros you want each
time you start AutoCAD. Each time you start a new AutoCAD drawing session, AutoCAD searches for the
acad.dvb file and loads it.
If you want a macro in your acad.dvb file to run each time you start a new drawing or open an existing
one, add the following code to your acaddoc.lsp file:
(defun S::STARTUP()
(command "_-vbarun" "updatetitleblock")
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (7 of 8) [23/03/2005 05:44:28 p.m.]
)
Automatically Loading a VBA Project
There are two different ways to load a VBA project automatically:
When VBA is loaded it will look in the AutoCAD directory for a project named acad.dvb. This file
will automatically load as the default project
G
Any project other than the default, acad.dvb, can be used by explicitly loading that project at
startup using the VBALOAD command. The following code sample uses the AutoLISP startup file
to load VBA and a VBA project named myproj.dvb when AutoCAD is started. Start notepad.exe
and create (or append to) acad.lsp the following lines:
G
(defun S::STARTUP()
(command "_VBALOAD" "myproj.dvb")
)
Automatically Running a VBA Macro
You can automatically run any macro in the acad.dvb file by calling it with the command line version of
VBARUN from an AutoCAD startup facility like acad.lsp. For example, to automatically run the macro
named drawline, first save the drawline macro in the acad.dvb file. Next, invoke notepad.exe and create
(or append to) acad.lsp the following lines:
(defun S::STARTUP()
(command "_-vbarun" "drawline")
)
You can cause a macro to run automatically when VBA loads by naming the macro AcadStartup. Any
macro in your acad.dvb file called AcadStartup will automatically get executed when VBA loads.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD and Customizable Support Files
http://www.afralisp.com/lisp/custom.htm (8 of 8) [23/03/2005 05:44:28 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page II. Page III.
VBA and Menu's - Page I
Before starting on this tutorial, I presume that you are familiar with AutoCAD menu's and
that you have a bit of experience in modifying menu's or creating your own partial
menu's. It will also make things a lot easier for you if you have a basic understanding of
AutoCAD's macro language.
If not, and you don't understand a word that I am talking about, I suggest you pop along
to this tutorial, Creating Menu's, which should explain the basics to you.
Right, pull up a chair, grab a beer, and let's get started.
In VBA you can only create Pulldown and Toolbar menu's, although you can access Image, Screen
and Tablet menu's.
This tutorial will demonstrate how to create Pulldown and Toolbar menu's, as well as show you a
few examples on how to use menu macro's to call AutoCAD command functions, AutoLisp routines
and Image menu's.
Let's begin with Pulldown menu's. First you need to create an empty file in Notepad called
"VbaMenu.mns". Make sure that this file is within your AutoCAD search path. Fire up AutoCAD,
open the VBA Editor and add this coding to a module :
'CODING STARTS HERE
Option Explicit
Sub VbaMenu1()
Dim currMenuGroup As AcadMenuGroup
Dim openMacro As String
Dim newMenuItem As AcadPopupMenuItem
Dim newScmenu As AcadPopupMenu
Dim newMenu As AcadPopupMenu
On Error GoTo Err_Control
'Load the VBAMENU menu
ThisDrawing.Application.MenuGroups.Load "VbaMenu.mns"
'We now need to obtain a reference to our new menu, VBAMENU
'Use MenuGroups property to obtain reference to main VBAMENU menu
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("VBAMENU")
'==========================================================
'Create Pulldown Menu
'==========================================================
'Creat the pulldown menu title
Set newMenu = currMenuGroup.Menus.Add("V&BA Menu")
'==========================================================
VBA and Menu's
http://www.afralisp.com/vba/vbamenu.htm (1 of 4) [23/03/2005 05:44:30 p.m.]
'create the first pulldown item, vbaload
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaload" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "VBA &Load", openMacro)
newMenuItem.HelpString = "Load a VBA Application"
'==========================================================
'create the second pulldown item, vbaide
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaide" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "VBA &Editor", openMacro)
newMenuItem.HelpString = "Switch to the VBA Editor"
'==========================================================
'create the third pulldown item, vbarun
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbarun" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "VBA &Macro", openMacro)
newMenuItem.HelpString = "Run a VBA Macro"
'==========================================================
'create the fourth pulldown item, vbaman
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaman" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "&VBA Manager",
openMacro)
newMenuItem.HelpString = "Display the VBA Manager"
'==========================================================
'insert a separator after the fourth menu item
newMenu.AddSeparator (5)
'==========================================================
'create a simple menu macro
openMacro = Chr(3) & Chr(3) & Chr(95) & "zoom" & Chr(32) & "w" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "&Zoom", openMacro)
newMenuItem.HelpString = "Zoom Window"
'===================================================================
'create a menu item that loads and runs an Autolisp routine
openMacro = Chr(3) & Chr(3) & Chr(95) & "(if (not c:ddvpoint) (load ""ddvpoint"")" & Chr(32)
& "ddvpoint" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "View &Point", openMacro)
newMenuItem.HelpString = "View Point"
'===================================================================
'create a menu item that calls an Image menu
openMacro = Chr(3) & Chr(3) & Chr(95) & "$I=image_3dobjects $I=*"
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "&3D Objects", openMacro)
newMenuItem.HelpString = "3D Objects"
'===================================================================
'create a menu item with a hyperlink
openMacro = Chr(3) & Chr(3) & Chr(95) & "browser" & Chr(32) & "www.afralisp.com" &
Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "&AfraLisp.com",
openMacro)
newMenuItem.HelpString = "Visit AfraLisp now, or else."
'===================================================================
'===================================================================
'insert the pulldown menu into the menu bar, third from the end
newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count - 2)
'===================================================================
're-compile the VBAMENU menu - VBAMENU.MNC
currMenuGroup.Save acMenuFileCompiled
'save it as a MNS file.
currMenuGroup.Save acMenuFileSource
VBA and Menu's
http://www.afralisp.com/vba/vbamenu.htm (2 of 4) [23/03/2005 05:44:30 p.m.]
Just_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'The menu exists, just exit
Case -2147024809
Err.Clear
Resume Just_Here
Case Else
MsgBox Err.Description
Exit Sub
End Select
End Sub
'CODING ENDS HERE
Save your project as VbaMenu1, return to AutoCAD and run the macro. You should have a new
Pulldown menu on the menu bar that looks like this :
Try out each menu item. It works hey! Now navigate your way to were you stored VbaMenu.mns
and open it. You should see something like this :
//
// AutoCAD menu file - O:\e51d\e51d1\VbaMenu.mns
//
***MENUGROUP=VbaMenu
***POP2
ID_mnuVBA Menu [V&BA Menu]
ID_VBA Load [VBA &Load]^C^C_vbaload
ID_VBA Editor [VBA &Editor]^C^C_vbaide
ID_VBA Macro [VBA &Macro]^C^C_vbarun
ID_VBA Manager [&VBA Manager]^C^C_vbaman
[--]
ID_Zoom [&Zoom]^C^C_zoom w
ID_View Point [View &Point]^C^C_(if (not c:ddvpoint) (load "ddvpoint") ddvpoint
ID_3D Objects [&3D Objects]^C^C_$I=image_3dobjects $I=*
ID_AfraLisp.com [&AfraLisp.com]^C^C_browser www.afralisp.com
***TOOLBARS
***HELPSTRINGS
ID_VIEW POINT [View Point]
ID_AFRALISP.COM [Visit AfraLisp now, or else.]
ID_VBA MANAGER [Display the VBA Manager]
VBA and Menu's
http://www.afralisp.com/vba/vbamenu.htm (3 of 4) [23/03/2005 05:44:30 p.m.]
ID_VBA LOAD [Load a VBA Application]
ID_ZOOM [Zoom Window]
ID_VBA MACRO [Run a VBA Macro]
ID_3D OBJECTS [3D Objects]
ID_VBA EDITOR [Switch to the VBA Editor]
//
// End of AutoCAD menu file - O:\e51d\e51d1\VbaMenu.mns
//
You should also find VbaMenu.mnc and VbaMenu.mnr in the same folder. Even though the
VbaMenu.mns file was empty when we started, VBA has created all the coding necessary and
compiled the other menu support files required for the menu to run.
On the next page, we'll have a look at creating Toolbar menu's.
Home. Page II. Page III.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Menu's
http://www.afralisp.com/vba/vbamenu.htm (4 of 4) [23/03/2005 05:44:30 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page I. Page III.
VBA and Menu's - Page II
Before continuing with this tutorial, please delete the VbaMenu.mnc, VbaMenu.mnr files, and
delete the contents of VbaMenu.mns. This is to allow the menu to be re-compiled with only the
Toolbar menu items. You must also ensure that the 4 bitmap files, VbaLoad.bmp, Vbaide.bmp,
VbaMacro.bmp, and VbaMan.bmp are in the same folder as your menu files.
Now place the following coding into a module and save it as VbaMenu2.
'CODING STARTS HERE
Option Explicit
Sub VbaMenu2()
Dim currMenuGroup As AcadMenuGroup
Dim newToolBar As AcadToolbar
Dim newToolBarButton As AcadToolbarItem
Dim openMacro As String
Dim SmallBitmapName As String
Dim LargeBitmapName As String
On Error GoTo Err_Control
'Load the VBAMENU menu
ThisDrawing.Application.MenuGroups.Load "VbaMenu.mns"
'We now need to obtain a reference to our new menu, VBAMENU
'Use MenuGroups property to obtain reference to main VBAMENU menu
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("VBAMENU")
'==========================================================
' Create Toolbar Menu
Set newToolBar = currMenuGroup.Toolbars.Add("Vba Menu")
'==========================================================
'vbaload macro and bitmaps
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaload" & Chr(32)
Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1, "VBA Load",
"VBALoad", openMacro, False)
SmallBitmapName = "VBALOAD.BMP"
LargeBitmapName = "VBALOAD.BMP"
newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
newToolBarButton.HelpString = "Load a VBA Application"
'==========================================================
'vbaide macro and bitmaps
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaide" & Chr(32)
Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1, "VBA Editor",
"VBA Editer", openMacro, False)
SmallBitmapName = "VBAIDE.BMP"
VBA and Menu's II
http://www.afralisp.com/vba/vbamenu1.htm (1 of 3) [23/03/2005 05:44:31 p.m.]
LargeBitmapName = "VBAIDE.BMP"
newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
'==========================================================
'vbarun macro and bitmaps
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbarun" & Chr(32)
Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1, "Run Macro",
"Run Macro", openMacro, False)
SmallBitmapName = "VBAMACRO.BMP"
LargeBitmapName = "VBAMACRO.BMP"
newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
'==========================================================
'vbaman macro and bitmaps
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaman" & Chr(32)
Set newToolBarButton = newToolBar.AddToolbarButton(newToolBar.Count + 1, "VBA
Manager", "VBA Manager", openMacro, False)
SmallBitmapName = "VBAMAN.BMP"
LargeBitmapName = "VBAMAN.BMP"
newToolBarButton.SetBitmaps SmallBitmapName, LargeBitmapName
'==========================================================
're-compile the VBAMENU menu - VBAMENU.MNC
currMenuGroup.Save acMenuFileCompiled
'save it as a MNS file.
currMenuGroup.Save acMenuFileSource
Just_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'The menu exists, just exit
Case -2147024809
Err.Clear
Resume Just_Here
Case Else
MsgBox Err.Description
Exit Sub
End Select
End Sub
'CODING ENDS HERE
Run the VbaMenu2 macro. A toolbar like this should appear on your screen :
Open your VbaMenu.mns file. It should look like this :
//
// AutoCAD menu file - VbaMenu.mns
//
***MENUGROUP=VbaMenu
***TOOLBARS
VBA and Menu's II
http://www.afralisp.com/vba/vbamenu1.htm (2 of 3) [23/03/2005 05:44:31 p.m.]
**VBA_MENU
ID_Vba_Menu_0 [_Toolbar("Vba Menu", _Floating, _Show, 212, 192, 1)]
ID_VBA_Load_0 [_Button("VBA Load", "VBALOAD.BMP", "VBALOAD.BMP")]^C^C_vbaload
ID_VBA_Editor_0 [_Button("VBA Editor", "VBAIDE.BMP", "VBAIDE.BMP")]^C^C_vbaide
ID_Run_Macro_0 [_Button("Run Macro", "VBAMACRO.BMP",
"VBAMACRO.BMP")]^C^C_vbarun
ID_VBA_Manager_0 [_Button("VBA Manager", "VBAMAN.BMP",
"VBAMAN.BMP")]^C^C_vbaman
***HELPSTRINGS
ID_VBA_MANAGER_0 [VBA Manager]
ID_VBA_LOAD_0 [Load a VBA Application]
ID_RUN_MACRO_0 [Run Macro]
ID_VBA_EDITOR_0 [VBA Editer]
//
// End of AutoCAD menu file - VbaMenu.mns
//
Again, the coding for the menu has been compiled.
Crikey, this is getting interesting! Let's dig a bit deeper.
On the next page we'll have a look at accessing and adding to the AutoCAD PopUp menu's. Come
on, don't be scared.......
Home. Page II. Page III.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Menu's II
http://www.afralisp.com/vba/vbamenu1.htm (3 of 3) [23/03/2005 05:44:31 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page I. Page II.
VBA and Menu's - Page III
Let's look at the right-click Pop-up menu first. Up until now we've been dealing with our own
partial menu that we loaded to run alongside the AutoCAD menu. Pop-up menu's on the other
hand, are part of the AutoCAD menu. Therefore we need to access this menu and add the items
that we require.
Place this coding into a module and save it as VbaMenu3 :
'CODING STARTS HERE
Option Explicit
Sub VbaMenu3()
Dim currMenuGroup As AcadMenuGroup
Dim openMacro As String
Dim newScmenu As AcadPopupMenu
Dim newMenu As AcadPopupMenu
Dim scMenu As AcadPopupMenu
Dim entry As AcadPopupMenu
On Error GoTo Err_Control
' To add items to the right-click shortcut menu, we need to obtain
' reference to the AutoCAD menu.
' Use MenuGroups property to obtain reference to main ACAD menu
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("ACAD")
'===================================================================
'find the shortcut menu
For Each entry In currMenuGroup.Menus
If entry.ShortcutMenu = True Then
Set scMenu = entry
End If
Next entry
'create a shortcut menu item
Set newScmenu = scMenu.AddSubMenu(0, "&VBA Menu")
'create the vbaload macro
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaload" & Chr(32)
'display the shortcut sub-menu item
newScmenu.AddMenuItem "", "VBA &Load", openMacro
'create the vbaide macro
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaide" & Chr(32)
'display the shortcut sub-menu item
newScmenu.AddMenuItem "", "VBA &Editor", openMacro
VBA and Menu's III
http://www.afralisp.com/vba/vbamenu2.htm (1 of 5) [23/03/2005 05:44:34 p.m.]
'create the vbarun macro
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbarun" & Chr(32)
'display the shortcut sub-menu item
newScmenu.AddMenuItem "", "VBA &Macro", openMacro
'create the vbaman macro
openMacro = Chr(3) & Chr(3) & Chr(95) & "vbaman" & Chr(32)
'display the shortcut sub-menu item
newScmenu.AddMenuItem "", "&VBA Manager", openMacro
'add a separator line
scMenu.AddSeparator 1
're-compile the AutoCAD MENU
currMenuGroup.Save acMenuFileCompiled
'save it as a MNS file.
currMenuGroup.Save acMenuFileSource
'===============================================
'===============================================
Just_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'The menu exists, just exit
Case -2147024809
Err.Clear
Resume Just_Here
Case Else
MsgBox Err.Description
Exit Sub
End Select
End Sub
'CODING ENDS HERE
Now run the macro VbaMenu3. Right-click anywhere on the screen to activate the right-click
pop-up menu. It should now look like this :
Now open the AutoCAD.mns file and have a look at the POP0 menu section.
***POP0
**SNAP
[&Object Snap Cursor Menu]
VBA and Menu's III
http://www.afralisp.com/vba/vbamenu2.htm (2 of 5) [23/03/2005 05:44:34 p.m.]
ID_mnuVBA Menu [->&VBA Menu]
ID_VBA Load [VBA &Load]^C^C_vbaload
ID_VBA Editor [VBA &Editor]^C^C_vbaide
ID_VBA Macro [VBA &Macro]^C^C_vbarun
ID_VBA Manager [&VBA Manager]^C^C_vbaman
[--]
ID_Tracking [Temporary trac&k point]_tt
ID_From [&From]_from
ID_MnPointFi [->Poin&t Filters]
ID_PointFilx [.X].X
ID_PointFily [.Y].Y
ID_PointFilz [.Z].Z
[--]
ID_PointFixy [.XY].XY
ID_PointFixz [.XZ].XZ
ID_PointFiyz [<-.YZ].YZ
[--]
ID_OsnapEndp [&Endpoint]_endp
ID_OsnapMidp [&Midpoint]_mid
ID_OsnapInte [&Intersection]_int
ID_OsnapAppa [&Apparent Intersect]_appint
ID_OsnapExte [E&xtension]_ext
[--]
ID_OsnapCent [&Center]_cen
ID_OsnapQuad [&Quadrant]_qua
ID_OsnapTang [Tan&gent]_tan
[--]
ID_OsnapPerp [&Perpendicular]_per
ID_OsnapPara [Para&llel]_par
ID_OsnapNode [No&de]_nod
ID_OsnapInse [In&sert]_ins
ID_OsnapNear [Nea&rest]_nea
ID_OsnapNone [&None]_non
[--]
ID_Osnap [&Osnap Settings...]'_+dsettings 2
As you can see, the AutoCAD menu has been re-compiled with our new menu items included.
Right, let's now add to the cursor menu. Place this coding into a module and save it as VbaMenu4.
'CODING STARTS HERE
Private Sub AcadDocument_BeginShortcutMenuDefault(ShortcutMenu As
AutoCAD.IAcadPopupMenu)
On Error Resume Next
'Add a menu item to the cursor menu
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
openMacro = Chr(27) + Chr(27) + Chr(95) + "trim" + Chr(32) + Chr(32)
Set newMenuItem = ShortcutMenu.AddMenuItem _
(11, "&Trim", openMacro)
openMacro = Chr(27) + Chr(27) + Chr(95) + "extend" + Chr(32) + Chr(32)
Set newMenuItem = ShortcutMenu.AddMenuItem _
(12, "&Extend", openMacro)
End Sub
Private Sub AcadDocument_EndShortcutMenu _
(ShortcutMenu As AutoCAD.IAcadPopupMenu)
VBA and Menu's III
http://www.afralisp.com/vba/vbamenu2.htm (3 of 5) [23/03/2005 05:44:34 p.m.]
On Error Resume Next
ShortcutMenu.Item("Trim").Delete
ShortcutMenu.Item("Extend").Delete
End Sub
'CODING ENDS HERE
Add VbaMenu4 to your startup suitcase and re-start AutoCAD. Now, trigger your curser pop-up
menu.
You should have two new menu items, namely Trim and Extend.
Do you notice that this does not force the AutoCAD menu to re-compile but just adds and deletes
from it on the fly. Worth thinking about isn't it?
Would you like to boldly go where no man ever goes? Then be brave and just click here for the
source coding.
Home. Page I. Page II.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
VBA and Menu's III
http://www.afralisp.com/vba/vbamenu2.htm (4 of 5) [23/03/2005 05:44:34 p.m.]
Search
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Menu's III
http://www.afralisp.com/vba/vbamenu2.htm (5 of 5) [23/03/2005 05:44:34 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page II. Page III. Page IV.
To download this complete Tutorial including, all Menu's and Support files,
be brave and Click Here.
Creating Menu's - Page I.
You can write or, obtain, as many AutoLISP routines as you like, but it's still a pain in the
bum to have to type in something like :
(load "DDStruc_Steel_Ver2")
To have to type this in, or even remember the name every time you need to load or, run the routine,
is just basically daft and un-productive.
You could, load all your routines from the Acad.Lsp file. This though, would mean that they are all
in memory, chewing up your system resources.
What you need to be able to do is to load/run the routines from the AutoCAD menu. Not so long
ago, in earlier releases, the only option you had was to modify the standard AutoCAD menu. Not
anymore. Now you can create a custom menu known as a "Partial Menu" and install this to run
side by side with the standard AutoCAD menu.
This Tutorial will take you through all the steps of developing a fully, functional Custom Standard
Menu.
Note : I will only be covering Pull Down Menu's, Image Menu's and Toolbars in this tutorial. If you
need information on Screen, Button or Tablet Menu's, then please refer to the AutoCAD
Customization Manual.
To get started let's begin with designing a simple Pull Down or Pop Menu.
Fire up your text editor and type in the following saving the file as Test.Mnu :
(Please ensure that you save all files to a directory in the AutoCAD Search Path.)
***MENUGROUP=TEST //menu name
***POP1 //pull down name
P1-1[Test Menu] //pull down label
P1-2[Line] //menu items preceeded with ID
P1-3[Copy]
P1-4[Move]
P1-5[Zoom]
The first line :
***MENUGROUP=TEST
is the name of the Partial Menu.
The second line :
***POP1
is the name of the Drop Down or POP menu.
The third line consists of 2 parts :
P1-1
Creating Menu's I
http://www.afralisp.com/lispa/menu1.htm (1 of 3) [23/03/2005 05:44:36 p.m.]
This is the "Name Tag" or "ID" of the menu item and allows you to access the menu item
programmatically. The second part :
[Test-Menu]
is the menu label that appears in the Pull Down Menu.
The first label in a pull down menu always defines the menu bar title whilst, the succeeding labels
define menu and sub-menu items.
Now we need to load the menu.
If you already know how to Load and Un-Load menu files you can now load Test.mnu.
If not, click here for detailed instructions.
A new menu item will appear on the menu bar entitled "Test Menu".
It should look like this :
O.K. Now we've got our menu to display but, there's a problem. It doesn't do anything!! Let's make
it functional.
Create a new menu file entitled TEST1.MNU and type in the following:
***MENUGROUP=TEST1
***POP1
P1-1[&Test Menu1]
P1-2[&Line]^C^CLine
P1-3[&Copy]^C^CCopy
P1-4[M&ove]^C^CMove
P1-5[&Zoom]^C^CZoom
Load this menu, following the same routine as you did for the first menu.
"Test Menu1" will appear in the menu bar and your new pull down menu should look like this :
Let's have a close look at one of the menu items :
P1-2[&Line]^C^CLine
The first part, P1-1 is, of course, the menu item ID.
The second part, [&Line] is the menu label. But did you notice something different? What is the '&'
character doing in front of the 'L'?
If you precede any letter in the menu item label with '&', this will define the letter as the shortcut
Creating Menu's I
http://www.afralisp.com/lispa/menu1.htm (2 of 3) [23/03/2005 05:44:36 p.m.]
key to this menu item.
(There are other special label characters but, we will discuss these at a later stage.) In other words,
when you press 'ALT L' the Line Menu Item will be chosen and any action affiliated to it will be
triggered.
Following the item label, each menu item can consist of a command, parameter,
or a sequence of commands and parameters. Let's look at the Line menu item macro.
^C^CLine
Just in case we have a previous incomplete command, we use the string ^C^C to start our menu
macro. This is exactly the same as pressing CTRL+C or ESC, twice on the keyboard. We use ^C
twice because some AutoCAD commands need to be cancelled twice before they return to the
Command prompt.
(e.g. The Dim Command.)
We immediately follow this sequence with our AutoCAD command, Line.
When a menu item is selected, AutoCAD places a blank after it. A blank in a menu macro is
interpreted as ENTER or SPACEBAR. In effect, this is exactly the same as typing, at the command
prompt "Line" followed by ENTER.
More about Menu Macro's on the next page......
Home. Page II. Page III. Page IV.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Creating Menu's I
http://www.afralisp.com/lispa/menu1.htm (3 of 3) [23/03/2005 05:44:36 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Page I. Home Page III. Page IV.
Creating Menu's - Page II.
Menu Macro's
Let's look at some Special Menu Characters :
[ ] Encloses a Menu Label.
; Enter.
Space Enter or Spacebar.
\ Pauses for user input.
_ Translates AutoCAD commands.
+ Continues menu macro to next line.
*^C^C Prefix for repeating Item.
$ Character Code that loads a menu section.
^B Toggels Snap/Off.
^C Cancels command.
^D Toggles Coords.
^E Sets the next Isometric Plane.
^G Toggles Grid On/Off.
^H Issues Backspace.
^O Toggles Ortho On/Off.
^P Toggles Menuecho On/Off.
^Q Echoes all prompts.
^T Toggles Tablet On/Off.
^V Changes current Viewport.
^Z Null Character.
I don't really want to get too involved with Menu Macro's, but here is a few sample Macro's to show you
the general idea :
***MENUGROUP=TEST2
***POP1
P1-1[&Test Menu2]
P1-2[&Layer 2 On]^C^CLayer;M;2;;
P1-3[&Ortho On/Off]^C^C^O
P1-4[Change to Layer 3]*^C^CChange;\;P;LA;3;;
P1-5[&Hello World](alert "Hello World")
Your Menu should look like this :
The first Menu Item is again, the menu label.
The second item changes the current layer to layer 2.
(Layer Enter Make Enter 2 Enter Enter).
Creating Menu's II
http://www.afralisp.com/lispa/menu2.htm (1 of 2) [23/03/2005 05:44:37 p.m.]
The third item simply toggles Ortho On or Off.
The fourth item let's you select an object and changes it to layer 3.
(Change Enter Pause Enter Properties Enter Layer Enter 3 Enter Enter).
The * prefix will force the macro to repeat until the user hits CTRL-C or ESC.
The fourth item demonstrates the use of AutoLISP within a menu item.
Menu macro's can get quite long and complicated but my advice to you is, rather write an AutoLISP
routine than try and design complicated macro's.
Look at this for a macro :
[Box](setq a (getpoint "Enter First Corner: "));\ +
(setq b (getpoint "Enter Second Corner: "));\+
pline !a (list (car a)(cadr b))!b (list (car b) (cadr a))c;
Crazy, Hey. As I said, rather write an AutoLISP routine. You can do a hell of a lot more and, create a
much more professional routine using AutoLISP than you ever will trying to write super-duper, 20 line
macro's.
Just one small point about the above macro. Did you notice the use of the special character + at the end of
some of the lines. This allows the macro to continue to the next line.
Anyway, enough about menu macro's. Let's have a look at some special label characters that you can use
in pull-down menu's.
-- Item label that expands to become a separator line.
+ Continues macro to next line.
-> Label prefix that indicates that the pull-down menu item
has a submenu
<- Label prefix that indicates that the pull-down menu item
is the last item in a submenu.
<-<-.. Label prefix that indicates that the pull-down menu item
is the last item in the submenu, and terminates the parent
menu. One <- is required to each terminate each parent menu.
~ Lable prefix that disables a menu item.
!. Label prefix that marks a menu item.
& Label prefix that defines shortcut key.
On the next page we will have a look at an example menu using
some of these special characters.
Page I. Home. Page III. Page IV.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Creating Menu's II
http://www.afralisp.com/lispa/menu2.htm (2 of 2) [23/03/2005 05:44:37 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Page I. Page II Home. Page IV.
Creating Menu's - Page III.
Before loading the following menu, you should really un-load any of the test menu's that you
still have loaded. If you don't, you just might run out of space on your menu bar.
OK, I see you're back. Now load the following menu file :
***MENUGROUP=TEST3
***POP1
P1-1[&Test Menu 3]
P1-2[&Layer 2 On]^C^CLayer;M;2;; //menu item
P1-3[--] //divider
P1-4[&Ortho On/Off]^C^C^O //menu item
P1-5[--] //divider
P1-6[->&Change] //submenu label
P1-7[->C&hange Layer] //submenu label
P1-8[Change to Layer 1]^C^CChange;\;P;LA;1;; //submenu items
P1-9[Change to Layer 2]^C^CChange;\;P;LA;2;;
P1-10[Change to Layer 3]^C^CChange;\;P;LA;3;;
P1-11[<-Change to Layer 4]^C^CChange;\;P;LA;4;; //submenu terminator
P1-12[->Ch&ange Colour] //submenu label
P1-13[Change to Colour 3]^C^CChange;\;P;C;1;; //submenu items
P1-14[Change to Colour 3]^C^CChange;\;P;C;2;;
P1-15[Change to Colour 3]^C^CChange;\;P;C;3;;
P1-16[<-<-Change to Colour 4]^C^CChange;\;P;C;4;; //submenu terminator
P1-17[--] //divider
P1-18[&Kenny](alert "Kenny is Handsome") //menu item
Your menu, hopefully, should look like this :

Right, enough of pull-downs for the meantime. Let's now have a look at Image Menu's.
Firstly, we need to create a couple of slides to display in our image menu.
Let's create some slides named D1 to D8, DDOOR and HDDOOR.
You can create these slides yourself using any object that you wish, as long as they are named as stated. (I
need the server space and drawing files are rather big.) Now we need to create a file library as a container
for these slides.
Ceating Menu's III
http://www.afralisp.com/lispa/menu3.htm (1 of 4) [23/03/2005 05:44:39 p.m.]
Locate the Slidelib.exe function. It is normally in your Acad Support directory. Copy it to the same
directory as your slides.
Now create a text file named Slidelist.LST and in it, make a list of all the slide names. (Remember to check
spelling and case.)
D1
D2
D3
D4
D5
D6
D7
D8
DDOOR
HDDOOR
Make sure that this file is also in the same directory as the slides.
Now go to DOS. (Remember that 'black' place?)
At the DOS prompt find your way to the directory where your slides, Slidelib.exe and Slidelist.LST are
located.
Type :
slidelib DOORS < Slidelist.LST then ENTER.
If you have done everything correct, DOORS.SLB should be created.
Next, we need to add an Image section to our menu file :
***MENUGROUP=TEST4
***POP1
P1_1[&Test Menu 4]
P1_2[&Layer 2 On]^C^CLayer;M;2;;
P1_3[--]
P1_4[&Ortho On/Off]^C^C^O
P1_5[--]
P1_6[->&Change]
P1_7[->C&hange Layer]
P1_8[Change to Layer 1]^C^CChange;\;P;LA;1;;
P1_9[Change to Layer 2]^C^CChange;\;P;LA;2;;
P1_10[Change to Layer 3]^C^CChange;\;P;LA;3;;
P1_11[<-Change to Layer 4]^C^CChange;\;P;LA;4;;
P1_12[->Ch&ange Colour]
P1_13[Change to Colour 3]^C^CChange;\;P;C;1;;
P1_14[Change to Colour 3]^C^CChange;\;P;C;2;;
P1_15[Change to Colour 3]^C^CChange;\;P;C;3;;
P1_16[<-<-Change to Colour 4]^C^CChange;\;P;C;4;;
P1_17[--]
P1_18[&Kenny](alert "Kenny is Handsome")
P1_19[--]
P1_20[Image Menu]^C^C$I=TEST4.DOORS $I=* //calls Image Menu
***IMAGE
**DOORS
[DOORS Created by Kenny Ramage ]
[DOORS(D1,DOOR1)]INSERT;*D1;\;;
[DOORS(D2,DOOR2)]INSERT;*D2;\;;
[DOORS(D3,DOOR3)]INSERT;*D3;\;;
[DOORS(D4,DOOR4)]INSERT;*D4;\;;
[DOORS(D5,DOOR5)]INSERT;*D5;\;;
[DOORS(D6,DOOR6)]INSERT;*D6;\;;
[DOORS(D7,DOOR7)]INSERT;*D7;\;;
[DOORS(D8,DOOR8)]INSERT;*D8;\;;
[DOORS(DDOOR,DOUBLE DOOR)]INSERT;*DDOOR;\;;
[DOORS(HDDOOR,DOOR & HALF)]INSERT;*HDDOOR;\;;
[ FITTINGS]$I=KENNY.FITTINGS $I=*
Ceating Menu's III
http://www.afralisp.com/lispa/menu3.htm (2 of 4) [23/03/2005 05:44:39 p.m.]
The first line, ***IMAGE, defines the Image section of the menu.
The second line, **DOORS, is the name of the Image section submenu.
The third line is the title of the label that appears at the top.
The following lines get a bit more complicated so, let's dissect them.
[DOORS(D1,DOOR)]INSERT;*D1;\;;
[DOORS is the name of the slide library.
(D1, is the name of the specific slide.
,DOOR1)] is the label that is displayed in the list box.
INSERT;*D1;\;; is the menu macro.
Your Pull Down menu should now look like this :
And your Image menu like this (with different images of course) :
Did you notice the method of calling the image menu?
P1_20[Image Menu]^C^C$I=TEST4.DOORS $I=*
Good, at least some one is awake ;-)
Phew...(Wipe's sweat off brow)....Time for a break.
Next we'll move on to Custom Toolbars.
See you on the next page......
Page I. Page II. Home. Page IV.

Ceating Menu's III


http://www.afralisp.com/lispa/menu3.htm (3 of 4) [23/03/2005 05:44:39 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Ceating Menu's III
http://www.afralisp.com/lispa/menu3.htm (4 of 4) [23/03/2005 05:44:39 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Page I. Page II Page III. Home.
Creating Menu's - Page IV.
Custom Toolbars
The easiest way of creating a custom toolbar is to use the AutoCAD interface.
First, copy and rename Test4.MNU to Test5.MNU. Edit the menu file so that it looks like this :
***MENUGROUP=TEST5
***POP1
P1_1[&Test Menu 5]
P1_2[&Layer 2 On]^C^CLayer;M;2;;
P1_3[--]
P1_4[&Ortho On/Off]^C^C^O
P1_5[--]
P1_6[->&Change]
P1_7[->C&hange Layer]
P1_8[Change to Layer 1]^C^CChange;\;P;LA;1;;
P1_9[Change to Layer 2]^C^CChange;\;P;LA;2;;
P1_10[Change to Layer 3]^C^CChange;\;P;LA;3;;
P1_11[<-Change to Layer 4]^C^CChange;\;P;LA;4;;
P1_12[->Ch&ange Colour]
P1_13[Change to Colour 3]^C^CChange;\;P;C;1;;
P1_14[Change to Colour 3]^C^CChange;\;P;C;2;;
P1_15[Change to Colour 3]^C^CChange;\;P;C;3;;
P1_16[<-<-Change to Colour 4]^C^CChange;\;P;C;4;;
P1_17[--]
P1_18[&Kenny](alert "Kenny is Handsome")
P1_19[--]
P1_20[Image Menu]^C^C$I=TEST4.DOORS $I=*
***IMAGE
**DOORS
[DOORS Created by Kenny Ramage ]
[DOORS(D1,DOOR1)]INSERT;*D1;\;;
[DOORS(D2,DOOR2)]INSERT;*D2;\;;
[DOORS(D3,DOOR3)]INSERT;*D3;\;;
[DOORS(D4,DOOR4)]INSERT;*D4;\;;
[DOORS(D5,DOOR5)]INSERT;*D5;\;;
[DOORS(D6,DOOR6)]INSERT;*D6;\;;
[DOORS(D7,DOOR7)]INSERT;*D7;\;;
[DOORS(D8,DOOR8)]INSERT;*D8;\;;
[DOORS(DDOOR,DOUBLE DOOR)]INSERT;*DDOOR;\;;
[DOORS(HDDOOR,DOOR & HALF)]INSERT;*HDDOOR;\;;
[ FITTINGS]$I=KENNY.FITTINGS $I=*
Open AutoCAD and load this new menu file.
Now, to create a new toolbar, follow these steps :
Creating Menu's IV
http://www.afralisp.com/lispa/menu4.htm (1 of 6) [23/03/2005 05:44:42 p.m.]
Right Click on any toolbar.
The Toolbars Dialogue will open.
Select "New".
The New Toolbar dialogue will open
In the "Toolbar Name" edit box enter "Testbar" and from the "Menu Group" drop down list
select Test5.mnu
Select O.K.
A small empty toolbar will appear on your screen.
Select "Customize" from the "Toolbars" dialogue.
The "Customize Toolbars" dialogue will open.
Creating Menu's IV
http://www.afralisp.com/lispa/menu4.htm (2 of 6) [23/03/2005 05:44:42 p.m.]
In the "Catagories" list box select "Custom".
Select the blank tile then drag and drop it onto your empty toolbar.
Repeat this so that you have 3 blank tiles on your toolbar.
Your toolbar should look like this :
Select "Close"
You now have a toolbar with 3 buttons that do exactly nothing!!
Right Click on the first blank tile.
The "Button Properties" dialogue will open.
In the "Name" edit box type "Test Tool 1".
This will appear as a tooltip.
In the "Help" edit box type "This is Test Button 1".
This will appear in the status bar.
In the "Macro Edit" edit box enter :
^C^C(Alert "Test Tool 1")
Creating Menu's IV
http://www.afralisp.com/lispa/menu4.htm (3 of 6) [23/03/2005 05:44:42 p.m.]
This is the action assigned to this button.
Now, from the "Button Icon" list, select the first blank tile, then "Edit".
The "Button Editor" will open.
Select "Grid" to place a grid over your button.
Using the edit tools and the colour palette, draw the image that you would like to appear on your
button.
When you are happy select "Save" then "Close".
In the "Buttons Properties" dialogue select "Apply".
You will notice your completed button appear in your toolbar.
Right Click on the second button and repeat the process, naming the button "Test Tool 2".
Then again for the third button naming it "Test Tool 3".
When you have finished and have closed all dialogue boxes, your toolbar should look something like
this :
Select any of the buttons on the toolbar and you should get an alert message.
Now Exit AutoCAD.
Open Test5.mnu
Do you notice that nothing has changed and there is no Toolbar section in the MNU file?
The reason for this is because when you Add, Move or Edit any toolbars using the AutoCAD
interface, the results are written to the MNS file and not to the MNU file. To update the MNU file
and make our changes permanent, we need to copy and paste the toolbars section from the MNS
file into the MNU file.
Right, let's do that. Your MNU file should now look like this :
***MENUGROUP=TEST5
***POP1
Creating Menu's IV
http://www.afralisp.com/lispa/menu4.htm (4 of 6) [23/03/2005 05:44:42 p.m.]
P1_1[&Test Menu 5]
P1_2[&Layer 2 On]^C^CLayer;M;2;;
P1_3[--]
P1_4[&Ortho On/Off]^C^C^O
P1_5[--]
P1_6[->&Change]
P1_7[->C&hange Layer]
P1_8[Change to Layer 1]^C^CChange;\;P;LA;1;;
P1_9[Change to Layer 2]^C^CChange;\;P;LA;2;;
P1_10[Change to Layer 3]^C^CChange;\;P;LA;3;;
P1_11[<-Change to Layer 4]^C^CChange;\;P;LA;4;;
P1_12[->Ch&ange Colour]
P1_13[Change to Colour 3]^C^CChange;\;P;C;1;;
P1_14[Change to Colour 3]^C^CChange;\;P;C;2;;
P1_15[Change to Colour 3]^C^CChange;\;P;C;3;;
P1_16[<-<-Change to Colour 4]^C^CChange;\;P;C;4;;
P1_17[--]
P1_18[&Kenny](alert "Kenny is Handsome")
P1_19[--]
P1_20[Image Menu]^C^C$I=TEST4.DOORS $I=*
***IMAGE
**DOORS
[DOORS Created by Kenny Ramage ]
[DOORS(D1,DOOR1)]INSERT;*D1;\;;
[DOORS(D2,DOOR2)]INSERT;*D2;\;;
[DOORS(D3,DOOR3)]INSERT;*D3;\;;
[DOORS(D4,DOOR4)]INSERT;*D4;\;;
[DOORS(D5,DOOR5)]INSERT;*D5;\;;
[DOORS(D6,DOOR6)]INSERT;*D6;\;;
[DOORS(D7,DOOR7)]INSERT;*D7;\;;
[DOORS(D8,DOOR8)]INSERT;*D8;\;;
[DOORS(DDOOR,DOUBLE DOOR)]INSERT;*DDOOR;\;;
[DOORS(HDDOOR,DOOR & HALF)]INSERT;*HDDOOR;\;;
[ FITTINGS]$I=KENNY.FITTINGS $I=*
***TOOLBARS
**TESTBAR
ID_1 [_Toolbar("Testbar", _Floating, _Show, 202, 163, 1)]
ID_2 [_Button("Test Tool 1", "ICON.bmp", "ICON_24_BLANK")]
^C^C(Alert "Test Tool 1")
ID_3 [_Button("Test Tool 2", "ICON0041.bmp", "ICON_24_BLANK")]
^C^C(Alert "Test Tool 2")
ID_4 [_Button("Test Tool 3", "ICON8467.bmp", "ICON_24_BLANK")]
^C^C(Alert "Test Tool 3")
Let's take a closer look at the toolbars section :
***TOOLBARS is, of course, the label for the start of the toolbars section. **TESTBAR is the label
for the Toolbar Subsection.
The first Toolbar definition line (ID_1) defines the characteristics of
the toolbar itself. This is made up of 6 parts :
tbarname The string that names the toolbar. ("Testbar")
orient The orientation of the toolbar. (Floating)
Acceptable values are Floating, Top, Bottom,
Left and Right.
visible The visibility of the toolbar. (Show)
Acceptable values are Show and Hide.
Creating Menu's IV
http://www.afralisp.com/lispa/menu4.htm (5 of 6) [23/03/2005 05:44:42 p.m.]
xval The x co-ordinate of the toolbar (202)
Measured from the left edge of the screen to the
right side of the toolbar. (in pixels)
yval The y co-ordinate of the toolbar. (163)
Measured from the top edge of the screen to the
top of the toolbar. (in pixels)
rows Number of rows in the toolbar (1)
The second and remaining Toolbar definition lines (ID_2 to ID_4) define the characteristics of the
buttons. They are each made up of 3 parts :
btnname The string that names the button. ("Test Tool 1")
id_small The name of the small image bitmap (ICON.bmp)
(16 x 16 bitmap)
id_big The name of the large image bitmap (ICON_24_BLANK)
(24 x 24 bitmap)
macro Action/Command assigned to the button.
Did you notice that a blank tile is in place of the large 24 x 24 bitmap.
The reason for this, of course, is because we never defined a large bitmap.
If I require large bitmaps I use an imaging editing package to increase the size of my existing 16 x
16 bitmap to 24 x 24 and save it as a large bitmap, adding "24" to the end of the name.
Anyway, that's about it. I hope that you managed to muddle your way through this lot and that you
will soon be writing your own partial menu's.
I don't know about you, but this is thirsty work, so I'm off for an extremely large, cold beer. (or 10).
Cheers for now.......
To download this complete Tutorial including, all Menu's and Support files,
be brave and Click Here.

Page I. Page II. Page III. Home.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Creating Menu's IV
http://www.afralisp.com/lispa/menu4.htm (6 of 6) [23/03/2005 05:44:42 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Loading Partial Menu's
Fire up AutoCAD and follow these instructions :

Select "Tools" "Customise Menu's" from pulldown. G


Select "Browse" G
Change file type to "Menu Template (*.MNU)" G
Open Directory where TEST.MNU resides. G
Select "TEST.MNU" then press "OK" G
Select "Load". G
Answer "Yes" when prompted. G
Click on "Menu Bar" tab. G
From "Menu Group" pulldown select "TEST". G
In the "Menu's" section, select "Test Menu". G
Press "Insert" to add it to the Menu Bar. G
Select "Close" G
Un-Loading Partial Menu's
To Un-Load Partial Menu's do the following :

Select "Tools" "Customise Menu's" from pulldown. G


In the Menu Groups list, highlight the menu that you wish to remove. G
Select "Unload". G
Select "Close". G
The menu will be removed.
Menu files can also be loaded and un-loaded programmatically.
The methods of doing this will be covered later in the tutorial.
Just a couple of comments on Loading and Un-Loading menu's.
When loading a menu file, AutoCAD compiles the .MNU file into .MNC and .MNR files. The .MNC
file is a compiled version of the .MNU file and the .MNR file contains the bitmaps used by the
menu.
AutoCAD also generates a .MNS file. This is an ASCII file that is initially the same as the .MNU file
but is modified by AutoCAD each time you make changes to the menu file through the interface.
(such as modifying the contents of a toolbar.
HINT : If you have modified a menu file and it does not display correctly, or gives you other
hassles, then delete the .MNC, .MNR and .MNS files. This forces the menu to re-compile.
Back to Tutorial.

Loading Partial Menu's


http://www.afralisp.com/lispa/menu1a.htm (1 of 2) [23/03/2005 05:44:43 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Loading Partial Menu's
http://www.afralisp.com/lispa/menu1a.htm (2 of 2) [23/03/2005 05:44:43 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page II.
VBA and Sequential Text Files
Sometimes you may need to store and retrieve information but do no need the power of a
spreadsheet or database. (not to mention the extra coding, configuration and support files that go
along with it.) In these cases a text file may be just the thing you need. The process of storing and
retrieving information is simple, and the file can be edited by anyone - even if that person doesn't
have a spreadsheet/database tool.
Let's have a look first at reading from a sequential text file.
Let's say we have a text file containing a list of standard layers that we would like to import into
AutoCAD.
Here's what we would need to do :
1. Open the file for input.
2. Read a line from the file and store it in a variable.
3. Add the contents of the variable to a list box.
4. Repeat steps 2 and 3 for each line in the file.
5. Close the file.
O.K. first let's create our text file. Open Notepad and enter these layer names :
Annotations
Architectural
Beers
Border
Civil
Dimensions
Electrical
Existing
Instrumentation
Mechanical
Piping
Steel
Text
Now save this file as Layer.txt, ensuring that it is within your support path.
Now open a new Project and Userform. Place a Listbox on the form keeping the default name.
In the Userform Initialize event procedure, place the following code :
'CODING STARTS HERE
Private Sub UserForm_Initialize()
Dim sTemp As String
'clear listbox
ListBox1.Clear
'open the text file
Open "Layer.txt" For Input As #1
'until the end of file
While Not EOF(1)
'read the line and store it in a variable
VBA ans Sequential Text Files
http://www.afralisp.com/vba/extext.htm (1 of 4) [23/03/2005 05:44:45 p.m.]
Line Input #1, sTemp
'display in the list box
ListBox1.AddItem sTemp
'loop
Wend
'close the file
Close #1
End Sub
'CODING ENDS HERE

Run the Project. You Listbox should look like this :


In the preceding example, 1 is the file number. However, if you open and close multiple files
throughout your program, using this number might not be a good idea. In that case, you should use
the "FreeFile" function. I've re-written the coding below to include this function as well as some
basic error trapping :
'CODING STARTS HERE
Private Sub UserForm_Initialize()
Dim sTemp As String
Dim nFile As Integer
On Error GoTo err_handler
'get the next free file number
nFile = FreeFile
'clear listbox
ListBox1.Clear
'open the text file
Open "Layer.txt" For Input As #nFile
'until the end of file
While Not EOF(nFile)
'read the line and store it in a variable
Line Input #nFile, sTemp
'display in the list box
VBA ans Sequential Text Files
http://www.afralisp.com/vba/extext.htm (2 of 4) [23/03/2005 05:44:45 p.m.]
ListBox1.AddItem sTemp
'loop
Wend
'close the file
Close #nFile
Exit Sub
err_handler:
MsgBox Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End Sub
'CODING ENDS HERE
To write data, you open the file for sequential output or append. Have a look at the following two
lines of code, each of which opens a file for output :
'output mode - always creates a new file, erases any existing information
Open "DwgLog.txt" for Output as #nFile
'append mode - adds to an existing file or creates one
Open "DwgLog.txt" for Append as #nFile
Append mode means data written to a file is added to the end of existing data. Opening a file for
Output means that any existing data will be erased. In either case the Open statement automatically
creates the file if it does not exist.
Have a look at the following coding that when you run it, will write a Log file containing the date,
time and Drawing Number :
'CODING ENDS HERE
Sub DrgLog ()
Dim nFile1 As Integer
Dim Dname As String
On Error GoTo err_handler
'retrieve the drawing name
Dname = ThisDrawing.GetVariable("DWGNAME")
'get the next free file number
nFile1 = FreeFile
'open the file to append to
Open "DrgLog.txt" For Append As #nFile1
'write to the file
Print #nFile1, Format$(Now, "mm-dd-yy hh:mm:ss") & " - " & Dname
'close the file
Close #nFile1
Exit Sub
err_handler:
MsgBox Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End Sub
'CODING ENDS HERE
VBA ans Sequential Text Files
http://www.afralisp.com/vba/extext.htm (3 of 4) [23/03/2005 05:44:45 p.m.]
DrgLog.txt should have been created in your working directory. Open it and have a look. It should
look something like this :
11-02-01 09:57:20 - X3481.dwg
11-02-01 19:57:21 - X3482.dwg
11-02-01 14:40:20 - K2341.dwg
11-02-01 15:21:40 - K3418.dwg
Every time the routine is run, the date, time and Drawing Number is added to the file. (Hey, we
could make a good drawing log file out of this?)
On the next page we'll have a look at opening and searching a text file for multiple instances of
information required for a program to run.
Home. Page II.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA ans Sequential Text Files
http://www.afralisp.com/vba/extext.htm (4 of 4) [23/03/2005 05:44:45 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Home. Page I.
VBA and Sequential Text Files (Cont.)
To write a parametric routine, we need to store the parametric data for each individual object
somewhere. We could hard code it into the program. Safe and secure but difficult to maintain.
Alright then, a database or a spreadsheet. Also fine if you've got the software and know how to use
it. A text file on the other hand is simple to maintain and does not require any other type of
software or the knowledge to use and configure it.
Let's say for example we would like to write an application that parametrically draws structural
steel sections for us. We know all the names and basic dimensions of all the sections but just need to
be able to retrieve these values for our program to use.
O.K. let's set up our text file first. Open a new file in Notepad and add this :
ROLLED STEEL UNEQUAL ANGLES DATA
---------------------------------
H X W X T1 X R1 X R2
---------------------------------
*65x50x6
65.0,50.0,6.0,6.0,3.0
*65x50x8
65.0,50.0,8.0,6.0,3.0
*75x50x6
75.0,50.0,6.0,7.0,3.5
*75x50x8
75.0,50.0,8.0,7.0,3.5
*80x60x6
80.0,60.0,6.0,8.0,4.0
*80x60x8
80.0,60.0,8.0,8.0,4.0
*90x65x6
90.0,65.0,6.0,8.0,4.0
*90x65x8
90.0,65.0,8.0,8.0,4.0
*90x65x10
90.0,65.0,10.0,8.0,4.0
*100x65x8
100.0,65.0,8.0,10.0,5.0
*100x65x10
100.0,65.0,10.0,10.0,5.0
*100x75x6
100.0,75.0,6.0,10.0,5.0
*100x75x8
100.0,75.0,8.0,10.0,5.0
*100x75x10
100.0,75.0,10.0,10.0,5.0
*100x75x12
100.0,75.0,12.0,10.0,5.0
*125x75x8
125.0,75.0,8.0,11.0,5.5
*125x75x10
125.0,75.0,10.0,11.0,5.5
*125x75x12
125.0,75.0,12.0,11.0,5.5
*150x75x10
150.0,75.0,10.0,11.0,5.5
*150x75x12
150.0,75.0,12.0,11.0,5.5
VBA and Sequential Text Files II
http://www.afralisp.com/vba/extext1.htm (1 of 5) [23/03/2005 05:44:48 p.m.]
*150x75x15
150.0,75.0,15.0,11.0,5.5
*150x90x10
150.0,90.0,10.0,12.0,6.0
*150x90x12
150.0,90.0,12.0,12.0,6.0
*150x90x15
150.0,90.0,15.0,12.0,6.0
Save the file as Extext.dat.
The file basically contains two main lines of information required for each unequal angle.
The first line - *100x75x10" is the name of the angle and will be the string that appears in the list
box. The asterix "*" preceding the name, we will use as a marker for searching.
The second line - "100.0,75.0,10.0,10.0,5.0" is the information we are trying to retrieve. It is in
comma delimited format to allow us to read each item into it's appropriate variable.
Right onto the coding. Create a new Project and add a userform with two buttons, a list box and
two labels, maintaining the default names. Now add this coding :
'CODING STARTS HERE
Option Explicit
Private Sub UserForm_Initialize()
Dim sTempa As String
Dim nFilea As Integer
On Error GoTo err_handler
'setup and format the form
UserForm1.Caption = "Un-Equal Angles"
CommandButton1.Caption = "OK"
CommandButton1.Accelerator = "O"
CommandButton1.Default = False
CommandButton2.Caption = "Cancel"
CommandButton2.Accelerator = "C"
CommandButton2.Cancel = False
Label1.Caption = "www.AfraLisp.com"
Label2.Caption = "Select Size :"
'=============================================
'=============================================
'get the next free file number
nFilea = FreeFile
'clear listbox
ListBox1.Clear
'open the text file
Open "Extext.dat" For Input As #nFilea
'until the end of file
While Not EOF(nFilea)
'read the line and store it in a variable
Line Input #nFilea, sTempa
'isolate the first character and test
If Left$(sTempa, 1) = "*" Then
'remove the first character
sTempa = Right$(sTempa, (Len(sTempa) - 1))
'display the remainder in the list box
ListBox1.AddItem sTempa
'end if
End If
VBA and Sequential Text Files II
http://www.afralisp.com/vba/extext1.htm (2 of 5) [23/03/2005 05:44:48 p.m.]
'loop
Wend
'close the file
Close #nFilea
Exit Sub
err_handler:
MsgBox "Error No " & Err.Number & " - " & Err.Description
Err.Clear
Exit Sub
End Sub
'-------------------------------------------------------------------------------------------------
Private Sub CommandButton1_Click()
Dim sTemp As String
Dim sTemp1 As String
Dim nFile As Integer
Dim sHeight As String
Dim sWidth As String
Dim sThickness As String
Dim sRadius1 As String
Dim sRadius2 As String
On Error GoTo err_handler
'hide the form
UserForm1.Hide
'get the selection from the list box
sTemp = ListBox1.Text
'get the next free file number
nFile = FreeFile
'open the text file
Open "Extext.dat" For Input As #nFile
'until the end of file
While Not EOF(nFile)
'read the line and store it in a variable
Line Input #nFile, sTemp1
'compare the selection
If sTemp1 = "*" & sTemp Then
'read the next line and retrieve the values from the text file
'storing them into their respective variables
Input #nFile, sHeight, sWidth, sThickness, sRadius1, sRadius2
'display the results
MsgBox "Dimensions for " & sTemp & vbCr & vbCr _
& sHeight & " " & sWidth & " " & sThickness & " " _
& sRadius1 & " " & sRadius2
'close the file
Close #nFile
'you have now retrieved all the values necessary to draw
'the un-equal angle.
'coding for that would go here.
'we're done, so exit
Exit Sub
VBA and Sequential Text Files II
http://www.afralisp.com/vba/extext1.htm (3 of 5) [23/03/2005 05:44:48 p.m.]
'end if
End If
'loop
Wend
'close the file
Close #nFile
Exit Sub
err_handler:
MsgBox "Error No " & Err.Number & " - " & Err.Description
Err.Clear
Exit Sub
End Sub
'-------------------------------------------------------------------------------------------------------------------------
Private Sub CommandButton2_Click()
End
End Sub
'-------------------------------------------------------------------------------------------------------------------------
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'if the user double clicks the list box
CommandButton1_Click
End Sub
'CODING ENDS HERE
Run the program. A dialog like this should appear :
Highlight a size and select "OK" or double-click on the size. A message box should appear listing
the un-equal angles vital statistics :
VBA and Sequential Text Files II
http://www.afralisp.com/vba/extext1.htm (4 of 5) [23/03/2005 05:44:48 p.m.]
Now all you need to do is draw the un-equal angle. Hey, don't look at me, I've done enough for
today and I'm now off for a beer. Cheers!!!
Whoops, almost forgot! You probably want the source coding. Okey dokey, just click here.
Home. Page I.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Sequential Text Files II
http://www.afralisp.com/vba/extext1.htm (5 of 5) [23/03/2005 05:44:48 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA - Hiding Dialogs and Other Things
Recently, I posted an article regarding Hiding Dialogs in DCL. Well in this article, we're going to have a
look at hiding dialogs using VBA.
"But that's dead easy!" I can hear you saying.
I agree, it is pretty simple. The difficult part is what you do before and after hiding the dialog.
In the following example, we're going to write a routine that will allow us to select a line, and a line only,
from our drawing. Whilst we're going about the business of selecting the line, the dialog will disappear
from view. On completion of our selection, the dialog will magically re-appear and will display the layer
that the line is on, along with the x, y and x co-ordinates of the start and end points of the
aforementioned line.
As an added bonus, if you then change the layer or any of the lines co-ordinates from within the dialog,
the line itself will be updated in real time upon your screen. Interested? Then try this out :
For this you will need a UserForm containing 1 Label for the Listbox, 1 ListBox, 3 Buttons, two Frames
for the TextBoxes, 6 TextBoxes (3 in each Frame,) and 6 Labels for the TextBoxes. Retain all of their
default names and captions.
Option Explicit
'-----------------------------
'declare the public variables
Public theline As Object
Public AllLayers As AcadLayers
'------------------------------
Private Sub UserForm_Initialize()
Dim ctr As Integer
Dim layer As Object
'set up the controls
UserForm1.Caption = "Properties of a Line"
Label1.Caption = "Layer"
VBA - Hiding Dialogs and Other Things.
http://www.afralisp.com/vba/vba-hide.htm (1 of 7) [23/03/2005 05:44:52 p.m.]
CommandButton1.Caption = "Select Line >>"
CommandButton1.Default = True
CommandButton1.Accelerator = "S"
CommandButton2.Caption = "Cancel"
CommandButton2.Cancel = True
CommandButton2.Accelerator = "C"
CommandButton3.Caption = "Ok"
CommandButton3.Accelerator = "O"
Frame1.Caption = "Start Point"
Frame2.Caption = "End Point"
Label2.Caption = "x"
Label3.Caption = "y"
Label4.Caption = "z"
Label5.Caption = "x"
Label6.Caption = "y"
Label7.Caption = "z"
'retrieve the layers collection
Set AllLayers = ThisDrawing.Layers
'populate the list box with the
'layer names
For Each layer In AllLayers
ListBox1.AddItem layer.Name
Next
'switch off the listbox and the texboxes
ListBox1.Enabled = False
ListBox1.BackColor = &HC0C0C0
TextBox1.Enabled = False
TextBox1.BackColor = &HC0C0C0
TextBox2.Enabled = False
TextBox2.BackColor = &HC0C0C0
TextBox3.Enabled = False
TextBox3.BackColor = &HC0C0C0
TextBox4.Enabled = False
TextBox4.BackColor = &HC0C0C0
TextBox5.Enabled = False
TextBox5.BackColor = &HC0C0C0
TextBox6.Enabled = False
TextBox6.BackColor = &HC0C0C0
End Sub
'----------------------------------
Private Sub CommandButton1_Click()
Dim ppoint(0 To 2) As Double
Dim spoint As Variant
Dim epoint As Variant
Dim layer As Object
Dim cnt As Integer
'set up the error trap
On Error GoTo ErrorTrap
'switch on the listbox and the textboxes
ListBox1.Enabled = True
ListBox1.BackColor = &H80000005
VBA - Hiding Dialogs and Other Things.
http://www.afralisp.com/vba/vba-hide.htm (2 of 7) [23/03/2005 05:44:52 p.m.]
TextBox1.Enabled = True
TextBox1.BackColor = &H80000005
TextBox2.Enabled = True
TextBox2.BackColor = &H80000005
TextBox3.Enabled = True
TextBox3.BackColor = &H80000005
TextBox4.Enabled = True
TextBox4.BackColor = &H80000005
TextBox5.Enabled = True
TextBox5.BackColor = &H80000005
TextBox6.Enabled = True
TextBox6.BackColor = &H80000005
'******************************
'This is the part you've been
'waiting for.
'Hide the dialog
Me.Hide
'difficult hey??
'******************************
'select the line object
ThisDrawing.Utility.GetEntity theline, ppoint, vbCr & _
"Please Select a Line: "
'check if it's a line
If theline.EntityType <> acLine Then
Missed:

'it's not a line - inform the user
MsgBox "This is not a bloody line!!", _
vbExclamation + vbOKOnly

Else
'It is a line so we can continue.
'First get the start and end points.
With theline
spoint = .StartPoint
epoint = .EndPoint
End With
'set the counter to zero
cnt = 0
'find out which layer the line is on, and
'then set the listbox index
For Each layer In AllLayers
If theline.layer = layer.Name Then
ListBox1.ListIndex = cnt
Else
cnt = cnt + 1
End If
Next
'populate the textboxes with the start and end points
TextBox1.Text = Format(spoint(0), "0.00")
VBA - Hiding Dialogs and Other Things.
http://www.afralisp.com/vba/vba-hide.htm (3 of 7) [23/03/2005 05:44:52 p.m.]
TextBox2.Text = Format(spoint(1), "0.00")
TextBox3.Text = Format(spoint(2), "0.00")
TextBox4.Text = Format(epoint(0), "0.00")
TextBox5.Text = Format(epoint(1), "0.00")
TextBox6.Text = Format(epoint(2), "0.00")
End If
GoThere:
'******************************
'And to unhide the dialog......
'redisplay the dialog
Me.Show
'Also very difficult!!!
'******************************

Exit Sub
'define the error trap
ErrorTrap:
Select Case Err
'if the user missed!!!
Case -2147352567

'let them try again
Resume Missed

'if there is another problem
Case Else

'tell the user what it is
MsgBox "There was an error " _
& Err.Number & ":" & _
Err.Description, vbCritical
Resume GoThere
Resume
End Select

End Sub
'---------------------------------
Private Sub CommandButton2_Click()
End
End Sub
'---------------------------------
Private Sub CommandButton3_Click()
End
End Sub
'---------------------------------
Private Sub ListBox1_Change()
'change the line to the layer selected
VBA - Hiding Dialogs and Other Things.
http://www.afralisp.com/vba/vba-hide.htm (4 of 7) [23/03/2005 05:44:52 p.m.]
theline.layer = ListBox1.Value
'update the line
theline.Update
End Sub
'-----------------------------------
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'change the line to the layer selected
theline.layer = ListBox1.Value
'update the line
theline.Update
End Sub
'------------------------------
Private Sub TextBox1_Change()
Dim thestartx As Variant
'get the start/end point of the line
thestartx = theline.StartPoint
'substitute the new co-ordinate
thestartx(0) = TextBox1.Text
'insert the new start/endpoint
theline.StartPoint = thestartx
'update the line
theline.Update
End Sub
'----------------------------
Private Sub TextBox2_Change()
Dim thestarty As Variant
thestarty = theline.StartPoint
thestarty(1) = TextBox2.Text
theline.StartPoint = thestarty
theline.Update
End Sub
'-----------------------------
Private Sub TextBox3_Change()
Dim thestartz As Variant
thestartz = theline.StartPoint
thestartz(2) = TextBox3.Text
theline.StartPoint = thestartz
theline.Update
End Sub
'-----------------------------
VBA - Hiding Dialogs and Other Things.
http://www.afralisp.com/vba/vba-hide.htm (5 of 7) [23/03/2005 05:44:52 p.m.]
Private Sub TextBox4_Change()
Dim theendx As Variant
theendx = theline.EndPoint
theendx(0) = TextBox4.Text
theline.EndPoint = theendx
theline.Update
End Sub
'-----------------------------
Private Sub TextBox5_Change()
Dim theendy As Variant
theendy = theline.EndPoint
theendy(1) = TextBox5.Text
theline.EndPoint = theendy
theline.Update
End Sub
'-----------------------------
Private Sub TextBox6_Change()
Dim theendz As Variant
theendz = theline.EndPoint
theendz(2) = TextBox6.Text
theline.EndPoint = theendz
theline.Update
End Sub
'------------------------------
Of course, you will also need something to run your program with. Insert a new module and add this :
Public Sub HideDialog()
UserForm1.Show
End Sub
Load and run the program. A dialog will appear with a ListBox containing all the Layers within your
drawing. You will find that none of the controls work with the exception of the Buttons. Press the
"Select Line >>" button and the dialog will be hidden. Now, choose any line within your drawing. If you
miss the line, or select an object that is not a line, a message box will appear informing you that you've
messed up. Don't worry, the program will let you try again. Once you've mastered the art of selecting a
line, the dialog will re-appear. The ListBox will now show you what layer your line is on, along with the
x, y and z co-ordinates of the lines Start and End points.
Choose a different Layer in the ListBox. Notice how the line is immediately change to the new Layer?
Now change one of the x or y co-ordinates. Again, the line is immediately updated and "moved" to the
new set of co-ordinates. (Oh, by the way, no validation is performed on the values entered into the x, y
and z co-ordinate TextBoxes. If you enter anything other than a number, I've a sneaky suspicion that the
program may crash.)
Play with it, have fun..........
Here's the source coding for all you lazy ones out there - Vba-Hide.zip (26 kb)

VBA - Hiding Dialogs and Other Things.


http://www.afralisp.com/vba/vba-hide.htm (6 of 7) [23/03/2005 05:44:52 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA - Hiding Dialogs and Other Things.
http://www.afralisp.com/vba/vba-hide.htm (7 of 7) [23/03/2005 05:44:52 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Hiding Dialog Boxes in DCL
Ladies and Gentlemen "WASSUP"
Hee, hee - I've always wanted to do that.
Probably the most vexing (on my part) query I get, is in regards to hiding dialog boxes.
It seems to take ages and numerous emails before the poor soul trying to grasp the concept finally
understands the principle, or (and this is more likely) gives up and joins a monastery/nunnery.
So, without further due, and absolutely no regard for my own safety, I'm going to have another shot at
explaining how to go about hiding such a wee delicate thing as a dialog box.
Okay, are you ready? Are you sat nice and comfy on your cuddly, wuddly little bottom?
The let's do it!!!
("Randall, could you please keep the noise down 'cos I'm trying to explain something here. What?
You're eating!! Try and use a knife and and fork - I know it's chicken and you're allowed to use your
fingers, but you're supposed to cook the thing and remove the feathers first.")
On to the more serious bit............
Often you need to make a selection on the screen whilst a dialog box is active. But to do this, you need
to be able to hide the dialog box to allow the user to make a selection from the screen. You must then
restore the dialog box, along with the values that the user has selected. To accomplish this lets first
have a look at two of the most critical DCL functions :
(done_dialog [status])
status : A positive integer that (start_dialog) will return instead of returning 1 for OK or 0 for
Cancel. The meaning of any status value greater than 1 is determined by your application.
G
Usage Notes : An explicit AutoLisp action for the "accept" button must specify a status of 1 (or an
application-defined value); otherwise, (start_dialog) returns the default value, 0, which makes it
appear as if the dialog box was canceled.
G
(start_dialog)
Return Values : The (start_dialog) function returns the optional status passed to (done_dialog).
The default value is 1 if the user presses OK, 0 if the user presses Cancel, or -1 if all dialog boxes
are terminated with (term_dialog). If (done_dialog) is passed an integer status greater than 1,
(start_dialog) returns this value, whose meaning is determined by the application.
G
What the heck does all this mean????
When you want to close a dialog, you call the (done_dialog) function.
But did you know that when you call the (done_dialog) function a status argument is returned? Well it's
true!!!
Now think about this. When (done_dialog) is called from a tile who's key is 'cancel' (the Cancel button),
it returns a status of 0.
If a tile who's key is 'accept' is chosen (the OK button), it will return a status value of 1.
Note carefully, YOU must define a status of 1.
Now here's the important bit, if you use the (done_dialog) function along with a status value of say 4,
you know that the dialog box has been hidden and not ended or cancelled.
But how do I retrieve that status value?
Easy, when you call (start_dialog), it returns the (done_dialog) status value.
(setq flag (start_dialogue))
By testing this value in a (while) loop we can determine whether the dialog was simply hidden or
accepted or cancelled. Below is a sample routine that should, hopefully, I hope and pray, explain it to
you a lot better.
This routine simply displays a dialog box with three buttons
If you select "OK" or "Cancel", an alert box is displayed and the dialog is simply closed.
But, if you click the "Select Object" button, the dialog is hidden and an alert box is displayed informing
you of the fact. After selecting OK, the dialog is re-displayed or, to use the words of a great magician
that I once knew, un-hidden.
CAD Encoding - Hiding Dialog Boxes in DCL - Page I
http://www.afralisp.com/lisp/hide1.htm (1 of 4) [23/03/2005 05:44:53 p.m.]
First the DCL Coding :

hidedialog1 : dialog {
label = "Hide Dialogue";
: button {
label = "Hide Dialog >>";
key = "hide";
width = 8;
fixed_width = true;
mnemonic = "H";
alignment = centered;
is_default = true;
}
: spacer { width = 1;}
ok_cancel;
}
Save this as "HideDialog1.DCL
And now the AutoLisp coding. Save this as "HideDialog1.LSP :

(defun c:hidedialog1 ( / dcl_id flag)


;set flag to 4
(setq flag 4)
;load the DCL file
(setq dcl_id (load_dialog "hidedialog1.dcl"))

;check the flag status and carry on looping
;if it is greater than 2
(while (> flag 2)

;load the dialog box
(if (not (new_dialog "hidedialog1" dcl_id))

;if not loaded exit
(exit))
;Note: I have explicitly defined the status
;return value for the "cancel" "accept" and "hide"
;tiles. I recommend you do the same.
;if Cancel button selected, close
;the dialog. This action sets the
;flag to 0.
CAD Encoding - Hiding Dialog Boxes in DCL - Page I
http://www.afralisp.com/lisp/hide1.htm (2 of 4) [23/03/2005 05:44:53 p.m.]
(action_tile "cancel" "(done_dialog 0)")
;if OK button was selected, close
; the dialog. This action
;sets the flag to 1.
(action_tile "accept" "(done_dialog 1)")

;if pick button selected, hide the dialog
;and set the flag to 4
(action_tile "hide" "(done_dialog 4)")
;start the dialog and set flag
;to value of start dialog
(setq flag (start_dialog))
;if the OK button was selected
(if (= flag 1) (alert "You chose the OK button"))
;if the Cancel button was selected
(if (= flag 0) (alert "You chose the Cancel button"))
;if the pick button was selected
(if (= flag 4) (alert "You chose the Hide Dialog button"))
);while
;unload the dialog
(unload_dialog dcl_id)
(princ)
);defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ);load clean
Let's now get really brave and have a look at a wee practical example.......................
Home Page II

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
CAD Encoding - Hiding Dialog Boxes in DCL - Page I
http://www.afralisp.com/lisp/hide1.htm (3 of 4) [23/03/2005 05:44:53 p.m.]
Search
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
CAD Encoding - Hiding Dialog Boxes in DCL - Page I
http://www.afralisp.com/lisp/hide1.htm (4 of 4) [23/03/2005 05:44:53 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Hiding Dialog Boxes in DCL - Page II
We will now attempt to design a dialog box that will displays certain properties of a selected entity. We
would like the dialog to display first, and then hide itself whilst we go about making up our mind which
object we want to select. Once selected, the dialog will be updated with the objects property values. We
also want to be able to continue selecting objects which means that the dialog must update after each
selection.
Okay, let's give it a go.
First the DCL Coding :

hidedialog : dialog {
label = "Hide Dialogue";
: list_box {
label = "&Properties :";
key = "selections";
height = 7;
width = 25;
}
: button {
label = "Select Object >>";
key = "hide";
width = 8;
fixed_width = true;
mnemonic = "S";
alignment = centered;
is_default = true;
}
: spacer { width = 1;}
ok_cancel;
}
Save this as "HideDialog.DCL
CAD Encoding - Hiding Dialog Boxes in DCL - Page II
http://www.afralisp.com/lisp/hide2.htm (1 of 4) [23/03/2005 05:44:55 p.m.]
And now the AutoLisp coding. Save this as "HideDialog.LSP :

(defun c:hidedialog ( / dcl_id thelist lay col ltp lwt flag)


(vl-load-com)
;set up default list box values
(setq thelist '("Layer = NULL" "Color = NULL"
"Linetype = NULL" "Lineweight = NULL"))
;set flag to 4
(setq flag 4)
;load the DCL file
(setq dcl_id (load_dialog "hidedialog.dcl"))

;check the flag status and carry on looping
;if it is greater than 2
(while (> flag 2)

;load the dialog box
(if (not (new_dialog "hidedialog" dcl_id))

;if not loaded exit
(exit))
;populate the list box with the values
;in thelist
(start_list "selections")
(mapcar 'add_list thelist)
(end_list)
;if Cancel button selected, close
;the dialog. This action sets the
;flag to 0.
(action_tile "cancel" "(done_dialog 0)")
;if OK button was selected, close
; the dialog. This action
;sets the flag to 1.
(action_tile "accept" "(done_dialog 1)")

;if pick button selected, hide the dialog
;and set the flag to 4
(action_tile "hide" "(done_dialog 4)")
;start the dialog and set flag
;to value of start dialog
(setq flag (start_dialog))
;if the OK button was selected
(if (= flag 1) (alert "You chose the OK button"))
;if the Cancel button was selected
(if (= flag 0) (alert "You chose the Cancel button"))
;if the pick button was selected
CAD Encoding - Hiding Dialog Boxes in DCL - Page II
http://www.afralisp.com/lisp/hide2.htm (2 of 4) [23/03/2005 05:44:55 p.m.]
(if (= flag 4)
;do the following
(progn
;select the object
(setq ent (entsel))
;convert to vl object
(setq ent (vlax-Ename->Vla-Object (car ent)))
;get the properties and place them in a list
;the layer first
(setq lay (strcat "Layer = "
(vla-get-layer ent))
;then the color
col (strcat "Color = "
(itoa (vla-get-color ent)))
;next the linetype
ltp (strcat "Linetype = "
(vla-get-linetype ent))
;finally the lineweight
lwt (strcat "Lineweight = "
(itoa (vla-get-lineweight ent)))
;create the list
thelist (list lay col ltp lwt)
);setq
);progn
);if
);while
;unload the dialog
(unload_dialog dcl_id)
(princ)
);defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ);load clean
Hey just think! You can now design your own properties dialog.
Well that's about it regarding hiding dialog boxes.
I hope you had a good time, enjoyed the snacks (especially the chicken) and didn't drink too much beer.
Remember, don't drink and drive because you might spill some.
Did I forget? No I didn't. If you would like to download the source coding, just click here.
Home Page I
CAD Encoding - Hiding Dialog Boxes in DCL - Page II
http://www.afralisp.com/lisp/hide2.htm (3 of 4) [23/03/2005 05:44:55 p.m.]

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
CAD Encoding - Hiding Dialog Boxes in DCL - Page II
http://www.afralisp.com/lisp/hide2.htm (4 of 4) [23/03/2005 05:44:55 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
PolyLines and Arcs
by Scott McGlynn
As we are all well aware, the bulge is defined as :
So, rearranging the equation :
Ok. Now we have the included angle for the Arc.
From trigonometry, we know that Arc Length is defined as:
So all we have to do is figure out the Radius.
We can determine that using 2 pieces of information, of the chord length, and the included angle as shown in Figure
1.
PolyLines and Arcs
http://www.afralisp.com/lisp/polyarc.htm (1 of 5) [23/03/2005 05:45:00 p.m.]
The Chord length can be calculated as the straightline distance between two points. We have a function defined called
"Calculate3Ddistance" that does just that :
Passing in the 2 points, we get back the full chord length. Divide by 2 and we have the short leg of the triangle above (y).
We can calculate the Hypotenuse which is also the radius using f, and the short leg using the following formula :
However,
PolyLines and Arcs
http://www.afralisp.com/lisp/polyarc.htm (2 of 5) [23/03/2005 05:45:00 p.m.]
so we can simplify this formula to :
Unfortunately, the Cosecant function is not defined in VB, so we are left with the 1/sin version.
Tying all of this together, we have a function called "CalculatePolylineLength" We pass the function an entity. We test to
ensure it is a Polyline, then proceed to the actual work.
First, we get the upper and lower bounds of the coords variant. Then begin a For Next loop to loop through each set of 2D
coordinates. Because the "GetBulge" method of the polyline object returns the bulge for a segment, and there are the
number of segments as thare are coordinates (2 coordinates per point), we get the bulge of the loop counter/2 instead of
the loopcounter.
We then get the coordinates of the first point, x1 & y1, then the coordinates of the second point x2 & y2. Depending on
the value of the bulge, we either call the "Calculate3D Distance" or "CalculateArcLength" keeping a running total of the
lengths.
PolyLines and Arcs
http://www.afralisp.com/lisp/polyarc.htm (3 of 5) [23/03/2005 05:45:00 p.m.]

PolyLines and Arcs


http://www.afralisp.com/lisp/polyarc.htm (4 of 5) [23/03/2005 05:45:00 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
PolyLines and Arcs
http://www.afralisp.com/lisp/polyarc.htm (5 of 5) [23/03/2005 05:45:00 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Polyline Bulges
By Stig Madsen, 2003
Bulges are something that women have (mostly to please the opposite sex it seems) and something that guys try to get by
placing socks in strategic places. At least until they get older. Which is the time they tend to develop bulges in not so strategic
places. In other words: bulges are all about curvature.
In AutoCAD, bulges are used in shapes and in arc segments of polylines. This article only deals with polyline bulges, and
because polyline bulges are describing circular arcs, let's first look at the geometry of a circular arc.
Because a circular arc describes a portion of the circumference of a circle, it has all the attributes of a circle:
Radius (r) is the same as in the circle the arc is a portion of. G
Center point (P) is also the same as in the circle. G
Included angle (&theta;). In a circle, this angle is 360 degrees. G
Arc length (le). The arc length is equal to the perimeter in a full circle. G
Adding to these attributes are some that are specific for an arc:
Start point and end point (P1 and P2) a.k.a. vertices (although sometimes it is practical to talk about specific points that a
circle passes through, there are no distinct vertices on the circumference of a circle).
G
Chord length (c). An infinite amount of chords can be described by both circles and arcs, but for an arc there is only one
distinct chord that passes through its vertices (for a circle, there is only one distinct chord that passes through the
center, the diameter, but it doesn't describe any specific vertices).
G
Given two fixed vertices, there is also a specific midpoint (P3) of an arc. G
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (1 of 8) [23/03/2005 05:45:05 p.m.]
The apothem (a). This line starts at the center and is perpendicular to the chord. G
The sagitta (s) a.k.a. height of the arc. This line is drawn from the midpoint of an arc and perpendicular to its chord. G
Except for the arc itself, an arc can describe two distinct geometric forms: Circular segment and circular sector. Both figures
includes all of the attributes above, but for doing calculations with bulges, we'll mostly use the piece of pie that the arc cuts out
of a circle, the circular sector.
So, what is a bulge for a circular arc and how is it defined? In AutoCAD's online help reference, it says about bulges for
polylines:
The bulge is the tangent of 1/4 of the included angle for the arc between the selected vertex and the next vertex in the polyline's
vertex list. A negative bulge value indicates that the arc goes clockwise from the selected vertex to the next vertex. A bulge of 0
indicates a straight segment, and a bulge of 1 is a semicircle.
What does this mean and how can an arc be defined without even knowing the radius - or at least a chord length? It says that
the only information given for arc segments in polylines are two vertices and a bulge.
Well, it also says that the bulge has something to do with the tangent of a quarter of the included angle of an arc. That must be
a clue of how to obtain the angle. In fact, once you have a bulge value, you can very quickly retrieve the included angle by
inverting the above statement. Simply use the built-in function ATAN to get an angle and multiply it by 4 in order to get the
included angle:
(* 4.0 (atan 0.57735))
2.09439
So, a bulge of 0.57735 is describing an included angle of 2.09439 radians (which is 120.0 degrees, by the way). Try it out for yourself. Start
drawing a lightweight polyline, type "A" for arc, then "A" again for Angle and "120.0" for the included angle. Drop the endpoint somewhere,
leave the polyline command and type this at the command line:
Command: (setq ent (entget (entlast)))
((-1 . < Entity name: 7ef844f8>) (0 . "LWPOLYLINE") (330 . < Entity name:
7ef5ccf8>) (5 . "31F") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0")
(100 . "AcDbPolyline") (90 . 2) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10
-566.044 916.408) (40 . 0.0) (41 . 0.0) (42 . 0.57735) (10 -485.424 1075.7) (40
. 0.0) (41 . 0.0) (42 . -7.40144) (210 0.0 0.0 1.0))
Command: (setq bulge (cdr (assoc 42 ent)))
0.57735
Now you have a bulge value for the arc segment in the polyline, and you can try out the formula above.
Ok, fine. But why is the bulge 1/4 of the included angle and where does the tangent fit in? There are many ways to explain this. One is shown
below. The figures show a circle with a central angle describing an arc and we'll try to show that the yellow angles &epsilon; and &sigma; are
exactly one quarter of the cyan central angle &theta;.
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (2 of 8) [23/03/2005 05:45:05 p.m.]
If the full angle is cut in half - as shown with the blue angle &eta; at figure 2 - we get an isosceles triangle (green) where the angles &phi; and
&tau; are equal. Because the sum of angles in a triangle is always 180 degrees, we now know that the angles &phi; and &tau; are
= = (180 - /2)/2 => = 90 - /4
Now look at the chord from P1 to P2 in figure 3. Together with the red legs of angle &theta; it also forms an isosceles triangle, and therefore
&gamma; is equal to &xi;. The top angle is the full angle of &theta;, so &gamma; and &xi; become equal to
= = (180 - )/2 => = 90 - /2
Thus, the yellow angle &epsilon; must be the magenta angle &phi; minus the orange angle &gamma;. In other words, &epsilon; is a quarter of
the included angle &theta;:
= (90 - /4) - (90 - /2) => = /2 - /4 = /4
The bulge is describing how much the arc "bulges out" from the vertices, i.e. the height of the arc (the sagitta (s), or the distance P3 to P4 in
figure 4). The height forms a leg of a right-angled triangle that has an exact angle of 1/4 of the included angle (see the yellow triangle P-P2-P3
in figure 4) and because tangent is describing the ratio between the legs in a right-angled triangle, it's easy to describe the geometry with this
one angle:
sin /cos = tan
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (3 of 8) [23/03/2005 05:45:05 p.m.]
We could also find tangent of angle &epsilon; by simply dividing the opposite leg with the adjacant leg - which means the sagitta, s, divided by
half the distance of the chord, c, - but not knowing s and having the tangent of &epsilon; already, we would rather want to find s:
s = c/2 * tan()
Given that bulge = tan(&epsilon;), we get
s = c/2 * bulge
Radius of the arc can now be found with this formula:
r = ((c/2)
2
+s
2
)/2*s
The sign of a particular bulge is important for the way it's defined in relation to the vertices. If a bulge is positive it means that the arc is
measured counterclockwise from the starting vertex to the end vertex. If a bulge is negative it means that the arc runs the other way round, -
it's measured clockwise. The system variable ANGDIR has no influence on this.
Therefore all the formulas above has to be concerned about the absolute value of the bulge instead of the actual value - or you might end up
with a negative radius. In the code below we will find the center point. There are many ways to do this, but the method that is chosen here
relies on the angles that were defined previously. Subsequently, we will need it to test whether the bulge is postive or negative and act
accordingly.
Remember that the orange angle &gamma; in fig. 3 was found to be 90 degrees minus half of the included angle? What happens if we add (or
subtract, depending on the arc direction) this angle to the angle between the two known vertices P1 and P2? We get the angle towards the
center. Knowing the angle, the radius and the start point of the arc we can find the center point with POLAR.
(setq gamma (/ (- pi theta) 2.0)
phi (if (>= bulge 0)
(+ (angle p1 p2) gamma)
(- (angle p1 p2) gamma)
)
p (polar p1 phi r)
)
Another way to find the direction towards the center is to use good old Pythagorus. We already know radius and the chord length, so by using
radius as the hypothenuse and half the chord length as a leg in a right-angled triangle, where the apothem is the second leg, it's possible to
draw the apothem and find the center point.
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (4 of 8) [23/03/2005 05:45:05 p.m.]
(setq c|2 (/ c 2.0))
(setq a (sqrt (- (expt r 2.0) (expt c|2 2.0)))
midp (polar p1 (angle p1 p2) c|2)
p2 (if (>= bulge 0)
(polar midp (+ (angle p1 p2) (/ pi 2.0)) a)
(polar midp (- (angle p1 p2) (/ pi 2.0)) a)
)
)
By now, enough angles and distances are known to also use other trigonometric functions in order to find the center point without using
POLAR, but that has to remain a home assignment for now. Let's get some code up'n'running, utilizing the formulas and methods we just
went over. Later we will repeat some of the formulas to use with bulges.
First function will be an ordinary pick-a-polyline function. It contains no magic. The user is merely asked to pick a lightweight polyline and, if
successful, it returns a list of all segments on the form (vertex1 bulge vertex2). These segments will later be used to analyze each arc segment in
the polyline. Although it only accepts lightweight polylines, there's nothing to prevent you from adjusting it to also accept old-style polylines.
(defun getPolySegs (/ ent entl p1 pt bulge seg ptlst)
(setvar "ERRNO" 0)
;; repeat request for polyline until user either picks
;; a polyline or exits without picking
(while (and (not ent) (/= (getvar "ERRNO") 52))
(if (and (setq ent (car (entsel "\nSelect polyline: ")))
(/= (cdr (assoc 0 (setq entl (entget ent)))) "LWPOLYLINE")
)
(setq ent nil)
)
)
(cond (ent
;; save start point if polyline is closed
(if (= (logand (cdr (assoc 70 entl)) 1) 1)
(setq p1 (cdr (assoc 10 entl)))
)
;; run thru entity list to collect list of segments
(while (setq entl (member (assoc 10 entl) entl))
;; if segment then add to list
(if (and pt bulge)
(setq seg (list pt bulge))
)
;; save next point and bulge
(setq pt (cdr (assoc 10 entl))
bulge (cdr (assoc 42 entl))
)
;; if segment is build then add last point to segment
;; and add segment to list
(if seg
(setq seg (append seg (list pt))
ptlst (cons seg ptlst))
)
;; reduce list and clear temporary segment
(setq entl (cdr entl)
seg nil
)
)
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (5 of 8) [23/03/2005 05:45:05 p.m.]
)
)
;; if polyline is closed then add closing segment to list
(if p1 (setq ptlst (cons (list pt bulge p1) ptlst)))
;; reverse and return list of segments
(reverse ptlst)
)
Next function will be our workhorse. It will use everything we now know about retrieving included angle, height of arc, chord length, radius
and center point.
The function accepts a list of arguments on the form that corresponds to the segment sublists from the previous function - (vertex1 bulge
vertex2). If the argument is acceptable, it will print out information about the arc segment. We'll let the comments in the code take over any
further explanation.
(defun getArcInfo (segment / a p1 bulge p2 c c|2 gamma midp p phi r r2 s theta)
;; assign variables to values in argument
(mapcar 'set '(p1 bulge p2) segment)
;; find included angle
;; remember that bulge is negative if drawn clockwise
(setq theta (* 4.0 (atan (abs bulge))))
;; output included angle
(princ (strcat "\n Included angle: "
(rtos theta)
" rad ("
(angtos theta 0)
" degrees)"
)
)
;; find height of the arc
(setq c (distance p1 p2)
s (* (/ c 2.0) (abs bulge))
)
;; output height of arc
(princ (strcat "\n Height of arc: " (rtos s)))
;; output chord length
(princ (strcat "\n Chord length: " (rtos c)))
;; If this function is used without making sure that the segment
;; is not simply a line segment (bulge = 0.0), it will produce
;; a division-by-zero error in the following. Therefore we want
;; to be sure that it doesn't process line segments.
(cond ((not (equal bulge 0.0 1E-6))
;; find radius of arc
;; first find half the chord length
(setq c|2 (/ c 2.0)
;; find radius with Pythagoras (used as output)
r (/ (+ (expt c|2 2.0) (expt s 2.0)) (* s 2.0))
;; find radius with trigonometry
r2 (/ c|2 (sin (/ theta 2.0)))
)
(princ (strcat "\n Radius of arc: " (rtos r)))
;; find center point of arc with angle arithmetic
;; (used as output)
(setq gamma (/ (- pi theta) 2.0)
phi (if (>= bulge 0)
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (6 of 8) [23/03/2005 05:45:05 p.m.]
(+ (angle p1 p2) gamma)
(- (angle p1 p2) gamma)
)
p (polar p1 phi r)
)
;; find center point of arc with Pythagoras
(setq a (sqrt (- (expt r 2.0) (expt c|2 2.0)))
midp (polar p1 (angle p1 p2) c|2)
p2 (if (>= bulge 0)
(polar midp (+ (angle p1 p2) (/ pi 2.0)) a)
(polar midp (- (angle p1 p2) (/ pi 2.0)) a)
)
)
;; output coordinates of center point
(princ (strcat "\n Center of arc: "
(rtos (car p))
","
(rtos (cadr p))
)
)
)
(T (princ "\n Segment has no arc info"))
)
(princ)
)
To try out these two functions, first draw a lightweight polyline with a couple of arc segments. At the command line, call getPolysegs and assign
a variable to the returned list:
Command: (setq myPoly (getPolySegs))
Select polyline: [select a polyline]
If a lightweight polyline was selected, it will return a list of segments. If, for example, the second segment contains a bulge value different from
0.0 then you can call the latter function like this:
Command: (getArcInfo (nth 1 myPoly))
Included angle: 1.9265 rad (110.3830 degrees)
Height of arc: 855.2904
Chord length: 3272.6317
Radius of arc: 1992.9203
Center of arc: 34915.2223,21409.8733
The last function in this article will bind the two functions together and explore each arc segment in the selected polyline. It will appear in part
two - along with some useful formulas for dealing with bulges.
Page II

Polyline Bulges Page I


http://www.afralisp.com/lisp/Bulges1.htm (7 of 8) [23/03/2005 05:45:05 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Polyline Bulges Page I
http://www.afralisp.com/lisp/Bulges1.htm (8 of 8) [23/03/2005 05:45:05 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
PolyLines and Blocks.
PolyLines and Blocks!!! Come back... Don't run away....
Honestly, they are a lot easier to deal with than you think.
I know that they are called "complex entities", but the only difference between them and other
entities is that we just have to dig a bit deeper to get to what we want. In fact, once we get there I'll
show you a couple of things that you swear is magic. So bear with me, take your time, and hang on
for a ride on the magic carpet.......
PolyLines.
The lwpolyline entity, or "optimized polyline," is new to Release 14.
A lwpolyline is defined in the drawing database as a single graphic entity.
This is different than a standard polyline, which is defined as a group of subentities. Lwpolylines
display faster and consume less disk space and RAM.
In Release 14, 3D polylines are always created as standard polyline entities.
2D polylines are created as lwpolyline entities unless they have been curved or fitted with the PEDIT
command. When a drawing from a previous release is opened in Release 14, all 2D polylines convert
to lwpolylines automatically unless they have been curved or fitted or contain xdata.
We will have a look at the R13 and below Polyline first.
First of all draw 3 joined polylines. (3DPoly if you are using R14).
Then type this :
Command: (setq e (entget (car (entsel))))
AutoLisp should return something like this :
Select object: ((-1 . ) (0 . "POLYLINE") (5 . "27B") (100
. "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDb3dPolyline") (66 . 1) (10 0.0
0.0 0.0) (70 . 8) (40 . 0.0) (41 . 0.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73
. 0) (74 . 0) (75 . 0))
Hey, wait a minute!!!......AutoLisp has returned the entity list, and I can see that it's a Polyline, but there are no
co-ordinates, and where does AutoLisp get the co-ordinates for all the vertices?
As I said earlier, we need to dig a little bit deeper to get the information we require. This is where the (entnext)
function comes into play.
Now type the following 5 code segments :
Command: (setq e1 (entget (entnext (cdr (car e)))))
((-1 . ) (0 . "VERTEX") (5 . "27C") (100 . "AcDbEntity")
(67 . 0) (8 . "0") (100 . "AcDbVertex") (100 . "AcDb3dPolylineVertex") (10
391.774 521.633 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 32) (50 . 0.0) (71
. 0) (72 . 0) (73 . 0) (74 . 0))
Command: (setq e2 (entget (entnext (cdr (car e1)))))
((-1 . ) (0 . "VERTEX") (5 . "27D") (100 . "AcDbEntity")
(67 . 0) (8 . "0") (100 . "AcDbVertex") (100 . "AcDb3dPolylineVertex") (10
758.971 383.418 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 32) (50 . 0.0) (71
. 0) (72 . 0) (73 . 0) (74 . 0))
Command: (setq e3 (entget (entnext (cdr (car e2)))))
((-1 . ) (0 . "VERTEX") (5 . "27E") (100 . "AcDbEntity")
(67 . 0) (8 . "0") (100 . "AcDbVertex") (100 . "AcDb3dPolylineVertex") (10
257.549 377.344 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 32) (50 . 0.0) (71
. 0) (72 . 0) (73 . 0) (74 . 0))
Command: (setq e4 (entget (entnext (cdr (car e3)))))
((-1 . ) (0 . "VERTEX") (5 . "27F") (100 . "AcDbEntity")
(67 . 0) (8 . "0") (100 . "AcDbVertex") (100 . "AcDb3dPolylineVertex") (10
PolyLines and Blocks Page I
http://www.afralisp.com/lispa/lisp20.htm (1 of 5) [23/03/2005 05:45:06 p.m.]
391.774 521.633 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (70 . 32) (50 . 0.0) (71
. 0) (72 . 0) (73 . 0) (74 . 0))
Command: (setq e5 (entget (entnext (cdr (car e4)))))
((-1 . ) (0 . "SEQEND") (5 . "280") (100 . "AcDbEntity")
(67 . 0) (8 . "0") (-2 . ))
The (cdr (car e)) returns the entity name of entity list e. Each code segment then uses the (entnext entity name)
of the entity that precedes it.
Take note of the entity type of each variable :
e (0 . "POLYLINE")
e1 (0 . "VERTEX")
e2 (0 . "VERTEX")
e3 (0 . "VERTEX")
e4 (0 . "VERTEX")
e5 (0 . "SEQEND")
Do you see that a 3 line Polyline consists of a master or, parent list, 4 vertex and an end-of sequence
("SEQEND") list.
To extract the entitity list for each vertex is therefore, quite easy. We just need to loop through the sequence of
vertices until we reach the SEQEND list.
Here's an example of a function that will print the coordinates for each vertex of a Polyline :
(defun c:coord ( / e r)
(setq e (entget (car (entsel))))
;get the parent entity list
(setq r 1)
;set loop control number to 1
(while r
;while loop control is not nil, carry on looping
(setq e (entget (entnext (cdr (car e)))))
;get the vertex entity list
(if (/= (cdr (assoc 0 e)) "SEQEND")
;if it is not "end-of-sequence
(progn
;do the following
(terpri)
;new line
(princ (cdr (assoc 10 e)))
;print the co-ordinates

);progn
(setq r nil)
;if end of sequence, stop looping
);if
);while
(princ)
);defun
(princ)
There is a quicker way of retrieving the entity list of a Polyline vertex.
PolyLines and Blocks Page I
http://www.afralisp.com/lispa/lisp20.htm (2 of 5) [23/03/2005 05:45:06 p.m.]
(nentsel) let's you select an entity and returns the name of the entity even if it belongs to a polyline. Try this.
Type this, then select any vertex of a polyline.
(setq e (entget (car (nentsel))))
AutoLisp should return something like this :
Select object: ((-1 . ) (0 . "POLYLINE") (5 . "270") (100
. "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDb3dPolyline") (66 . 1) (10 0.0
0.0 0.0) (70 . 9) (40 . 0.0) (41 . 0.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73
. 0) (74 . 0) (75 . 0))
How's that? Straight to the entity list!!
Now, while we're here, let's have a quick look at blocks.....
Blocks.
Create a block consisting of a couple of lines and a circle with a radius of 20.
Now type this :
(setq e (entget (car (nentsel))))
Now pick the circle. AutoLisp should return something like this:
Select object: ((-1 . ) (0 . "CIRCLE") (5 . "282") (100 .
"AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbCircle") (10 0.0 -1.51849 0.0) (40
. 20.0) (210 0.0 0.0 1.0))
Hey, Hang about. It's returned the entity list of the circle even though it's part of a block!! Now type the
following:
(setq d (assoc 40 e))
(setq e1 (subst '(40 . 50.0) d e))
(entmod e1)
Now REGEN the drawing.
Did you noticed what happened? The radius of the circle has change even though it's part of a block. Not only
that, it has also redefined the block definition.
In other words, every block in the drawing with the same name would have changed.
I told you it was magic......
Let's change the layer of the circle:
(setq d (assoc 8 e1))
(setq e2 (subst '(8 . "STEEL") d e1))
(entmod e2)
Again, REGEN the drawing. The circle has changed to Layer "STEEL".
Now do you see what I mean by magic. I bet you never thought you would be able to modify a block without
exploding it. Well you can now.....
LwPolylines.
As we mentioned earlier, LwPolylines are a new feature in AutoCad Release 14.
They differ in that they are defined as a single entity. Let's have a look at a LwPolylines entity list.
Draw a LwPolyline and enter this:
(setq e (entget (car (entsel))))
AutoLisp should return something like this:
Select object: ((-1 . ) (0 . "LWPOLYLINE") (5 . "287")
(100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbPolyline") (90 . 3) (70 .
1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 597.908 661.3) (40 . 0.0) (41 . 0.0)
(42 . 0.0) (10 1179.86 476.045) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 479.39
397.084) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))
As you can see, there is no need to use (entnext) to step through the vertex entities as the group 10 entity code is
already part of the parent list.
But, we do have another problem!! There are numerous group 10 entity codes.
(As well as Group 40 - Start Width; Group 41 - End Width and Group 42 - Bulge)
To extract these, we need to first, find the length of the list. Then we must loop through each code entity in the
PolyLines and Blocks Page I
http://www.afralisp.com/lispa/lisp20.htm (3 of 5) [23/03/2005 05:45:06 p.m.]
list searching for a group 10. Once found, we can easily extract the vertex co-ordinates. The following function
does just that:
(defun c:lwcoord (/ e len n e1)
(setq e (entget (car (entsel))))
;get the entity list
(setq len (length e))
;get the length of the list
(setq n 0)
;set counter to zero
(repeat len
;repeat for the length of the entity list
(setq e1 (car (nth n e)))
;get each item in the entity list
;and strip the entity code number
(if (= e1 10)
;check for code 10 (vertex)
(progn
;if it's group 10 do the following
(terpri)
;new line
(princ (cdr (nth n e)))
;print the co-ordinates

);progn
);if
(setq n (1+ n))
;increment the counter
);repeat
(princ)
);defun
(princ)
Well, that's it concerning Polylines and Blocks. I told you it was easy!!!
Remember, I've only scratched the surface with the things that you can do once you dig into entity lists,
especially with complex entities.
One last thing. Want to create your own entity?
Normally, in AutoLisp you would draw a line like this:
(command "Line" pt1 pt2 "")
Now, create you own line by doing this:
(setq e '((0 . "LINE")(8 . "0")(10 50.0 50.0 0.0)(11 100.0 100.0 0.0)))
(entmake e)
Makes you think, doesn't it??
Cheers for now................

PolyLines and Blocks Page I


http://www.afralisp.com/lispa/lisp20.htm (4 of 5) [23/03/2005 05:45:06 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
PolyLines and Blocks Page I
http://www.afralisp.com/lispa/lisp20.htm (5 of 5) [23/03/2005 05:45:06 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Polyline Bulges - Part II
Given the two functions getPolySegs and getArcInfo we can now put together a command that inspects
all bulges in a polyline.
(defun C:POLYARCS (/ a polysegs seg)
;; make a list of polyline segments of a
;; selected polyline
(cond ((setq polysegs (getPolySegs))
;; a is just an informative counter
(setq a 0)
;; run thru each segment
(foreach seg polysegs
(setq a (1+ a))
;; only process the segment if it's an arc
;; i.e. bulge /= 0.0
(cond ((not (zerop (cadr seg)))
(princ (strcat "\nSegment " (itoa a) ": "))
;;
(getArcInfo seg)
)
)
)
)
)
)
Example:
Command: polyarcs
Select polyline:
Segment 2:
Included angle: 2.9932 rad (171.4974 degrees)
Height of arc: 1.1422
Chord length: 2.4605
Radius of arc: 1.2336
Center of arc: -9.4965,14.9290
Segment 4:
Included angle: 0.9844 rad (56.3997 degrees)
Height of arc: 0.4201
Chord length: 3.3447
Radius of arc: 3.5390
Center of arc: -5.8690,19.3390
Segment 5:
Included angle: 1.6177 rad (92.6872 degrees)
Height of arc: 0.5787
Chord length: 2.7043
Radius of arc: 1.8689
Center of arc: -2.1545,17.4054
This concludes the code for now. Below are some useful formulas for dealing with bulges. The picture
recaps some geometric details of the circular arc.
Polyline Bulges Page II
http://www.afralisp.com/lisp/Bulges2.htm (1 of 3) [23/03/2005 05:45:10 p.m.]
= (* 4.0 (atan bulge))
= (/ 2.0)
= (+ )
= (- (/ pi 2.0)(/ 4.0))
= (/ (- (* pi 2.0) ) 4.0)
= (- (/ pi 2.0)(atan bulge))
= (/ (- pi ) 2.0)
= (- (/ pi 2.0)(* 2.0 (atan bulge)))
= (atan (/ a c))
= (/ 4.0)
= (atan bulge)
= (atan (/ s c))
c = (distance p1 p2)
= (* 2.0 r (cos ))
= (* 2.0 r (sin (/ 2.0)))
s = (* (/ c 2.0) bulge)
a = (sqrt (- (expt r 2.0) (expt (/ c 2.0) 2.0)))
(* r (cos ))
r = (/ (+ (expt (/ c 2.0) 2.0)(expt s 2.0))(* 2.0 s))
= (/ s (* 2.0 (sin )(cos )))
= (/ a (cos ))
The center point is found in the code by calculating angles and distances in order to use POLAR. In
function getArcInfo are given two methods. One is calculating the apothem as a leg in the triangle
P-P2-P4 and setting out the center point from P4. The other is using the angle &gamma; and the radius
to set out the point from P1. Both methods have to read the sign of the bulge to know in which direction
the center point has to be set out.
Another method could be to view the arc as a part of the circumcircle to triangle P1-P2-P3. The medians
to the lines P1-P3 and P2-P3 intersect in the center point. We know the gradients for these medians
because both angles are known. E.g. any perpendicular to the line P1-P3 has the gradient (- (/ 1.0 gr)),
where gr is the gradient of P1-P3. Once having a point of the median (midpoint of P1-P3) and the grade,
it's possible to find the Y-interception and thereby the equation for the median. Doing this for both
medians we can use the following formulas for finding the intersection point - which is the center point
for the arc:
xi = - (m1 - m2)/(n1 - n2)
yi = m1 + n1*xi
where
m1 = gradient for median to P1-P3
n1 = Y-interception for median to P1-P3
m2 = gradient for median to P2-P3
n2 = Y-interception for median to P2-P3
There are many other solutions for finding the center point - among those some shorter trigonometric
methods - but this will have to do for now.
Because the geometry described by the 2 vertices and the bulge is relatively simple, there are many
other formulas than those depicted here. The important part is to understand how the bulge is defined
Polyline Bulges Page II
http://www.afralisp.com/lisp/Bulges2.htm (2 of 3) [23/03/2005 05:45:10 p.m.]
and how it relates to the only other two pieces of data given - the vertices. Hopefully this was able to
shed a light on some of the definitions.
For more information, refer to :
Unit Circle Definition of Sine and Cosine Functions
Page I

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Polyline Bulges Page II
http://www.afralisp.com/lisp/Bulges2.htm (3 of 3) [23/03/2005 05:45:10 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Unit Circle Definition of Sine and Cosine Functions
The trigonometric functions can be defined in terms of a unit circle, i.e. a circle of radius one.
The sin/cos Triangle
If the unit circle is placed at the origin of a rectangular coordinate system with the angle q measured
from the positive x-axis to the terminal side, then the point on the unit circle where the terminal side
intersects the unit circle is defined to be (cos q, sin q), i.e. the first coordinate of a point on the unit
circle is the cos q and the second coordinate is sin q.
The tan/sec Triangle
The tan q and sec q are defined by a triangle whose height is tangent to the unit circle at the point (1, 0)
and whose hypotenuse is on the terminal side of the angle.
The cot/csc Triangle
The cot q and csc q are defined by a triangle whose height is one and whose hypotenuse is on the
terminal side of the angle.
Unit Circle Definition of Sine and Cosine Functions
http://www.afralisp.com/lisp/bulge.htm (1 of 3) [23/03/2005 05:45:13 p.m.]
The sin/cos, tan/sec, and cot/csc Triangles
All three of the triangles used to define the trigonometric functions are shown in figure below.

Using the sin/cos, tan/sec, and cot/csc Triangles to Establish Basic Trigonometric
Identites
The three similar triangles sin/cos, tan/sec, and cot/csc are extracted from the figure. A fourth similar
triangle is shown with the adjacent, opposite, and hypotenuse sides labelled.
The definition of the six trigonometric functions and other useful identities follow from using the fact
that the ratio of corresponding sides of similar triangles must be the equal. The results are:
Unit Circle Definition of Sine and Cosine Functions
http://www.afralisp.com/lisp/bulge.htm (2 of 3) [23/03/2005 05:45:13 p.m.]
Using the sin/cos, tan/sec, and cot/csc Triangles to Determine the Pythagorean Idenities
The Pythagorean Theorem states: in any right-angled triangle, the sum of the squares of the lengths of
the sides containing the right angle is equal to the square of the hypothenuse. In short c
2
= a
2
+ b
2
.
Applying the Pythagorean Theorem to the sin/cos, tan/sec, and cot/csc triangles gives:

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Unit Circle Definition of Sine and Cosine Functions
http://www.afralisp.com/lisp/bulge.htm (3 of 3) [23/03/2005 05:45:13 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
ACCESSing AutoCAD
Written by Scott McGlynn - SMcGlynn@MCECo.com
Scott has been working with AutoCAD since 1985 (Release 2.15) and with Visual Basic since 1993.
He has worked for one of the larger electrical contractors in the US since 1994 as a Project Engineer. He
recently acquired a BS in Business Administration.
In regards to VB, he has been mostly self taught with a couple of classes here and there over
the years.
Microsoft Access is a simple relational database management system, RDBMS for short. Databases are
great for storing data. An excellent use of databases can be found in what I call a "Conduit and Cable
Schedule". Creating the Database is a whole topic unto itself and I will not go into a lot of detail about it,
however, I will describe what this Conduit andCable Schedule is all about. Following is a screen shot of
the "Relationships" view of the Database we will be referencing :
You will notice this is a large and rather complex database structure, but over the next few months, we
will be going through it step by step and breaking it down. The tables we will be using today include the
LOC, CAB, CON and DWG tables. The LOC table is a list of locations, the CAB, a list of Cables, the CON,
a list of Conduits and the DWG table, a list of drawings.
In large electrical projects, there are lots and lots of pieces of equipment that need power, have control
wires and other such interconnections. When designing the electrical distribution systems it is nice to
have a method of referencing those conduits and wires between these locations. For instance, a
Accessing AutoCAD
http://www.afralisp.com/vba/access.htm (1 of 6) [23/03/2005 05:45:16 p.m.]
particular Electrical panel might have 42 separate circuit breakers. Each one feeding a different pump.
As electrical contractors, we have to install conduit and wire to feed all of these pieces of equipment.
From a purely theoretical standpoint, every location in a job must be unique. We can't have two pumps
with the same name, no one would know which one we were referring to. By the same token, we can't
have two conduits with the same number. So, in the Access Database, we will have the CAB, CON and
LOC tables with indexes that prevent the generation of records with duplicate names.
Interfacing that Database with AutoCAD has been on my wish list for a few years, with the help of
Kenny Ramage and the rest of the gang here at Afralisp and Cad Encoding, I've gotten up the courage
to tackle just that. Ok, so let's begin.
Virtually Everything I do will be done from within Microsoft Access. The biggest question I have had to
ask myself is which application to write the code in. I could Write the application in Access and have
Access talk to AutoCAD, or I could write the code in AutoCAD and have AutoCAD talk to Access. I
chose the former over the latter for the simple reason that I have thousands and thousands of lines of
code written in Access to make the Conduit and Cable Schedule Work. I didn't really want to reinvent
the wheel, so there it is. Also, for compatibility issues, I am working in AutoCAD 2002 and Microsoft
Access 97. While there shouldn't be a big difference between versions, there may be.
My First step in this little shindig was to create a new class module to contain all of the code for the
AutoCAD interface. Once the new class is created, at the top, add the following lines of code :
Option Compare Database
Option Explicit
Private WithEvents objACAD As AcadApplication
Private objDoc As AcadDocument
Private Appexists As Boolean
The "Option Compare Database and the "Option Explicit" tell the Access App to first use the Database
default for comparing strings, etc and secondly to force the dimensioning of all variables.
That third line is a big one. It defines the interface for the AutoCAD Application. The "WithEvents"
keyword allows Access to generate Event Handlers for all of the Events AutoCAD exposes. For
instance, when a new drawing is opened, Access will know about it. The objDoc variable gives us a
direct reference to the Autocad Document which is a drawing. Finally, we define a boolean value for
internal use that makes sure the App Exists before we try to use it.
Please note, this is not an actual object, but a class. In order to create the object, we have to define an
object variable as this class and instantiate it. In the case of the Access Application, I have a global
variable called "objACAD" defined that is instantiated when the Access Application starts (it is
instantiated when a splash form comes up This allows any and all objects within the Application to
incorporate Autocad information into the data.)
When the class is instantiated, the "Class_Initialize" Event is executed. The code for this follows:
Private Sub Class_Initialize()
On Error Resume Next
Set objACAD = GetObject(, "Autocad.Application")
AppExists = True
If objACAD Is Nothing Then
Set objACAD = CreateObject("AutoCad.Application")
If objACAD Is Nothing Then Appexists = False

End If
IF AppExists Then Set objDoc = objACAD.ActiveDocument
End Sub
First we set up an Error handler, then we attempt to get a reference to any existing Autocad
Applications that might be running. IF that fails, we then try to create a new instance of AutoCAD. If that
fails, we then set Set our AppExists value to false. Finally, we set a reference to the Current Document.
Using an Exhaust Fan as an example, there are power conductors that go from a Motor Control Center
(MCC) to an Exhaust Fan Disconnect (EF-DISC). Then there are Power conductors to go from EF-DISC
to the Exhaust Fan (EF). Finally, there are control conductors that go from the MCC to a Processor
Panel (PP) that indicate if the EF is Running, Faulted, etc. Schematically, it would look like this :
Accessing AutoCAD
http://www.afralisp.com/vba/access.htm (2 of 6) [23/03/2005 05:45:16 p.m.]
Notice the cable numbers. This is a cable numbering system I have come up with that seems to work
reasonably well. Each cable is defined by the piece of equipment's name (in this case, EF). The second
part, the P01, P02, and C01 define the types of cables they are, Power, Control, Signal, Data,Fiberoptic,
etc. So, our Cable Table contains a list of all the Cable Names (each being unique). Now lets take a look
at this schematic from the point of view of construction. Below is a floor plan showing the location of
each of these pieces of equipment.
Notice there is more to this than just the equipment listed in the schematic. From a construction point
of view, I have an additional pull box located on the west well (north is up) The conduit goes from MCC
to PB-1 Then a conduit from PB-1 to EF-DISC. Finally, a conduit from EF-DISC to EF. Numbering the
conduits, we get the plan shown below Notice, the cable EFC01 is contained in both Conduit 1 and
Conduit 2.
Accessing AutoCAD
http://www.afralisp.com/vba/access.htm (3 of 6) [23/03/2005 05:45:16 p.m.]
Now that we have an idea of what the conduit and cable schedule will contain, lets take a look at
interfacing it with AutoCAD. Something that would be nice to have is an ability to select a location in the
database and have AutoCAD automatically open the drawing and zoom to the location. In pseudo code,
it would be something like:
Given a Selected Location in the Database,
Open Drawing Containing Location
Find Autocad Entity that is the location
Get Boudning Box of Entity
Zoom to bounding box
Complete.
Two important pieces of information are stored in the Location Table that will help in this endeavor.
First, is an index that is the Drawing, second is the Handle of the Entity in that Drawing.
How do we obtain those two pieces of information? . .Well, lets look at some pseudocode for that one:
Given a Selected Location in the Database,
1. Ask the user if the current Autocad Drawing is the one containing the entity that is the location
(is the polyline box representing PB-1 on the current drawing?)
G
2. If it is, leave the current drawing open, if not, allow the user to select the drawing required. G
3. Allow the user to select the entity that represents the location. G
4. Retrieve the drawing name and the handle G
5. Store information in the database. G
6. Complete. G
Accessing AutoCAD
http://www.afralisp.com/vba/access.htm (4 of 6) [23/03/2005 05:45:16 p.m.]
This is a screen shot of the "Location" Form. There are many fields in
this form that are of little consequence to us here. The fields we are
most concerned with are the Handle, DWGID and the button next to it
as well as the "Show Item" command button.
Lets take a look at the code behind the button next to the Handle Text
box.
Private Sub cmdGetHandle_Click()
Dim col As Collection
Dim ent As AcadEntity
Dim strDWG As String
Set col = objACAD.GetHandle
If col.Count = 0 Then Exit Sub
Set ent = col.Item(1)
txtHandle = ent.Handle
strDWG = ent.Document.Path & "\" & ent.Document.name
txtDWGID = FindDrawing("filename", strDWG).DWGID
End Sub
Similar to our pseudo code, we call a function from our ojbACAD class called GetHandle. Notice the
return value for the GetHandle Function is a Collection. In our current example, we only want one entity.
However, there are other uses for this function. Namely, when routing cables through conduits, I can
select all the conduits and pull boxes the cable goes through and the Database will be able to add the
cable to all of those items.
Public Function GetHandle() As Collection
Dim objDoc As Object
Dim col As Collection
Dim ob As AcadEntity
Dim str As String
Dim pt As Variant
Dim str As String
Dim fname As String
Set col = New Collection
If objACAD Is Nothing Then
MsgBox "Could Not Get Autocad Application"
Exit Function
End If
If objACAD.Documents.Count = 0 Then
str = GetFileName(CurrentDb.name, "Select File to Open")
If str = "" Then
Set GetHandle = Nothing
GoTo CleanUp
End If
Set objDoc = objACAD.Documents.Open(str)
End If
Do
On Error Resume Next
Set ob = Nothing
objDoc.Utility.GetEntity ob, pt, "Select the Enetity:"
If Err.number = 80020009 Then GoTo CleanUp
col.Add ob, ob.Handle
ob.Highlight True

Loop Until ob Is Nothing
CleanUp:
For Each ob In col
ob.Highlight False
str = str & ob.Handle & ", "
Next
str = Left$(str, Len(str) - 2)
Set GetHandle = col
Accessing AutoCAD
http://www.afralisp.com/vba/access.htm (5 of 6) [23/03/2005 05:45:16 p.m.]
Set col = Nothing
End Function
To Be Continued........

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Accessing AutoCAD
http://www.afralisp.com/vba/access.htm (6 of 6) [23/03/2005 05:45:16 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
File Functions in Visual Basic
Dir
One useful file function is the Dir$ function. This function works like the Dir command at an
MS-DOS command prompt. You can use the Dir$ function to retrieve a list of one or more
operating system files that match a file specification or path. A path can include the name of a
directory, a specific file name, or both. For example, C:/*.DWG is the path to all the files in the
root directory of drive C having a DWG extension. The syntax of the Dir$ function is as follows :
stringvar = Dir$(path[,attributes])

Finding Files
One use of the Dir$ function is to determine whether a file exists. If you try to open a database or
access a file that does not exist, an error occurs. However, you can use Dir$ first to check for a files
existence before opening it, as in the following example :
If Dir$("C:/MYFILE.DWG" = " " Then
Msgbox "The file was not found. Please try again!"
End If
The Dir$ function returns the filename without the full path if the specified file is found, or it
returns an empty string if no files were found. The preceding line of code displays a message box if
MYFILE.DWG does not exist in the root directory of drive C. If the file does exist, the string
"myfile.dwg" is returned. To make things even simpler, you can create a generic function that
returns a Boolean value "True" if the given file exists.
Public Function bFileExists (Sfile As String) As Boolean
If Dir$(sFile) <> " " Then
bFileExists = True
Else
bFileExists = False
End Function
This function could then be used to check any filename passed to the program by the user, as in the
following example :
Dim sUserFile As String
sUserFile = InputBox$("Enter the File Name : ")
If Not bFileExists(sUserFile) Then
MsgBox "The file does not exist. Please try again."
End
End If
File Functions in Visual Basic
http://www.afralisp.com/vba/files.htm (1 of 5) [23/03/2005 05:45:18 p.m.]
Notice that the code sample ends the program if the file does not exist, to prevent any errors that
might occur later. Another way to handle this situation would be to keep asking the user for a
filename until a valid filename is entered.
Listing Files and Folders
Another use of the Dir$ function is to return a list of files in the specified path. If you use the Dir
command at an MS DOS prompt, each matching file is listed
on the screen. However, because the Dir$ function is designed to return only a single string
variable, you have to use a loop and retrieve one filename at a time. (You can also display a list of
files with a file list box, which is one of Visual Basic's default controls.
Suppose that your C:/DRAWINGS directory contains several drawings with a DWG extension. The
path used to retrieve these files with the Dir$ function would be C:/DRAWINGS/*.DWG. You can
use the following lines of code to retrieve the filenames and add them to a list box :
sNextFile As String
sNextFile = Dir$("C:/DRAWINGS/*.DWG")
While sNextFile <> " "
lstDwgList.AddItem sNextFile
sNextFile = Dir$
Wend
In the preceding example, notice that only the file path to Dir$ is supplied on the first call. Each
subsequent call to Dir$ has no arguments, indicating that you want to use the previous file path and
move to the next filename in the list. When no more files match, Dir$ returns an empty string and
the "While" loop terminates.
Caution : When you use Dir$ in a loop, always exit the loop after an empty string is returned. If you
try to make another call to Dir$ with no arguments, a runtime error occurs.
The second, optional parameter of the Dir$ function is used to provide additional conditions
(beyond the specified path) with which to select files. For example, using the constant "vbDirectory"
returns only the subdirectories (or folders) in the specified path. The constant "vbVolume" causes
Dir$ to return the specified drive's volume label. The available constants are
summarized below :
Constant Value Purpose
vbNormal 0 (Default Value)
vbHidden 2 Include Hidden Files
vbSystem 4 Include System Files
vbVolume 8 Return Drive Volume Label
vbDirectory 16 Display SubDirectories
vbReadOnly 1 Include read-only files
Note : Constants can be added together if you want to use more than one. For example, the
following code finds the system, hidden and read only file IO.SYS on a machine :
debug.Print Dir$("C:/IO.SYS" , vbHidden+vbSystem+vbReadOnly)
Note that the "vbHidden" constant refers to a file's attributes and not the Windows Explorer option
that hides certain file types.
File Manipulation Functions
File Functions in Visual Basic
http://www.afralisp.com/vba/files.htm (2 of 5) [23/03/2005 05:45:18 p.m.]
As with the Dir$ function, most of the file manipulation commands in Visual Basic are as
straightforward as their MS-DOS equivalents, although with a few limitations. These commands
are summarised below :
Copy a File FileCopy source dest
Delete one or more Files Kill path
Rename a File Name oldname As newname
Create a Folder MkDir pathname
Remove an empty Folder RemDir pathname
Change current directory ChDir pathname
Change current drive ChDrive drive
Several of these functions are described in the following sections :
Copying Files
The "FileCopy" command has the limitation that you cannot use wildcards to
specify multiple files. "FileCopy" can copy files locally or over a network, as shown in the
following example :
'The following line copies a file while changing its name :
FileCopy "D:\DRAWING\TEST.DWG", "C:\BACKUP\TEST-BACK.DWG"
'The following lines of code use a network path for the source file :
Dim sDest As String
Dim sSource As String
sSource = "\\MYSERVER\DRAWINGS\TEST.DWG"
sDest = "C:\BACKUP\TEST-BACK.DWG"
FileCopy sSource, sDest
The "FileCopy" statement automatically overwrites an existing file, unless the
file is read-only or locked open by another application.
Deleting Files
Visual Basic also allows you to delete files by using the "Kill" statement. "Kill"
can use wildcards to specify multiple files, as in the following example :
Kill "D:\DRAWINGS\*.DWG"
Renaming Files
The "Name" statement is like the MS-DOS "RENAME" command but can be used on only one file
at a time "
Name oldname As newname
You can also use "Name" like the "MOVE" command in MS-DOS if the specified paths are
different :
'Moves the files to a new directory
MkDir "C:\BACKUP\TEST-BACK.DWG"
Name "D:\DRAWING\TEST.DWG" As "C:\BACKUP\TEST-BACK.DWG"
In the preceding example,note the "MkDir" statement, which you have probably guessed is used to
create a new directory. The "MkDir" and "RemDir" statements add and remove directories.
File Functions in Visual Basic
http://www.afralisp.com/vba/files.htm (3 of 5) [23/03/2005 05:45:18 p.m.]
Setting the Current Directory
In the examples discussed so far, the path has always included the drive and directory. However, as
you may recall from using MS-DOS, during the context of your MS-DOS session, you are always
"in" a certain directory, which is usually displayed to the left of the MS-DOS cursor. For example,
if you type CD \WINDOWS, you can rename, copy, or delete files within the WINDOWS directory
without specifying C:\WINDOWS in the pathname. The same concept of a "current directory"
applies to Visual Basic. By using the "ChDir" and "ChDrive" statements, you can set the current
working directory on each drive and switch between current drives, eliminating the need to specify
the full path for each file operation :
'Change to the desired directory and drive and rename file
ChDir "C:\DRAWINGS"
ChDrive "C:"
Name "TEST1.DWG" As "TEST2.DWG"
'Delete a file in the current directory
ChDrive "D:"
ChDir "D:\DRAWINGS"
Kill "OLDTEST.DWG"
Performing deletes can be dangerous if you don't know the current directory. Fortunately, Visual
Basic offers a function that provides this value: the "CurDir" function. The syntax of "CurDir" is :
stringvar = CurDir$([Drive])
Note - You can use the "Left$" function to get the current drive letter, as in the
following example :
sDriveLetter = Left$(CurDir$( ) , 1)
Okay, let's put this all together into a practical example.
Wouldn't it be nice to be able to backup all your drawings from your working
directory into a backup directory, either on another drive or to the network.
Have a look at this wee application, remembering to change the directory
paths to suit your own.
Open a new module and copy and paste this coding :
'VBA CODING STARTS HERE
Option Explicit
Sub Backup()
Dim sSourceDir As String
Dim sBackDir As String
Dim sNextFile As String
On Error GoTo FileCopyError
'Change these paths to suit.
sSourceDir = "C:\DRAWINGS\"
sBackDir = "D:\BACKUP\"
sNextFile = Dir$(sSourceDir & "*.DWG")
While sNextFile <> ""
FileCopy sSourceDir & sNextFile, sBackDir & sNextFile
sNextFile = Dir$
Wend
File Functions in Visual Basic
http://www.afralisp.com/vba/files.htm (4 of 5) [23/03/2005 05:45:18 p.m.]
MsgBox "Drawing Backup Complete. Have a Nice Day."
Exit Sub
FileCopyError:
MsgBox "There was a problem copying the Drawings"
End
End Sub
'VBA CODING ENDS HERE

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
File Functions in Visual Basic
http://www.afralisp.com/vba/files.htm (5 of 5) [23/03/2005 05:45:18 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Error Trapping
As you are writing your code, Visual Basic informs you of syntactical errors.
However, once the program is running, you may encounter unexpectedruntime errors in many circumstances.
For example, suppose you try to open a text file that the user has deleted.
When a compiled program has an error like this, an error message isdisplayed and the program ends.
Although you cannot predict and write code for every possible type of error,
"File Not Found" errors are fairly easy to handle. If you do not write code towork around the error, you can at
least provide a message that makes more sense before ending the program.
The "On Error" Statement
The most common way to handle error conditions is to use Visual Basic's"On Error" statement.The "On Error"
statement interrupts the normal flow of your program when
an error occurs and begins executing your error handling code. A typical
use is as follows :
On Error Goto FileOpenError
When this statement is executed, any errors that occur in subsequentstatements cause Visual Basic to stop normal
line-by-line execution andjump to the statement labeled as "FileOpenError".
Labeling Code Lines
Line labels in Visual Basic are similar to the line numbers of early BASIC.In Visual Basic, line labels can include
text if you want, but each label mustbe unique. They are followed by a colon (:), as in the following example :
Private Sub Form_Load ()
On Error Goto FileOpenError
Open "C:\SOMEFILE.TXT" For Unput As #1
Line Input #1, sData
Exit Sub
FileOpenError:
MsgBox "There was a problem opening the file. Stop for coffee!"
End
End Sub
In the preceding sample code, if the "Open" or "Line Input" statements causean error, the statements starting at
the label "FileOpenError" are executed,causing the message to be displayed and ending the program.
You should note a few points about the sample code. First, note the locationand style of the error handling routine.
It is usually placed near the end of thesubroutine, with the label not indented to indicate a special section of code.
Second, and more important, note the "Exit Sub" statement after the "Open" statement. It is necessary to prevent
the error handler routine from executingeven when the "Open" statement was successful.
Controlling Program Flow After an Error
In the preceding code example, you simply end the program if an error occurs.
However, you can handle the error in several (better) ways :
Exit the subroutine after informing the user of the error, and allow the program
to continue running with limited functionality.
G
Resume execution with the next statement following the error. G
Error Trapping in Visual Basic
http://www.afralisp.com/vba/error.htm (1 of 3) [23/03/2005 05:45:19 p.m.]
Provide a way for the user to correct the error and retry the offending statement. G
You can also have multiple labels within a procedure and set the current error handler
multiple times. For example, you can add a line to the code sample after the "Open"
statement that specifies a new label, "FileInputError". You can also turn off error
handling with the following statement :
On Error Goto 0
The "On Error" statement goes hand in hand with the "Resume" statement. For example, this statement causes
errors to be ignored and the program to proceed through each line of the code anyway :
On Error Resume Next
You should use the preceding line of code sparingly because it really just ignores
errors rather than handles them. A better use of "Resume" is to go to another section
of code. as in the following example :
Private Sub Form_Load ()
On Error Goto FileOpenError
RetryHere:
Open "C:\SOMEFILE.TXT" For Unput As #1
Line Input #1, sData
Exit Sub
FileOpenError:
Dim sMessage As String
sMessage = "There was a problem opening the file. " & VbCrLf
sMessage = sMessage & "Press Retry to try again, or Cancel to quit."
If MsgBox (sMessage, vbRetryCancel + vbCritical, "Error!") = vbRetry Then
Resume RetryHere
Else
End
End If
End Sub
You can though use "On Error Resume Next" if you are trying to connect to AutoCAD
from an external Visual Basic or other application :
'if error carry on with next line
On Error Resume Next
'set reference to AutoCAD Application
Set acadApp = GetObject(, "AutoCAD.Application.16")
'if there is an error (AutoCAD not open)
If Err Then
'clear the error
Err.Clear
'open AutoCAD
Set acadApp = CreateObject("Autocad.Application.16")
'setq reference to AutoCAD Application
Set acadApp = GetObject(, "AutoCAD.Application.16")
'if there is another error
If Err Then
'inform user
MsgBox Err.Description
'exit application
Exit Sub
Error Trapping in Visual Basic
http://www.afralisp.com/vba/error.htm (2 of 3) [23/03/2005 05:45:19 p.m.]
End If
End If
Next, set the document variable to the Document object in the AutoCADapplication. The Document object is
returned by the ActiveDocumentproperty of the Application object :
Dim ThisDrawing as AcadDocument
Set ThisDrawing = acadApp.ActiveDocument
From this point on, use the "ThisDrawing" variable to reference the current AutoCAD drawing just like AutoCAD
VBA.
Determining The Type of Error
After an error has occurred, your code can find out more information about the error in several ways :
Err - Contains a number that represents the error. G
Error - Contains a string describing the error. G
Err Object - Contains error number, description and additional information.
Also used to raise your own custom errors.
G
If you know how to recover from certain errors that may occur, you can use these
objects to respond intelligently to a specific error. In one of the previous examples, you received a "File Not
Found" error, which is number 53. You can easily add code
in the error handler to take appropriate action (that is, check another file) if the
value of "Err" is 53.
Hint : When you are writing an error handling routine with a message box, display the error number and
description in your message box to make troubleshooting easier.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Error Trapping in Visual Basic
http://www.afralisp.com/vba/error.htm (3 of 3) [23/03/2005 05:45:19 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA and Outlook.

This application will demonstrate how to connect AutoCAD and Outlook using VBA. It
will allow you to add a Task to Outlook along with a reminder time and a due time.
Special thanks to Randall Raath of VBDesign for this idea.
Here is the complete source coding :
Private Sub CommandButton1_Click()
UserForm1.Hide
AddTask
End Sub
Sub AddTask()
Dim appOutLook As Outlook.Application
Dim taskOutLook As Outlook.TaskItem
Dim Rem1 As Integer
Dim Due1 As Integer
Set appOutLook = CreateObject("Outlook.Application")
Set taskOutLook = appOutLook.CreateItem(olTaskItem)
Rem1 = (CInt(UserForm1.TextBox3.Text) * 60) _
+ CInt(UserForm1.TextBox5.Text)
Due1 = (CInt(UserForm1.TextBox4.Text) * 60) _
+ CInt(UserForm1.TextBox6.Text)
With taskOutLook
.Subject = UserForm1.TextBox1.Text
.Body = UserForm1.TextBox2.Text
.ReminderSet = True
VBA and Outlook
http://www.afralisp.com/vbaa/vba13.htm (1 of 2) [23/03/2005 05:45:21 p.m.]
.ReminderTime = DateAdd("n", Rem1, Now)
'set the reminder time
.DueDate = DateAdd("n", Due1, Now)
'set the due time
.ReminderPlaySound = True
.ReminderSoundFile = "C:\Windows\Media\Ding.WAV"
'Add the path to a .wav file on your computer.
.Save
End With
Set taskOutLook = Nothing
Set appOutLook = Nothing
End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub UserForm_Initialize()
UserForm1.TextBox1.SelStart = 0
UserForm1.TextBox1.SelLength = _
Len(UserForm1.TextBox1.Text)
End Sub
If you would like a copy of this module, just click here. Enjoy.......

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Outlook
http://www.afralisp.com/vbaa/vba13.htm (2 of 2) [23/03/2005 05:45:21 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA and Powerpoint.
This application will take a selected directory of drawings, convert them to WMF format
and insert them into Powerpoint as individual slide.
Usage :
Open the Powerpoint file dwg2slide.ppt.
Run the macro 'dwg2slide'.
Choose any file in the directory you wish to process.
Select 'O.K.' to proceed and sit back.
After a couple of minutes (depending on how many drawing files are in
the directory you choose), your slides will have been created.
Here is the coding for the entire application :
(Remember, this is written in Powerpoint VBA).
First create a module named Module1:
Public dirname As String
Sub Dwg2Slide()
Dim selname As String
Dim SelName1 As String
Dim InCounter As Integer
Dim InFoundpos As Integer
UserForm1.CommonDialog1.Filter = "dwg Files (*.dwg)|*.dwg"
'set default file type
UserForm1.CommonDialog1.Flags = cdlOFNHideReadOnly
'switch off read only
UserForm1.CommonDialog1.ShowOpen
'open dialog box
selname = UserForm1.CommonDialog1.filename
'retrieve the file name
InCounter = 1
'initilize counter
InFoundpos = InStr(InCounter, selname, "\")
'look for the \
While InFoundpos <> 0
'check for the last \
SelName1 = Mid$(selname, InCounter, InFoundpos - InCounter)
'extract the directory name

InCounter = InFoundpos + 1
'increase the counter
VBA and Powerpoint
http://www.afralisp.com/vbaa/vba12.htm (1 of 5) [23/03/2005 05:45:22 p.m.]

InFoundpos = InStr(InCounter, selname, "\")
'find the next \

dirname = dirname & SelName1 & "\"
'construct the path

Wend
UserForm1.Show
'show the dialog
End Sub
Next create a userform named Userform1. The following coding goes under the event procedures of
the userforms controls:
Private Sub CommandButton1_Click()
Dim filename As String
Dim sl As Integer
Dim acadApp As Object
Dim acadDoc As Object
Dim sset As Object
Dim pViewport As Object
'declare variables


Set acadApp = CreateObject("Autocad.Application")
'open AutoCAD
If Err Then
'if there is an error
MsgBox Err.Description
'inform user
Exit Sub
'exit application
End If
'End If
acadApp.Visible = True
'Make Autocad Visible
Set acadDoc = acadApp.ActiveDocument
'set reference to active document
Me.Hide
'Hide the dialogue box
filename = Dir(dirname, vbNormal)
'retrieve the first entry
Do While filename <> ""
VBA and Powerpoint
http://www.afralisp.com/vbaa/vba12.htm (2 of 5) [23/03/2005 05:45:22 p.m.]
'start the loop
If UCase(Right$(filename, 4)) = ".DWG" Then
'ignore files that do not end with .DWG
If (GetAttr(dirname & filename) And vbNormal) = vbNormal Then
'use bitwise comparison to make sure filename is not a directory
acadDoc.Open dirname & filename
'open drawing to purge
mylen = Len(filename)
'get the length of the filename
mylen = mylen - 4
'subtract the .DWG Extension
filename1 = Left(filename, mylen)
'retrieve the drawing name
Set pViewport = acadDoc.ActiveViewport
'set reference to the viewports
pViewport.ZoomExtents
'zoom to extents
Set sset = acadDoc.SelectionSets.Add("NEWSS")
'set reference to election set
sset.Select acSelectionSetAll
'select the whole drawing
acadDoc.Export dirname & filename1, "WMF", sset
'export the drawing
acadDoc.Save
'save the drawing
End If
End If
filename = Dir
'get the next entry
Loop
'carry on looping
acadApp.Quit
'Close Autocad
filename = Dir(dirname, vbNormal)
'retrieve the first entry
sl = 1
Do While filename <> ""
'start the loop
VBA and Powerpoint
http://www.afralisp.com/vbaa/vba12.htm (3 of 5) [23/03/2005 05:45:22 p.m.]
If UCase(Right$(filename, 4)) = ".WMF" Then
'ignore files that do not end with .WMF
If (GetAttr(dirname & filename) And vbNormal) = vbNormal Then
'use bitwise comparison to make sure filename is not a directory
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add _
(Index:=sl, Layout:=ppLayoutBlank).SlideIndex
'insert a new slide

ActiveWindow.Selection.SlideRange.Shapes.AddPicture _
(filename:=filename, LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=-2, Top:=58, Width:=727, _
Height:=423).Select
'import WMF File into slide

sl = 1 + sl
'increment the slide number

End If
End If
filename = Dir
'get the next entry
Loop
'carry on looping
MsgBox ("Process Complete.."), , "Drawings to Slide"
'inform user that we have finished
End
End Sub
Private Sub CommandButton2_Click()
End
End Sub
If you would like a copy of this module, just click here. Enjoy.......

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
VBA and Powerpoint
http://www.afralisp.com/vbaa/vba12.htm (4 of 5) [23/03/2005 05:45:22 p.m.]
Search
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Powerpoint
http://www.afralisp.com/vbaa/vba12.htm (5 of 5) [23/03/2005 05:45:22 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA Command Line Project.
As good as VBA is, there are still certain things that are difficult or just impossible to
achieve using VBA. For example, have you ever tried to Explode a block using VBA or
Load and Run an AutoLisp routine. Not easy is it?
The following code module sends a user defined string to the AutoCAD command line.
Theoretically, this means that you can run any AutoCAD command that you wish.
Copy and paste the following coding into a module in VBA and run any of the 4 sub- routines. The
four sub-routines available as examples are :
Zoome - This simply Zooms to the drawing extents. G
Xplode - Will explode a block. The block must be
the last item entered into the drawing.
G
DwfExport - This will export the current drawing as a DWF File. G
RunLisp - This will Load and Run an AutoLisp file. G
Thanks to Michael Hunter, ActiveCad, and Joe Sutphin for this Module and the idea. Sorry guys,
but it is to good not to spread around :-)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Declare Function GetForegroundWindow Lib "user32" () As Long
Public Const WM_COPYDATA = &H4A
Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As String
End Type
Public Sub SendToCommandPrompt(strMessage As String) Dim DataStruct As COPYDATASTRUCT
DataStruct.dwData = 1 DataStruct.lpData = strMessage DataStruct.cbData = Len(strMessage) + 2 AppActivate
ThisDrawing.Application.Caption SendMessage GetForegroundWindow, WM_COPYDATA, 0, DataStruct End
Sub
Sub xplode() SendToCommandPrompt "explode" & vbCr & "last" & vbCr & vbCr End Sub
Sub DwfExport() SendToCommandPrompt "DWFOUT" & vbCr & vbCr & "A" & vbCr & "YES" & vbCr End
Sub
Sub Zoome() SendToCommandPrompt "ZOOM" & vbCr & "EXTENTS" & vbCr End Sub
Sub RunLisp() SendToCommandPrompt "(Load ""ALispFile"")" & vbCr & "ALispFile" & vbCr End Sub
If you would like a copy of this module, just click here. Enjoy.......

VBA Command Line Project


http://www.afralisp.com/vbaa/vba11.htm (1 of 2) [23/03/2005 05:45:24 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Command Line Project
http://www.afralisp.com/vbaa/vba11.htm (2 of 2) [23/03/2005 05:45:24 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA Fax (23 Kb)
A lot of people now have E-Mail which makes the sharing of drawings a lot easier. But, not
everybody has got AutoCAD, so even if you E-Mail the drawing to them they still cannot open it.
You could fax it, but that has it's own problems.
Firstly, you must plot the drawing out to suit the size format of the fax machine,
or cut the drawing up into strips and fax it that way.
If you have a fax card and modem connected to your computer you can use a little bit of Visual
Basic to send the drawing to your fax.
First of all you need to set your fax as the default system printer.
Next, open AutoCAD and go to Preferences - Printers and set up a default system Printer. Finally,
open up the Fax VBA Application and change the Fax name to that of your Fax. That's it, you are
ready to Fax any drawing.
Here is the coding for the application :
Private Sub CommandButton1_Click()
ThisDrawing.Plot.PlotToDevice "WinFax"
'change the name of the Fax to suit

End Sub
Private Sub CommandButton2_Click()
End
End Sub
Thanks to Randall Rath of VBDesign for the idea for this project.....

VBA Fax
http://www.afralisp.com/vbaa/vba10.htm (1 of 2) [23/03/2005 05:45:26 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Fax
http://www.afralisp.com/vbaa/vba10.htm (2 of 2) [23/03/2005 05:45:26 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Timesheet Project (28 Kb)
This project demonstrates a method of extracting system variable data from AutoCAD and
importing it into Microsoft Excel.
The application calculates the length of time a user has spent in a drawing session and extracts this
data to a timesheet created in Excel. It then totals the daily drawing hours along with with the date,
the draughtsman's login name, the drawing number and the job number.
To use this VBA application, simply extract all of the files into your working
directory then load and run Timesheet.Lsp.
(If you have problems when writing or running this project, ensure that
the Microsoft Excel 8.0 Object Library is selected in your VBA References.)
After running the application, open the Excel file Timesheet.xls. You should have something
looking like this :
Timeshet Project
http://www.afralisp.com/vbaa/vba9.htm (1 of 5) [23/03/2005 05:45:28 p.m.]
Here is the source coding for this application.
Public ElapseTime As String
Public Dwgname As String
Public Username As String
'declare global variables
Private Sub CommandButton1_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim Colnum As Integer
Dim Rownum As Integer
Dim Currcell As Range
'declare local variables
Set xlbook = GetObject("Timesheet.xls")
'set reference to Excel file
Set xlapp = xlbook.Parent
'set reference to workbook
xlapp.Visible = True
'make Excel visible
xlapp.Windows("TIMESHEET.XLS").Visible = True
'make the workbook visible
'the 2 preceeding lines can be commented out if you
'do not want to see Excel in action
Set xlsheet = xlbook.Sheets("SHEET1")
'set reference to the worksheet Sheet1
Rownum = 10
'set initial row number
Timeshet Project
http://www.afralisp.com/vbaa/vba9.htm (2 of 5) [23/03/2005 05:45:28 p.m.]
Colnum = 3
'set initial column number
Set Currcell = xlsheet.Cells(Rownum, Colnum)
'position the current cell
Do While Currcell <> ""
'while the current cell is NOT empty
Rownum = Rownum + 1
'increase the row number by one

Set Currcell = xlsheet.Cells(Rownum, Colnum)
'reset the current cell

Loop
'carry on looping
xlsheet.Cells(Rownum, Colnum) = Format(ElapseTime, "h:m:s")
'enter the elapsed time
xlsheet.Cells(Rownum, (Colnum - 1)) = UCase(Dwgname)
'enter the drawing number
xlsheet.Cells(Rownum, (Colnum - 2)) = UCase(UserForm1.TextBox1.Text)
'enter the job number
xlsheet.Cells(5, 2) = UCase(Username)
'enter Login Name
xlsheet.Cells(3, 2) = Date
'enter the date
xlbook.Close savechanges:=True
'save the changes in Excel
xlapp.Quit
'quit Excel
Set xlsheet = Nothing
Set xlbook = Nothing
Set axlapp = Nothing
'clean up
UserForm1.Hide
'hide the dialog box
If Not ThisDrawing.Saved Then
'if the current drawing is not saved
If MsgBox(" OK to Save Drawing?", 4) = vbNo Then
'do nothing

Else
ThisDrawing.Save
'if Yes save the drawing

End If
Timeshet Project
http://www.afralisp.com/vbaa/vba9.htm (3 of 5) [23/03/2005 05:45:28 p.m.]
End If
ThisDrawing.Application.Quit
'close the drawing and exit AutoCAD
End Sub
Private Sub CommandButton2_Click()
End
'end the application
End Sub
Private Sub UserForm_Initialize()
ElapseTime = ThisDrawing.GetVariable("TDUSRTIMER")
'get the elapsed time
Dwgname = ThisDrawing.GetVariable("DWGNAME")
'get the drawing number
Username = ThisDrawing.GetVariable("LOGINNAME")
'get the login name
UserForm1.TextBox2.Text = UCase(Dwgname)
'display the drawing number
UserForm1.TextBox3.Text = Format(ElapseTime, "h:m:s")
'display the elapsed time
UserForm1.TextBox4.Text = UCase(Username)
'display the login name
UserForm1.TextBox5.Text = Date
'display the date
UserForm1.TextBox1.Text = "Job No"
'display a default Job No value
UserForm1.TextBox1.SetFocus
'set the focus to the Job No text box
UserForm1.TextBox1.SelStart = 0
'select the start of the text
UserForm1.TextBox1.SelLength = Len(UserForm1.TextBox1.Text)
'highlight the text
End Sub
You must also create a new module:
Sub timesheet ()
userform1.show
End Sub

Timeshet Project
http://www.afralisp.com/vbaa/vba9.htm (4 of 5) [23/03/2005 05:45:28 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Timeshet Project
http://www.afralisp.com/vbaa/vba9.htm (5 of 5) [23/03/2005 05:45:28 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Loading VBA Projects
When you load an AutoLisp file you just type (load "MYLISPFILE") and AutoCAD will find
the file and load it, as long as it is located within the AutoCAD search path.
Loading a VBA Project file though, is slightly different. AutoCAD will only search the
current working directory for the VBA file. The way to get around this, and to force
AutoCAD into searching the AutoCAD search path, is to use the "Findfile" function.
The following AutoLisp coding will load any VBA Project file that is within the AutoCAD
search path, run the Project and then unload it on completion.
Thanks to Randall Rath of VBDesign for this idea.
(defun c:ldvb ()
;define function
(setvar "CMDECHO" 0)
;switch off command echo
(if (findfile "yourproject.dvb")
;if the project file is found
;in your AutoCAD search path
(progn
;do the following
(setvar "FILEDIA" 0)
;switch off dialogue boxes
(command "_vbaload"
(findfile "yourproject.dvb"))
;load the project file
(command "-vbarun" "yourprojectmacro")
;run the project macro
(command "_vbaunload")
;unload the file
(setvar "FILEDIA" 1)
;switch dialogues back on
);progn
(princ "\nyourproject.dvb not found")
;if project not found, inform the user
);if
(setvar "CMDECHO" 1)
;switch command echo back on
(princ)
Loading VBA Projects
http://www.afralisp.com/vbaa/vba8.htm (1 of 2) [23/03/2005 05:45:30 p.m.]
;finish clean
);defun
(princ "\nyourproject.dvb Loaded")
;inform user
(princ "\nType 'Ldvb' to Run")
;tell him how to run it
(princ)
;load clean

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Loading VBA Projects
http://www.afralisp.com/vbaa/vba8.htm (2 of 2) [23/03/2005 05:45:30 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA and Excel (85 Kb)
This is a sample VBA routine written for AutoCAD Rel 14.
This application will demonstrate how to export data to Microsoft Excel, perform calculations on
that data and then re-import the results of the calculations back into AutoCAD.
Usage.
Unzip the files matlist.dvb, matlist.Lsp, matlist.Dwg and matlist.xls to your working directory.
Insert the matlist.Dwg. as a block into any drawing.
It should look like this :
Type (load "matlist") at the command prompt.
Type "matlist" to run the application.
(If you have problems when writing or running this projects, ensure that the Microsoft Excel 8.0
Object Library is selected in your VBA References.)
After running the application you can inspect the results of the exported data
in the file matlist.xls. It should look something like this:
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (1 of 7) [23/03/2005 05:45:32 p.m.]
The Source Code.
Public acad As Object
Public doc As Object
Public ms As Object
Public ss As Object
Public ssnew As Object
Public Theatts As Variant
Public MsgBoxResp As Integer
'declare global variables
Private Sub CommandButton1_Click()
UpdateAttrib 0, UserForm1.txt1.Text
UpdateAttrib 1, UserForm1.txt2.Text
UpdateAttrib 2, UserForm1.txt3.Text
UpdateAttrib 3, UserForm1.txt4.Text
UpdateAttrib 4, UserForm1.txt5.Text
UpdateAttrib 5, UserForm1.txt6.Text
UpdateAttrib 6, UserForm1.txt7.Text
UpdateAttrib 7, UserForm1.txt8.Text
UpdateAttrib 8, UserForm1.txt9.Text
UpdateAttrib 9, UserForm1.txt10.Text
UpdateAttrib 10, UserForm1.txt11.Text
UpdateAttrib 11, UserForm1.txt12.Text
UpdateAttrib 12, UserForm1.txt13.Text
UpdateAttrib 13, UserForm1.txt14.Text
UpdateAttrib 14, UserForm1.txt15.Text
UpdateAttrib 15, UserForm1.txt16.Text
UpdateAttrib 16, UserForm1.txt17.Text
UpdateAttrib 17, UserForm1.txt18.Text
UpdateAttrib 18, UserForm1.txt19.Text
UpdateAttrib 19, UserForm1.txt20.Text
UpdateAttrib 20, UserForm1.txt21.Text
UpdateAttrib 21, UserForm1.txt22.Text
UpdateAttrib 22, UserForm1.txt23.Text
UpdateAttrib 23, UserForm1.txt24.Text
UpdateAttrib 24, UserForm1.txt25.Text
UpdateAttrib 25, UserForm1.txt26.Text
UpdateAttrib 26, UserForm1.txt27.Text
UpdateAttrib 27, UserForm1.txt28.Text
UpdateAttrib 28, UserForm1.txt29.Text
UpdateAttrib 29, UserForm1.txt30.Text
UpdateAttrib 30, UserForm1.txt31.Text
UpdateAttrib 31, UserForm1.txt32.Text
UpdateAttrib 32, UserForm1.txt33.Text
UpdateAttrib 33, UserForm1.txt34.Text
UpdateAttrib 34, UserForm1.txt35.Text
UpdateAttrib 35, UserForm1.txt36.Text
'get the attribute values

ssnew.Item(0).Update
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (2 of 7) [23/03/2005 05:45:32 p.m.]
'update the attribute block

End
End Sub
Sub UpdateAttrib(TagNumber As Integer, BTextString As String)
'This Sub Procedure tests the attribute data to check
'that is not a null value

If BTextString = "" Then
'if the attribute is empty

Theatts(TagNumber).TextString = ""
'put a '-' place holder

Else
'if it is not empty

Theatts(TagNumber).TextString = BTextString
'use the attribute value

End If

End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub CommandButton3_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
'declare local variables
Set xlbook = GetObject("matlist.xls")
'set reference to Excel file
Set xlapp = xlbook.Parent
'set reference to workbook
xlapp.Visible = True
'make Excel visible
xlapp.Windows("MATLIST.XLS").Visible = True
'make the workbook visible
'the 2 preceeding lines can be commented out if you
'do not want to see Excel in action
Set xlsheet = xlbook.Sheets("SHEET1")
'set reference to the worksheet Sheet1
xlsheet.Cells(2, 1) = UserForm1.txt1.Text
xlsheet.Cells(3, 1) = UserForm1.txt8.Text
xlsheet.Cells(4, 1) = UserForm1.txt15.Text
xlsheet.Cells(5, 1) = UserForm1.txt22.Text
xlsheet.Cells(6, 1) = UserForm1.txt29.Text
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (3 of 7) [23/03/2005 05:45:32 p.m.]
xlsheet.Cells(2, 2) = UserForm1.txt2.Text
xlsheet.Cells(3, 2) = UserForm1.txt9.Text
xlsheet.Cells(4, 2) = UserForm1.txt16.Text
xlsheet.Cells(5, 2) = UserForm1.txt23.Text
xlsheet.Cells(6, 2) = UserForm1.txt30.Text
xlsheet.Cells(2, 3) = UserForm1.txt3.Text
xlsheet.Cells(3, 3) = UserForm1.txt10.Text
xlsheet.Cells(4, 3) = UserForm1.txt17.Text
xlsheet.Cells(5, 3) = UserForm1.txt24.Text
xlsheet.Cells(6, 3) = UserForm1.txt31.Text
xlsheet.Cells(2, 4) = UserForm1.txt4.Text
xlsheet.Cells(3, 4) = UserForm1.txt11.Text
xlsheet.Cells(4, 4) = UserForm1.txt18.Text
xlsheet.Cells(5, 4) = UserForm1.txt25.Text
xlsheet.Cells(6, 4) = UserForm1.txt32.Text
xlsheet.Cells(2, 5) = UserForm1.txt5.Text
xlsheet.Cells(3, 5) = UserForm1.txt12.Text
xlsheet.Cells(4, 5) = UserForm1.txt19.Text
xlsheet.Cells(5, 5) = UserForm1.txt26.Text
xlsheet.Cells(6, 5) = UserForm1.txt33.Text
xlsheet.Cells(2, 7) = UserForm1.txt7.Text
xlsheet.Cells(3, 7) = UserForm1.txt14.Text
xlsheet.Cells(4, 7) = UserForm1.txt21.Text
xlsheet.Cells(5, 7) = UserForm1.txt28.Text
xlsheet.Cells(6, 7) = UserForm1.txt35.Text
'fill the worksheet cells with the attribute values
UserForm1.txt6.Text = xlsheet.Cells(2, 6)
UserForm1.txt13.Text = xlsheet.Cells(3, 6)
UserForm1.txt20.Text = xlsheet.Cells(4, 6)
UserForm1.txt27.Text = xlsheet.Cells(5, 6)
UserForm1.txt34.Text = xlsheet.Cells(6, 6)
UserForm1.txt36.Text = xlsheet.Cells(7, 6)
'retrieve the calculated attribute values
xlbook.Close savechanges:=True
'save the changes in Excel
xlapp.Quit
'quit Excel
Set xlsheet = Nothing
Set xlbook = Nothing
Set axlapp = Nothing
'clean up
End Sub
Private Sub UserForm_Initialize()
Dim BlkG(0) As Integer
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
'declare local variables

Set acad = GetObject(, "AutoCAD.Application")
'set reference to AutoCAD
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (4 of 7) [23/03/2005 05:45:32 p.m.]

Set doc = acad.ActiveDocument
'set reference to the drawing

Set ms = doc.ModelSpace
'set reference to model space

Set ssnew = doc.SelectionSets.Add("TBLK")
'create a selection set

Pt1(0) = 0: Pt1(1) = 0: Pt1(2) = 0
Pt2(0) = 3: Pt2(1) = 3: Pt2(2) = 0
'set up the array

BlkG(0) = 2
'group code 2 for block name

TheBlock(0) = "MATLIST"
'the name of the attribute block

ssnew.Select 5, Pt1, Pt2, BlkG, TheBlock
'get the block

If ssnew.Count >= 1 Then
'if the block is found

Theatts = ssnew.Item(0).GetAttributes
'get the attributes

UserForm1.txt1.Text = UCase(LTrim(Theatts(0).TextString))
'get the title attribute
'clear any leading spaces and
'convert to uppercase

UserForm1.txt2.Text = UCase(LTrim(Theatts(1).TextString))
UserForm1.txt3.Text = UCase(LTrim(Theatts(2).TextString))
UserForm1.txt4.Text = UCase(LTrim(Theatts(3).TextString))
UserForm1.txt5.Text = UCase(LTrim(Theatts(4).TextString))
UserForm1.txt6.Text = UCase(LTrim(Theatts(5).TextString))
UserForm1.txt7.Text = UCase(LTrim(Theatts(6).TextString))
UserForm1.txt8.Text = UCase(LTrim(Theatts(7).TextString))
UserForm1.txt9.Text = UCase(LTrim(Theatts(8).TextString))
UserForm1.txt10.Text = UCase(LTrim(Theatts(9).TextString))
UserForm1.txt11.Text = UCase(LTrim(Theatts(10).TextString))
UserForm1.txt12.Text = UCase(LTrim(Theatts(11).TextString))
UserForm1.txt13.Text = UCase(LTrim(Theatts(12).TextString))
UserForm1.txt14.Text = UCase(LTrim(Theatts(13).TextString))
UserForm1.txt15.Text = UCase(LTrim(Theatts(14).TextString))
UserForm1.txt16.Text = UCase(LTrim(Theatts(15).TextString))
UserForm1.txt17.Text = UCase(LTrim(Theatts(16).TextString))
UserForm1.txt18.Text = UCase(LTrim(Theatts(17).TextString))
UserForm1.txt19.Text = UCase(LTrim(Theatts(18).TextString))
UserForm1.txt20.Text = UCase(LTrim(Theatts(19).TextString))
UserForm1.txt21.Text = UCase(LTrim(Theatts(20).TextString))
UserForm1.txt22.Text = UCase(LTrim(Theatts(21).TextString))
UserForm1.txt23.Text = UCase(LTrim(Theatts(22).TextString))
UserForm1.txt24.Text = UCase(LTrim(Theatts(23).TextString))
UserForm1.txt25.Text = UCase(LTrim(Theatts(24).TextString))
UserForm1.txt26.Text = UCase(LTrim(Theatts(25).TextString))
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (5 of 7) [23/03/2005 05:45:32 p.m.]
UserForm1.txt27.Text = UCase(LTrim(Theatts(26).TextString))
UserForm1.txt28.Text = UCase(LTrim(Theatts(27).TextString))
UserForm1.txt29.Text = UCase(LTrim(Theatts(28).TextString))
UserForm1.txt30.Text = UCase(LTrim(Theatts(29).TextString))
UserForm1.txt31.Text = UCase(LTrim(Theatts(30).TextString))
UserForm1.txt32.Text = UCase(LTrim(Theatts(31).TextString))
UserForm1.txt33.Text = UCase(LTrim(Theatts(32).TextString))
UserForm1.txt34.Text = UCase(LTrim(Theatts(33).TextString))
UserForm1.txt35.Text = UCase(LTrim(Theatts(34).TextString))
UserForm1.txt36.Text = UCase(LTrim(Theatts(35).TextString))

UserForm1.txt1.SetFocus
UserForm1.txt1.SelStart = 0
UserForm1.txt1.SelLength = Len(UserForm1.txt1.Text)
'set the focus to the drawing title and highlight it

Else
'if no attribute title block is found

MsgBox "Sorry - No Material List Attributes....", vbCritical, _
"AfraLisp Tutorial"
'inform the user that there is no attribute title block

ThisDrawing.SelectionSets("TBLK").Delete
End
'end the application

End If

ThisDrawing.SelectionSets("TBLK").Delete
End Sub

Now create a Module named Tblock :


Sub matlist()
UserForm1.Show
End Sub
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (6 of 7) [23/03/2005 05:45:32 p.m.]
Search
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and Excel
http://www.afralisp.com/vbaa/vba7.htm (7 of 7) [23/03/2005 05:45:32 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA and DataBases (67kb)
This is a sample VBA routine written for AutoCAD Rel 14, 2000, 2000i and 2002.
This application will demonstrate how to import and export Title Block attribute data, to and from an Access 2000
database.
Usage AutoCAD 14 and 2000.
Unzip the files Tblock2000.dvb, Tblock2000.Lsp, Tblock.Dwg and Tblock.Mdb to your working directory.
Insert the Tblock.Dwg. as a block into any drawing.
Usage AutoCAD 2000i and 2002.
Unzip the files Tblock2002.dvb, Tblock2002.Lsp, Tblock.Dwg and Tblock.Mdb to your working directory.
Insert the Tblock.Dwg. as a block into any drawing.
It should look like this :
Type (load "tblock2000(2)") at the command prompt.
Type "tblock2000(2)" to run the application.
(If you have problems when writing or running this projects, ensure that the Microsoft DAO 3.6 Object Library is
selected in your VBA References.)
The Source Code.
VBA and DataBases
http://www.afralisp.com/vbaa/vba6.htm (1 of 6) [23/03/2005 05:45:37 p.m.]
Public acad As Object
Public doc As Object
Public ms As Object
Public ss As Object
Public ssnew As Object
Public Theatts As Variant
Public MsgBoxResp As Integer
Public dbInfo As Database
Public rsInfo As Recordset
'declare global variables
Private Sub CommandButton1_Click()
UpdateAttrib 0, UserForm1.TextBox1.Text
UpdateAttrib 1, UserForm1.TextBox2.Text
UpdateAttrib 2, UserForm1.TextBox3.Text
UpdateAttrib 3, UserForm1.TextBox4.Text
UpdateAttrib 4, UserForm1.TextBox5.Text
'get the attribute values

ssnew.Item(0).Update
'update the attribute block

End
End Sub
Sub UpdateAttrib(TagNumber As Integer, BTextString As String)
'This Sub Procedure tests the attribute data to check
'that is not a null value

If BTextString = "" Then
'if the attribute is empty

Theatts(TagNumber).TextString = "-"
'put a '-' place holder

Else
'if it is not empty

Theatts(TagNumber).TextString = BTextString
'use the attribute value
ThisDrawing.SelectionSets.Item("TBLK").Delete
'delete the block

End If

End Sub
Private Sub CommandButton2_Click()
ThisDrawing.SelectionSets.Item("TBLK").Delete
End
End Sub
Private Sub CommandButton3_Click()
Dim DrgNumber As String
Dim Msg As String
Dim Msg1 As String
Dim Style As String
Dim TitleLine As String
VBA and DataBases
http://www.afralisp.com/vbaa/vba6.htm (2 of 6) [23/03/2005 05:45:37 p.m.]
Dim Response As String
'declare local variables
DrgNumber = UserForm1.TextBox2.Text
'get the drawing number
Set dbInfo = OpenDatabase("TBLOCK.MDB")
'set the reference to the database
'if the database is not an Access dadtabase use the following line
'Set dbInfo = OpenDatabase("
'C:\DATABASE PATH\", False, False, "dBASE III;C:\DATABASE PATH\TBLOCK.DBF;")
Set rsInfo = dbInfo.OpenRecordset("SELECT *
FROM TITLEBLOCK WHERE DRGNO = '" & DrgNumber & "'", dbOpenDynaset)
'search for the drawing number
UserForm1.Hide
'hide the dialogue box
If (rsInfo.RecordCount <> 0) Then
'if the drawing number is found
Msg = "Drawing already Exists in the DataBase."
Msg1 = "Would you like to Update the Drawing Details?"
Style = vbYesNo + vbQuestion + vbDefaultButton2
Title = "Existing Entry in DataBase"
'set variables for message box

Response = MsgBox(Msg & Chr(13) & Chr(10) & Msg1, Style, Title)
'display the message box

If Response = vbYes Then
'if the user wants to update the database

UserForm1.rsInfo.Edit
'open the database for edit
'-------------------
'this section is for AutoCAD 14/2000
UserForm1.rsInfo("TITLE") = UserForm1.TextBox1.Text
UserForm1.rsInfo("DRGNO") = UserForm1.TextBox2.Text
UserForm1.rsInfo("DATE") = UserForm1.TextBox3.Text
UserForm1.rsInfo("DRAWN") = UserForm1.TextBox4.Text
UserForm1.rsInfo("SCALE") = UserForm1.TextBox5.Text
'get the field values
'--------------------
'For AutoCAD 2000i/2002 replace the preceding section with this :
'UserForm1.rsInfo.Fields("TITLE") = UserForm1.TextBox1.Text
'UserForm1.rsInfo.Fields("DRGNO") = UserForm1.TextBox2.Text
'UserForm1.rsInfo.Fields("DATE") = UserForm1.TextBox3.Text
'UserForm1.rsInfo.Fields("DRAWN") = UserForm1.TextBox4.Text
'UserForm1.rsInfo.Fields("SCALE") = UserForm1.TextBox5.Text
'get the field values
'---------------------

UserForm1.rsInfo.Update
'update the database

MsgBox ("DataBase has been Updated"), , "Update DataBase"
'inform the user

VBA and DataBases
http://www.afralisp.com/vbaa/vba6.htm (3 of 6) [23/03/2005 05:45:37 p.m.]
UserForm1.Show
'reinstate the dialogue box

Else
'if the user does not want to update

UserForm1.Show
'reinstate the dialogue

End If
Else
'if the drawing number has not been found

Msg = "Drawing has not been Entered Into DataBase."
Msg1 = "Would you like to Enter the Drawing Details?"
Style = vbYesNo + vbQuestion + vbDefaultButton2
Title = "New Entry in DataBase"
'set up the message box variables

Response = MsgBox(Msg & Chr(13) & Chr(10) & Msg1, Style, Title)
'display the message box
If Response = vbYes Then
'if the user wants to enter the drawing details

UserForm1.rsInfo.AddNew
'open the dtabase to add a new record

'-------------------
'this section is for AutoCAD 14/2000
UserForm1.rsInfo("TITLE") = UserForm1.TextBox1.Text
UserForm1.rsInfo("DRGNO") = UserForm1.TextBox2.Text
UserForm1.rsInfo("DATE") = UserForm1.TextBox3.Text
UserForm1.rsInfo("DRAWN") = UserForm1.TextBox4.Text
UserForm1.rsInfo("SCALE") = UserForm1.TextBox5.Text
'get the field values
'--------------------
'For AutoCAD 2000i/2002 replace the preceding section with this :
'UserForm1.rsInfo.Fields("TITLE") = UserForm1.TextBox1.Text
'UserForm1.rsInfo.Fields("DRGNO") = UserForm1.TextBox2.Text
'UserForm1.rsInfo.Fields("DATE") = UserForm1.TextBox3.Text
'UserForm1.rsInfo.Fields("DRAWN") = UserForm1.TextBox4.Text
'UserForm1.rsInfo.Fields("SCALE") = UserForm1.TextBox5.Text
'get the field values
'---------------------

UserForm1.rsInfo.Update
'update the database

MsgBox ("Drawing has been Entered into DataBase"), ,
"Enter Into DataBase"
'inform the user

UserForm1.Show
'reinstate the dialogue box

Else
'if the user does not want to enter the drawing details

UserForm1.Show
'reinstate the dialoge box

End If
End If
VBA and DataBases
http://www.afralisp.com/vbaa/vba6.htm (4 of 6) [23/03/2005 05:45:37 p.m.]
End Sub
Private Sub UserForm_Initialize()
Dim BlkG(0) As Integer
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
'declare local variables

Set acad = GetObject(, "AutoCAD.Application")
'set reference to AutoCAD

Set doc = acad.ActiveDocument
'set reference to the drawing

Set ms = doc.ModelSpace
'set reference to model space

Set ssnew = doc.SelectionSets.Add("TBLK")
'create a selection set

Pt1(0) = 0: Pt1(1) = 0: Pt1(2) = 0
Pt2(0) = 3: Pt2(1) = 3: Pt2(2) = 0
'set up the array

BlkG(0) = 2
'group code 2 for block name

TheBlock(0) = "TBLOCK"
'the name of the attribute block

ssnew.Select 5, Pt1, Pt2, BlkG, TheBlock
'get the block

If ssnew.Count >= 1 Then
'if the block is found

Theatts = ssnew.Item(0).GetAttributes
'get the attributes

UserForm1.TextBox1.Text = UCase(LTrim(Theatts(0).TextString))
'get the title attribute
'clear any leading spaces and
'convert to uppercase


UserForm1.TextBox2.Text = UCase(LTrim(Theatts(1).TextString))
'get the drawing number attribute
'clear any leading spaces and
'convert to uppercase

UserForm1.TextBox3.Text = Date
'get todays date

UserForm1.TextBox4.Text = UCase(LTrim(Theatts(3).TextString))
'get the draughtsmans name
'clear any leading spaces and
'convert to uppercase

UserForm1.TextBox5.Text = "1:" & CStr(doc.GetVariable("DIMSCALE"))
'get the drawing scale, convert it to a string
VBA and DataBases
http://www.afralisp.com/vbaa/vba6.htm (5 of 6) [23/03/2005 05:45:37 p.m.]
'and prefix it with 1:


UserForm1.TextBox1.SetFocus
UserForm1.TextBox1.SelStart = 0
UserForm1.TextBox1.SelLength = Len(UserForm1.TextBox1.Text)
'set the focus to the drawing title and highlight it

Else
'if no attribute title block is found

MsgBox "Sorry - No Title Block Attributes....", vbCritical,
"AfraLisp Tutorial"
'inform the user that there is no attribute title block

End
'end the program

End If

End Sub
Create a new module and add this :
Sub TBlock()
UserForm1.Show
End Sub

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA and DataBases
http://www.afralisp.com/vbaa/vba6.htm (6 of 6) [23/03/2005 05:45:37 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
VBA Steel Project (28 Kb)
This is a sample VBA routine written for AutoCAD Rel 14.
This application will parametrically draw metric structural steel sections and is intended as an aid
towards a better understanding of VBA and AutoCAD.
Usage.
Unzip the files VbaSteel.dvb and VbaSteel.Lsp to any directory in your AutoCAD search path.
Type (load "vbasteel") at the command prompt.
Type "vbasteel" to run the application.
The Source Code.
Private Sub cmdCancel1_Click()
Me.Hide
UserForm2.Show
End Sub
Private Sub cmdOK1_Click()
Const PI = 3.141592654
'define PI as constant
Dim Height As Double
Dim Width As Double
Dim t1 As Double
Dim t2 As Double
Dim r1 As Double
Dim acadApp As Object
Dim acadDoc As Object
Dim acadUtil As Object
Dim inPnt As Variant
Dim North As Variant
Dim South As Variant
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (1 of 7) [23/03/2005 05:45:39 p.m.]
Dim West As Variant
Dim East As Variant
'declare variables
West = (PI * (180# / 180#))
'convert 180 degrees to radians
North = (PI * (90# / 180#))
'Convert 90 degrees to radians
East = 0
'convert 0 degrees to radians
South = (PI * (270# / 180#))
'convert 270 degrees to radians
NL = Chr(13) & Chr(10)
'define New Line
prompt1 = NL & "Insertion Point: "
'define prompt
Set acadApp = GetObject(, "AutoCAD.Application")
'get reference to AutoCAD
Set acadDoc = acadApp.ActiveDocument
'get reference to Drawing
Set acadUtil = acadDoc.Utility
'get reference to Utility Object
Me.Hide
'hide the dialogue
Select Case ListBox1.ListIndex
'use the select case function to retrieve
'section choosen in list box
Case 0
'if case index = 0
Height = 152.4
'set height

Width = 152.4
'set width

t1 = 6.1
'set web thickness

t2 = 6.8
'set flange thickness

r1 = 7.6
'set root radius

Case 1
Height = 157.5
Width = 152.9
t1 = 6.6
t2 = 6.4
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (2 of 7) [23/03/2005 05:45:39 p.m.]
r1 = 7.6
Case 2
Height = 161.8
Width = 154.4
t1 = 8.1
t2 = 11.5
r1 = 7.6
Case 3
Height = 203.2
Width = 203.2
t1 = 7.3
t2 = 11#
r1 = 10.2
Case 4
Height = 206.2
Width = 203.9
t1 = 8#
t2 = 12.5
r1 = 10.2
Case 5
Height = 209.6
Width = 205.2
t1 = 9.3
t2 = 14.2
r1 = 10.2
End Select
'end select case
inPnt = acadUtil.GetPoint(, prompt1)
'get the insertion point
Dim inPntv(0 To 2) As Double
'declare point variable
For i = 0 To 2
'convert x, y & z from variables to doubles
inPntv(i) = inPnt(i)
Next
Dim pt1 As Variant
'declare variants
pt1 = acadUtil.PolarPoint(inPntv, East, t1 / 2)
'use polar function to calculate point
Dim pt1v(0 To 2) As Double
For i = 0 To 2
pt1v(i) = pt1(i)
Next
Dim pt2 As Variant
pt2 = acadUtil.PolarPoint(pt1v, North, (Height - t2 - t2) / 2)
Dim pt2v(0 To 2) As Double
For i = 0 To 2
pt2v(i) = pt2(i)
Next
Dim pt2a As Variant
Dim pt2b As Variant
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (3 of 7) [23/03/2005 05:45:39 p.m.]
Dim pt3 As Variant
pt2a = acadUtil.PolarPoint(pt2v, South, r1)
pt2b = acadUtil.PolarPoint(pt2v, East, r1)
pt3 = acadUtil.PolarPoint(pt2v, East, (Width - t1) / 2)
Dim pt3v(0 To 2) As Double
For i = 0 To 2
pt3v(i) = pt3(i)
Next
Dim pt4 As Variant
pt4 = acadUtil.PolarPoint(pt3v, North, t2)
Dim pt4v(0 To 2) As Double
For i = 0 To 2
pt4v(i) = pt4(i)
Next
Dim pt5 As Variant
pt5 = acadUtil.PolarPoint(pt4v, West, Width)
Dim pt5v(0 To 2) As Double
For i = 0 To 2
pt5v(i) = pt5(i)
Next
Dim pt6 As Variant
pt6 = acadUtil.PolarPoint(pt5v, South, t2)
Dim pt6v(0 To 2) As Double
For i = 0 To 2
pt6v(i) = pt6(i)
Next
Dim pt7 As Variant
pt7 = acadUtil.PolarPoint(pt6v, East, (Width - t1) / 2)
Dim pt7v(0 To 2) As Double
For i = 0 To 2
pt7v(i) = pt7(i)
Next
Dim pt7a As Variant
Dim pt7b As Variant
Dim pt8 As Variant
pt7a = acadUtil.PolarPoint(pt7v, West, r1)
pt7b = acadUtil.PolarPoint(pt7v, South, r1)
pt8 = acadUtil.PolarPoint(pt7v, South, Height - t2 - t2)
Dim pt8v(0 To 2) As Double
For i = 0 To 2
pt8v(i) = pt8(i)
Next
Dim pt8a As Variant
Dim pt8b As Variant
Dim pt9 As Variant
pt8a = acadUtil.PolarPoint(pt8v, North, r1)
pt8b = acadUtil.PolarPoint(pt8v, West, r1)
pt9 = acadUtil.PolarPoint(pt8v, West, (Width - t1) / 2)
Dim pt9v(0 To 2) As Double
For i = 0 To 2
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (4 of 7) [23/03/2005 05:45:39 p.m.]
pt9v(i) = pt9(i)
Next
Dim pt10 As Variant
pt10 = acadUtil.PolarPoint(pt9v, South, t2)
Dim pt10v(0 To 2) As Double
For i = 0 To 2
pt10v(i) = pt10(i)
Next
Dim pt11 As Variant
pt11 = acadUtil.PolarPoint(pt10v, East, Width)
Dim pt11v(0 To 2) As Double
For i = 0 To 2
pt11v(i) = pt11(i)
Next
Dim pt12 As Variant
pt12 = acadUtil.PolarPoint(pt11v, North, t2)
Dim pt12v(0 To 2) As Double
For i = 0 To 2
pt12v(i) = pt12(i)
Next
Dim pt13 As Variant
pt13 = acadUtil.PolarPoint(pt12v, West, (Width - t1) / 2)
Dim pt13v(0 To 2) As Double
For i = 0 To 2
pt13v(i) = pt13(i)
Next
Dim pt13a As Variant
Dim pt13b As Variant
pt13a = acadUtil.PolarPoint(pt13v, East, r1)
pt13b = acadUtil.PolarPoint(pt13v, North, r1)
Dim moSpace As Object
'declare model space object
Set moSpace = acadDoc.ModelSpace
'get the model space object
Dim lwpolyObj As Object
'declare the light weight polyline object
Dim ptArray(0 To 35) As Double
'declare the array of doubles
ptArray(0) = pt1(0)
'set the array points
ptArray(1) = pt1(1)
ptArray(2) = pt2a(0)
ptArray(3) = pt2a(1)
ptArray(4) = pt2b(0)
ptArray(5) = pt2b(1)
ptArray(6) = pt3(0)
ptArray(7) = pt3(1)
ptArray(8) = pt4(0)
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (5 of 7) [23/03/2005 05:45:39 p.m.]
ptArray(9) = pt4(1)
ptArray(10) = pt5(0)
ptArray(11) = pt5(1)
ptArray(12) = pt6(0)
ptArray(13) = pt6(1)
ptArray(14) = pt7a(0)
ptArray(15) = pt7a(1)
ptArray(16) = pt7b(0)
ptArray(17) = pt7b(1)
ptArray(18) = pt8a(0)
ptArray(19) = pt8a(1)
ptArray(20) = pt8b(0)
ptArray(21) = pt8b(1)
ptArray(22) = pt9(0)
ptArray(23) = pt9(1)
ptArray(24) = pt10(0)
ptArray(25) = pt10(1)
ptArray(26) = pt11(0)
ptArray(27) = pt11(1)
ptArray(28) = pt12(0)
ptArray(29) = pt12(1)
ptArray(30) = pt13a(0)
ptArray(31) = pt13a(1)
ptArray(32) = pt13b(0)
ptArray(33) = pt13b(1)
ptArray(34) = pt1(0)
ptArray(35) = pt1(1)
Set lwpolyObj = moSpace.AddLightWeightPolyline(ptArray)
'draw the beam
Dim newBulge As Double
'declare the bulge (Radius)
newBulge = 0 - (Tan(1.570796327 / 4))
'Calculate the bulge (radius)
Call lwpolyObj.SetBulge(1, newBulge)
'radius vertice number 1
Call lwpolyObj.SetBulge(7, newBulge)
'radius vertice number 7
Call lwpolyObj.SetBulge(9, newBulge)
'radius vertice number 9
Call lwpolyObj.SetBulge(15, newBulge)
'radius vertice number 15
Rot = CDbl(Txb1.Text)
'get the rotation angle and convert
'to double
Rot1 = PI * (Rot / 180)
'convert to radians
Call lwpolyObj.Rotate(inPntv, Rot1)
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (6 of 7) [23/03/2005 05:45:39 p.m.]
'rotate the beam
End Sub
Private Sub ListBox1_Click()
Txb1.SetFocus
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
cmdOK1_Click
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
'add the beam sizes to the list box
ListBox1.AddItem "152x152x23"
ListBox1.AddItem "152x152x30"
ListBox1.AddItem "152x152x37"
ListBox1.AddItem "203x203x46"
ListBox1.AddItem "203x203x52"
ListBox1.AddItem "203x203x60"
ListBox1.ListIndex = 0
End Sub

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
VBA Steel Project
http://www.afralisp.com/vbaa/vba5.htm (7 of 7) [23/03/2005 05:45:39 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Drawing Setup Project (119 Kb)
This is a Drawing Setup Routine written in VBA for AutoCAD R14.
The user is given a choice of 4 Drawing Sheets, 5 Drawing Sizes, and a Drawing Scale Factor. All sizes
are Metric.
Usage.
Unzip the files to a temporary directory.
Copy all DWT (Drawing Template files) to the Template drawing sub-directory in you AutoCAD Rel
14 directory. (No files will be overwritten.)
Copy VbaSetup.dvb and VbaSetup.Lsp to any directory in your AutoCAD search path.
Type (load "vbasetup") at the command prompt.
Type "vbasetup" to run the application.
The Source Code.
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOk_Click()
Dim acadApp As Object
Dim acadDoc As Object
Dim templateFileName As String
Dim DrgSheet As String
Dim DrgSize As String
Dim newLimits(0 To 3) As Double
Dim pViewport As Object
Dim sc As Double
Dim oldTextStyle As Object
Dim Blockref As Object
Dim InsertionPoint(0 To 2) As Double
Drawing Setup Project
http://www.afralisp.com/vbaa/vba4.htm (1 of 5) [23/03/2005 05:45:41 p.m.]
Dim Mspace As Object
Dim Insertsheet As String
'declare variables
Me.Hide
'hide the dialogue box
Set acadApp = GetObject(, "AutoCAD.Application")
'setq reference to AutoCAD Application
If Err Then
'if there is another error
MsgBox Err.Description
'inform user
Exit Sub
'exit application
End If
Set acadDoc = acadApp.ActiveDocument
'set reference to active document
If Not acadDoc.Saved Then
'if the current drawing is not saved
If MsgBox(" OK to Save Drawing?", 4) = vbNo Then
'ask the user what he wants to do

End
'if No end application

Else
acadDoc.Save
'if Yes save the drawing

End If
End If
sc = CDbl(TextBox1.Text)
'get the scale and convert to double
If Opt1.Value = True Then
'if this button selected
DrgSheet = "E"
'set first letter of drawing sheet

templateFileName = "acadeng.dwt"
'set the relevant template file

Set doc = acadDoc.New(templateFileName)
'open new drawing with selected template file

End If
If Opt2.Value = True Then
Drawing Setup Project
http://www.afralisp.com/vbaa/vba4.htm (2 of 5) [23/03/2005 05:45:41 p.m.]
DrgSheet = "A"
templateFileName = "acadarch.dwt"
Set doc = acadDoc.New(templateFileName)
End If
If Opt3.Value = True Then
DrgSheet = "EL"
templateFileName = "acadelec.dwt"
Set doc = acadDoc.New(templateFileName)
End If
If Opt4.Value = True Then
DrgSheet = "B"
templateFileName = "acadblank.dwt"
Set doc = acadDoc.New(templateFileName)
End If
Select Case ListBox1.ListIndex
'get the item selected from list box
Case 0
'if the index is 0 (first item)
DrgSize = "A0"
'set the drawing size

newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 1189# * sc
newLimits(3) = 841# * sc
'set the limits

Set oldTextStyle = acadDoc.ActiveTextStyle
'get the current text style

Case 1
DrgSize = "A1"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 841# * sc
newLimits(3) = 594# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
Case 2
DrgSize = "A2"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 594# * sc
newLimits(3) = 420# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
Case 3
DrgSize = "A3"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 420# * sc
newLimits(3) = 297# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
Case 4
DrgSize = "A4"
newLimits(0) = 0#
newLimits(1) = 0#
Drawing Setup Project
http://www.afralisp.com/vbaa/vba4.htm (3 of 5) [23/03/2005 05:45:41 p.m.]
newLimits(2) = 297# * sc
newLimits(3) = 210# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
End Select
acadDoc.Limits = newLimits
'set drawing limits
Set pViewport = acadDoc.ActiveViewport
'get reference to viewports
pViewport.ZoomExtents
'zoom to extents
Call acadDoc.SetVariable("Ltscale", sc * 10)
'set Ltscale
Call acadDoc.SetVariable("Dimscale", sc)
'set Dimscale
Call acadDoc.SetVariable("Userr1", sc)
'store scale in Userr1 for later use
Call acadDoc.SetVariable("Regenmode", 1)
'set Regenmode
Call acadDoc.SetVariable("Tilemode", 1)
'set Tilemode
oldTextStyle.Height = 3.5 * sc
'set Text Height
Insertsheet = DrgSheet & DrgSize
'String Drawing Sheet Name Together
InsertionPoint(0) = 0
InsertionPoint(1) = 0
InsertionPoint(2) = 0
'set the insertion point
Set Mspace = acadDoc.ModelSpace
'get reference to Model Space
Set Blockref = Mspace.InsertBlock(InsertionPoint, Insertsheet, sc, sc, 0)
'Insert the drawing sheet
'MsgBox ("Drawing Setup Complete"), , "AfraLisp Drawing Setup"
End
End Sub
Private Sub ListBox1_Click()
TextBox1.SetFocus
End Sub
Drawing Setup Project
http://www.afralisp.com/vbaa/vba4.htm (4 of 5) [23/03/2005 05:45:41 p.m.]
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
cmdOk_Click
End Sub
Private Sub Opt1_Click()
TextBox1.SetFocus
End Sub
Private Sub Opt2_Click()
TextBox1.SetFocus
End Sub
Private Sub Opt3_Click()
TextBox1.SetFocus
End Sub
Private Sub Opt4_Click()
TextBox1.SetFocus
End Sub
Private Sub UserForm_Initialize()
ListBox1.AddItem "A0 - 1189 x 841"
ListBox1.AddItem "A1 - 841 x 594"
ListBox1.AddItem "A2 - 594 x 420"
ListBox1.AddItem "A3 - 420 x 297"
ListBox1.AddItem "A4 - 297 x 210"
ListBox1.ListIndex = 0
End Sub

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Drawing Setup Project
http://www.afralisp.com/vbaa/vba4.htm (5 of 5) [23/03/2005 05:45:41 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoLisp/VBA Drawing Setup
A well written drawing setup routine can save hours in any drawing office and is invaluable when it
comes to enforcing drawing office standards. There is nothing worse than a drawing office where
everybody "does there own thing" in regards to drawing setups. As well as this, a setup routine and
template drawings/drawing sheets can be given to third party companies to ensure that they comply
with your standards and specifications. This month we're going to have a look at a simple but powerful
setup routine first written in plain old AutoLisp and then written using the Dark Side - otherwise known
as VBA for the uninitiated. Let's have a look at the program in action :
Usage :
Select your Drawing Sheet type first,
then the Drawing Size, select a Scale
and then the OK button and away you
go.
To use your own drawing sheets in this
routine, please refer to the Readme file
which is included within the
downloadable drawing sheet zip file.
(The download link is at the bottom of
the next page - hey, we have to make
sure you read everything.)

This program not only inserts a chosen type and size of drawing sheet into your drawing, but also sets
your text height and dimension scaling to suit the scale factor.
You can even preset your own system variables within the program. Go for it, it's yours for ever and
ever to do with as you wish.
First the DCL coding.
Copy and paste this into Notepad and save it as "ALSetup.dcl."
//DCL CODING STARTS HERE
alsetup : dialog {
label = "CAD Encoding Drawing Setup";
: row {
: boxed_radio_column {
label = "Choose Sheet";
: radio_button {
label = "&Engineering Sheets";
key = "rb1";
value = "1";
}
: radio_button {
label = "&Architectural Sheets";
AutoLisp/VBA Drawing Setup Page I
http://www.afralisp.com/lisp/setup1.htm (1 of 5) [23/03/2005 05:45:45 p.m.]
key = "rb2";
}
: radio_button {
label = "&Electrical Sheets";
key = "rb4";
}
: radio_button {
label = "&Blank Sheets";
key = "rb5";
}
}
: boxed_radio_column {
label = "Choose Size :";
: radio_button {
label = "A&0 - 1189 x 841";
key = "rb6";
value = "1";
}
: radio_button {
label = "A&1 - 841 x 594";
key = "rb7";
}
: radio_button {
label = "A&2 - 594 x 420";
key = "rb8";
}
: radio_button {
label = "A&3 - 420 x 297";
key = "rb9";
}
: radio_button {
label = "A&4 - 297 x 210";
key = "rb10";
}
}
}
: edit_box {
label = "&Enter Drawing Scale :" ;
key = "eb1" ;
edit_width = 8 ;
}
:spacer { width = 1;}
ok_cancel ;
: paragraph {
: text_part {
label = "Designed and Created";
}
: text_part {
label = "by CAD Encoding";
}
AutoLisp/VBA Drawing Setup Page I
http://www.afralisp.com/lisp/setup1.htm (2 of 5) [23/03/2005 05:45:45 p.m.]
}
}
//DCL CODING ENDS HERE
And next, here's the AutoLisp coding. No Visual Lisp this time, just plain AutoLisp. ("Phew," I can hear a
lot of you saying, wiping your delicate brows in relief.)
Copy and paste this into Notepad and save it as "ALSetup.lsp."
;CODING STARTS HERE
(prompt "\nCAD Encoding Setup loaded - Type \"ALSETUP\" to run....")
(defun C:ALSETUP ( / userclick dcl_id siz typ x y l size n oldblip
oldecho oldsnap #dwgsc)
;save system settings
(setq oldblip (getvar "BLIPMODE")
oldecho (getvar "CMDECHO")
oldsnap (getvar "OSMODE")
);setq
;set system variables
(setvar "BLIPMODE" 0)
(setvar "CMDECHO" 0)
(setvar "OSMODE" 0)
;load the dialog
(setq dcl_id (load_dialog "alsetup.dcl"))
(if (not (new_dialog "alsetup" dcl_id))
(exit)
);if
;define default settings
(set_tile "rb1" "1")
(set_tile "rb6" "1")
(set_tile "eb1" "1")
(mtile)
(setq siz "A0")
(setq typ "e")
;define radio buttons action statements
(action_tile "rb1" "(setq typ \"e\") (mtile)")
(action_tile "rb2" "(setq typ \"a\") (mtile)")
(action_tile "rb4" "(setq typ \"el\") (mtile)")
(action_tile "rb5" "(setq typ \"b\") (mtile)")
(action_tile "rb6" "(setq siz \"A0\") (mtile)")
(action_tile "rb7" "(setq siz \"A1\") (mtile)")
(action_tile "rb8" "(setq siz \"A2\") (mtile)")
(action_tile "rb9" "(setq siz \"A3\") (mtile)")
(action_tile "rb10" "(setq siz \"A4\") (mtile)")
;define Cancel action statements
(action_tile "cancel"
AutoLisp/VBA Drawing Setup Page I
http://www.afralisp.com/lisp/setup1.htm (3 of 5) [23/03/2005 05:45:45 p.m.]
"(done_dialog)(setq userclick nil)")
;define OK action statements
(action_tile "accept"
(strcat
"(progn (setq #dwgsc (atof (get_tile \"eb1\")))"
"(done_dialog) (setq userclick T))"
);progn
)
;display the dialog
(start_dialog)
;unload the dialog
(unload_dialog dcl_id)
;check the flag setting
(if userclick
;if it's set, do the following
(progn
;set up the sheet size
(cond
((= siz "A0") (setq x 1189.0 y 841.0))
((= siz "A1") (setq x 841.0 y 594.0))
((= siz "A2") (setq x 594.0 y 420.0))
((= siz "A3") (setq x 420.0 y 297.0))
((= siz "A4") (setq x 297.0 y 210.0))
);cond

;Construct drawing sheet name
(setq size (strcat typ siz))
;set system variables according to scale
(setvar "DIMSCALE" #dwgsc)
(setvar "USERR1" #dwgsc)
(setvar "LTSCALE" (* #dwgsc 10))
(setvar "REGENMODE" 1)
(setvar "TILEMODE" 1)
(setq n (* 3.5 #dwgsc))
;define the limits list
(setq L (list (* x #dwgsc) (* y #dwgsc)))
;set up the drawing
(command "LIMITS" "0,0" L
"ZOOM" "W" "0,0" L
"STYLE" "italict" "italict" N "" "" "" "" ""
"INSERT" size "0,0" #dwgsc "" "" )
;inform the user
(prompt "\n ")
(prompt "\nOkay - Setup Routine Complete")

);progn
AutoLisp/VBA Drawing Setup Page I
http://www.afralisp.com/lisp/setup1.htm (4 of 5) [23/03/2005 05:45:45 p.m.]
);if
;reset system variables
(setvar "BLIPMODE" oldblip)
(setvar "CMDECHO" oldecho)
(setvar "OSMODE" oldsnap)
;finish clean
(princ)
);defun
;;;---------------------------
;function to set the focus to
;the scale edit box
(defun mtile ()
(mode_tile "eb1" 2)
);defun
;;;--------------------------
;load clean
(princ)
;CODING ENDS HERE
Store both files and the drawing sheet files in a directory within your AutoCAD search path. Now type
(load "ALSetup") at the AutoCAD command prompt, and then "ALSetup" to run the setup program.
On the next page we'll have a look at doing the same thing using VBA, but this time we'll make use of
drawing template files.
Home Page II

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoLisp/VBA Drawing Setup Page I
http://www.afralisp.com/lisp/setup1.htm (5 of 5) [23/03/2005 05:45:45 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoLisp/VBA Drawing Setup II
Welcome to the Dark Side!!
Just to be different, instead of using drawing files, this time we are going to use drawing template files within our
setup routine.
As well as that, just to show off, we are going to make our dialog a wee bit more colorful than the boring old
AutoLisp dialog. (eat your hearts out Lispers.)
Okay, here's a preview of what our dialog will look like on completion :
Usage :
Select your Drawing Sheet type first,
then the Drawing Size, select a Scale
and then the OK button and away you
go.
To use your own template drawings in
this routine, please refer to the Readme
file which is included within the
downloadable drawing sheet zip file.
(The download link is at the bottom of
this page )

As for the AutoLisp version, you can customise this program to your little hearts desire.
Right, let's have a look at a wee bit of coding. Fire up AutoCAD and open a new Project in the Visual Basic Editor.
First you need to insert a new UserForm keeping the default name. (UserForm1)
Now add the following controls, naming them as shown :
Button - "cmdOk" G
Button - "cmdCancel" G
Frame containing 4 Option Buttons - "Opt1", "Opt2", "Opt3" and "Opt4". G
Listbox - "Listbox1" G
Edit Box - "Textbox1" G
Now add the following coding under General Declarations :
Option Explicit
'------------------------------------------------
Private Sub cmdCancel_Click()
End
End Sub
'-------------------------------------------------
Private Sub cmdOk_Click()
'declare variables
Dim acadApp As Object
Dim acadDoc As Object
Dim doc As Object
Dim templateFileName As String
Dim DrgSheet As String
AutoLisp/VBA Drawing Setup Page II
http://www.afralisp.com/lisp/setup2.htm (1 of 5) [23/03/2005 05:45:47 p.m.]
Dim DrgSize As String
Dim newLimits(0 To 3) As Double
Dim sc As Double
Dim oldTextStyle As Object
Dim Blockref As Object
Dim InsertionPoint(0 To 2) As Double
Dim Mspace As Object
Dim Insertsheet As String
'hide the dialogue box
Me.Hide
'set a reference to the AutoCAD Application
Set acadApp = GetObject(, "AutoCAD.Application")
'if there is an error
If Err Then

'inform user
MsgBox Err.Description

'exit application
Exit Sub

End If
'set reference to active document
Set acadDoc = acadApp.ActiveDocument
'if the current drawing is not saved
If Not acadDoc.Saved Then
'ask the user what he wants to do
If MsgBox(" OK to Save Drawing?", 4) = vbNo Then

'if No end application
End

Else
'if Yes save the drawing
acadDoc.Save

End If
End If
'get the scale and convert to double
sc = CDbl(TextBox1.Text)
'if this button selected
If Opt1.Value = True Then
'set first letter of drawing sheet
DrgSheet = "E"

'set the relevant template file
templateFileName = "acadeng.dwt"

'open new drawing with selected template file
Set doc = acadDoc.New(templateFileName)

End If
AutoLisp/VBA Drawing Setup Page II
http://www.afralisp.com/lisp/setup2.htm (2 of 5) [23/03/2005 05:45:47 p.m.]
If Opt2.Value = True Then
DrgSheet = "A"
templateFileName = "acadarch.dwt"
Set doc = acadDoc.New(templateFileName)
End If
If Opt3.Value = True Then
DrgSheet = "EL"
templateFileName = "acadelec.dwt"
Set doc = acadDoc.New(templateFileName)
End If
If Opt4.Value = True Then
DrgSheet = "B"
templateFileName = "acadblank.dwt"
Set doc = acadDoc.New(templateFileName)
End If
'get the item selected from list box
Select Case ListBox1.ListIndex
'if the index is 0 (first item)
Case 0
'set the drawing size
DrgSize = "A0"

'set the limits
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 1189# * sc
newLimits(3) = 841# * sc

'get the current text style
Set oldTextStyle = acadDoc.ActiveTextStyle

Case 1
DrgSize = "A1"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 841# * sc
newLimits(3) = 594# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
Case 2
DrgSize = "A2"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 594# * sc
newLimits(3) = 420# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
Case 3
DrgSize = "A3"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 420# * sc
newLimits(3) = 297# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
Case 4
DrgSize = "A4"
newLimits(0) = 0#
newLimits(1) = 0#
newLimits(2) = 297# * sc
newLimits(3) = 210# * sc
Set oldTextStyle = acadDoc.ActiveTextStyle
AutoLisp/VBA Drawing Setup Page II
http://www.afralisp.com/lisp/setup2.htm (3 of 5) [23/03/2005 05:45:47 p.m.]
End Select
'set drawing limits
acadDoc.Limits = newLimits
'zoom to extents
ZoomExtents
'set Ltscale
Call acadDoc.SetVariable("Ltscale", sc * 10)
'set Dimscale
Call acadDoc.SetVariable("Dimscale", sc)
'store scale in Userr1 for later use
Call acadDoc.SetVariable("Userr1", sc)
'set Regenmode
Call acadDoc.SetVariable("Regenmode", 1)
'set Tilemode
Call acadDoc.SetVariable("Tilemode", 1)
'set Text Height
oldTextStyle.Height = 3.5 * sc
'String Drawing Sheet Name Together
Insertsheet = DrgSheet & DrgSize
'set the insertion point
InsertionPoint(0) = 0
InsertionPoint(1) = 0
InsertionPoint(2) = 0
'get reference to Model Space
Set Mspace = acadDoc.ModelSpace
'Insert the drawing sheet
Set Blockref = Mspace.InsertBlock(InsertionPoint, Insertsheet, sc, sc, sc, 0)
End
End Sub
'-------------------------------------------------
Private Sub ListBox1_Click()
TextBox1.SetFocus
End Sub
'--------------------------------------------------
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
cmdOk_Click
End Sub
'--------------------------------------------------
Private Sub Opt1_Click()
TextBox1.SetFocus
End Sub
'--------------------------------------------------
Private Sub Opt2_Click()
TextBox1.SetFocus
End Sub
AutoLisp/VBA Drawing Setup Page II
http://www.afralisp.com/lisp/setup2.htm (4 of 5) [23/03/2005 05:45:47 p.m.]
'--------------------------------------------------
Private Sub Opt3_Click()
TextBox1.SetFocus
End Sub
'--------------------------------------------------
Private Sub Opt4_Click()
TextBox1.SetFocus
End Sub
'--------------------------------------------------
Private Sub UserForm_Initialize()
'Populate the List Box
ListBox1.AddItem "A0 - 1189 x 841"
ListBox1.AddItem "A1 - 841 x 594"
ListBox1.AddItem "A2 - 594 x 420"
ListBox1.AddItem "A3 - 420 x 297"
ListBox1.AddItem "A4 - 297 x 210"
ListBox1.ListIndex = 0
End Sub
Next, you need to add a new Module.
Then add this coding :
Sub VbaSetup()
UserForm1.Show
End Sub
Save your project as "VbaSetup.dvb", then run the macro "VbaSetup."
The dialog should appear in all it's glory. Congratulations!
Quick, call your colleagues, call your boss, in fact, call all your friends and family to come and have a look and what
you've done. Who's a clever boy then? (sorry, or girl.)
To download the AutoLisp and VBA source coding, just click here.
To download the drawings sheets and template files, click here
Home Page I

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoLisp/VBA Drawing Setup Page II
http://www.afralisp.com/lisp/setup2.htm (5 of 5) [23/03/2005 05:45:47 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Utils (33 Kb)
Utils is a selection of Utility Functions written in VBA for use in Autocad Rel 14.
It consists of 3 Files :
CHL.DVB--Change Layer
CHLT.DVB-Change Linetype
CHC.DVB--Change Color
Along with them I have Included UTIL.LSP and UTIL.MNU
These 2 files provide the link between Autocad and VBA by providing a Toolbar to select a routine and a
lisp file that loads and runs the routine.
I have provided these files mainly to show what can be done using VBA and Autocad.
P.S.
Please ensure that all files are in a directory called c:\utils and that this directory is in you Autocad search
Path.
Source Code For Chl.Dvb
Dim ss As IAcadSelectionSet
Option Explicit

Private Sub CommandButton1_Click()
Dim Entity As Object
Me.Hide
Set ss = ThisDrawing.SelectionSets.Add("NEWSS")
ss.SelectOnScreen
For Each Entity In ss
Entity.Layer = lstLayers.Text
Next
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Utils
http://www.afralisp.com/vbaa/vba1.htm (1 of 3) [23/03/2005 05:45:51 p.m.]
Private Sub lstLayers_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim Entity As Object
Me.Hide
Set ss = ThisDrawing.SelectionSets.Add("NEWSS")
ss.SelectOnScreen
For Each Entity In ss
Entity.Layer = lstLayers.Text
Next
Unload Me
End Sub
Private Sub UserForm_Activate()
Dim AcadApp As Object
Dim AllLayers As Object
Dim Layer As Object
Set AcadApp = GetObject(, "AutoCAD.Application")
Set AllLayers = AcadApp.ActiveDocument.Layers
For Each Layer In AllLayers
lstLayers.AddItem Layer.Name
Next
End Sub
Source Code For Utils.Lsp
(prompt "\nPlease Wait...CadKen VBA Utilities Loading...")
(defun c:chl ()
(setvar "filedia" 0) ; disable all file dialog boxes
(command "_VBALOAD" "c:\\UTILS\\chl.dvb") ; load the VBA routine
(setvar "filedia" 1) ; enable all file dialog boxes
(command "_-VBARUN" "module1.ChangeLayer") ; run the defined macro
(princ) ; finish clean
) ; c:chl
(defun c:chlt ()
(setvar "filedia" 0)
(command "_VBALOAD" "c:\\UTILS\\chlt.dvb")
(setvar "filedia" 1)
(command "_-VBARUN" "module1.ChangeLineType")
(princ)
)
(defun c:chc ()
(setvar "filedia" 0)
(command "_VBALOAD" "c:\\UTILS\\chc.dvb")
(setvar "filedia" 1)
(command "_-VBARUN" "module1.ChangeColor")
(princ)
)
(princ)
Source Code For Utils.Mnu
***MENUGROUP=UTILS
***TOOLBARS
**UTILITIES
TB_Utility [_Toolbar("Utilities", _Floating, _Show, 0, 0, 1)]
TB_ChLayer [_Button("Change Layer", "chl.bmp", "ICON_32_BLANK")]^C^C^P+
(cond ((null C:UTILS) (prompt "Please Wait...")(load "UTILS"))) CHL
TB_ChLType [_Button("Change Line Type", "chlt.bmp", "ICON_32_BLANK")]^C^C^P+
(cond ((null C:UTILS) (prompt "Please Wait...")(load "UTILS"))) CHLT
Utils
http://www.afralisp.com/vbaa/vba1.htm (2 of 3) [23/03/2005 05:45:51 p.m.]
TB_ChColor [_Button("Change Color", "chc.bmp", "ICON_32_BLANK")]^C^C^P+
(cond ((null C:UTILS) (prompt "Please Wait...")(load "UTILS"))) CHC

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Utils
http://www.afralisp.com/vbaa/vba1.htm (3 of 3) [23/03/2005 05:45:51 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Drawing Layer Manager
This contribution is stolen from Frank Zander with his blessing.
Contract CADD Group - http://www.contractcaddgroup.com
This application is the perfect example of how something so simple can be so powerful. My immediate reaction on
reading this article and then running the coding was, "Why didn't I think of that?" I implemented it into my office
so quickly you wouldn't believe it.
Using VBA in AutoCAD R14 / 2000 to Control Layer Standards.
by Frank Zander
Introduction
Have you ever wondered why drawings can contain many layers, but objects such as "text",
"dimensions" and "hatch" do not always end up on the correct layers? This article addresses a
potential solution to that problem. First, I talk briefly about layer standards and show you how to create
a small VBA project for AutoCAD r14.01 or 2000 to control layers.
Layer Standards
Several times in the past, I have been asked by new users, "Why doesn't AutoCAD put text objects on
the text layer and hatch objects on a hatch layer, etc?" The answer is that Autodesk has designed
AutoCAD to give users unrestricted flexibility with layer names and to allow companies to create or
adopt any layer standard. Unfortunately, this flexibility of open-architecture layer names within
AutoCAD has allowed many an AutoCAD user to recklessly create layer names. Sometimes, it seems,
layer names are chosen according to what pops into the user's head while staring at the AutoCAD layer
dialogue box! And after several other users in the same company use these layer names, the results are
then called the "company layer standards".
There are many recognized layer standards in existence, such as AIA, Master Format, British BSD, etc.
that companies can adopt, but it seems to be more trendy for companies to make up their own layer
names and standards on the fly. The rationale seems to be "Those other existing layer standards could
not possibly accommodate the type of work that our company does. " How many times have you come
across a drawing (done by someone else, of course) containing layers called dim, dimension, and
dimensions? The purpose of this small VBA project is to create a mini layer-manager that enforces
layers for "text", "hatch" and "dimension" objects as they are created in a drawing. Text goes on to a
layer called "text", hatch patterns are placed on a layer called "hatch", and dimensions are placed on a
layer called "dim". Seems almost too obvious! Sure, this is a rather simplistic way of managing layers
for objects, but it works! For those interested in modifying the code to fit your own company layer
standard or for working with multiple disciplines, take a look at the section called "Extending the Code"
later in the article.
I was recently exposed to the "AcadDocument_BeginCommand" sub-program when I began a technical
review for WROX press of a book called AutoCAD - VBA Programmers Reference (currently being
written by Joe Sutphin). Joe's example code made me think, "Wow! I could apply his technique to do
some layer management of my own!" In the program outlined in this article, I access this sub-program
to check on the command being accessed by AutoCAD. Once the command being used is checked, it
creates the appropriate layer settings before AutoCAD starts the command. Therefore, when a user
enters the text command, my VBA program sets-up and/or creates the text layer, transparently in the
background, before the text command starts. The sub-program "AcadDocument_BeginCommand" picks
up on AutoCAD commands used in LISP programs and any alias (defined in the ACAD.pgp) that
references an AutoCAD command. For example, if a user types "BH" (standard short cut alias for the
"bhatch" command), the sub-program "AcadDocument_BeginCommand" still traps the "bhatch"
command.
The compliment to the "AcadDocument_BeginCommand" sub-program is the sub-program
"AcadDocument_EndCommand". I use the latter sub-program to check for the name of the command
that has just been completed. If the command name matches my criteria (using the "select case"
method), the layer is set back to the original layer in use before the command was started. Look at the
Drawing Layer Manager
http://www.afralisp.com/vbaa/drawman.htm (1 of 5) [23/03/2005 05:45:52 p.m.]
following commented code to see if you can follow what is happening inside the VBA program. Start
with the "AcadDocument_BeginCommand" sub-program and finish with the
"AcadDocument_EndCommand" sub-program.
Place this coding into a VBA Module and save it as DrawMan.dvb. Then add it to your startup suitcase.
' Using Option Explicit -- you must explicitly declare all variables using the
' Dim, Private, Public, ReDim, or Static statements.
' If you attempt to use an undeclared variable name,
' an error occurs at compile time.
' Option Explicit is a great way to make sure you do not have wonkie typo mistakes
' in your code.
Option Explicit
' set the public object current Layer to be an AutoCAD Layer
Public objCurrentLayer As AcadLayer
' set the public object Previous Layer to be an AutoCAD Layer
Public objPreviousLayer As AcadLayer
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
' Save the current / active AutoCAD layer
Set objPreviousLayer = ThisDrawing.ActiveLayer
' Check for the folowing cases of the AutoCAD command.
Select Case CommandName
' Check the AutoCAD command,
' is there a match for TEXT, MTEXT, or DTEXT
Case "TEXT", "MTEXT", "DTEXT" ' then do the following..
' check for to see if the current layer is Text
' if the current layer is not TEXT then set up the TEXT
' layer for use.
If Not ThisDrawing.ActiveLayer.Name = "4" Then
' set up the TEXT layer
' this layer will be created if it does not exist
Set objCurrentLayer = ThisDrawing.Layers.Add("4")
' make the TEXT layer blue
objCurrentLayer.Color = acCyan
' turn the TEXT layer ON
objCurrentLayer.LayerOn = True
' Thaw the TEXT layer
objCurrentLayer.Freeze = False
' Unlock the TEXT layer
Drawing Layer Manager
http://www.afralisp.com/vbaa/drawman.htm (2 of 5) [23/03/2005 05:45:52 p.m.]
objCurrentLayer.Lock = False
' Make the TEXT layer the current
' active layer in this drawing.
ThisDrawing.ActiveLayer = objCurrentLayer
' end of if checking for TEXT being the current layer.
End If
' Check the AutoCAD command,
' is there a match for HATCH, or the BHATCH command.
Case "HATCH", "BHATCH"
' check for to see if the current layer is HATCH
' if the current layer is not HATCH then set up the HATCH
' layer for use.
If Not ThisDrawing.ActiveLayer.Name = "8" Then
' set up the HATCH layer
Set objCurrentLayer = ThisDrawing.Layers.Add("8")
' make the HATCH layer red
objCurrentLayer.Color = 8
' turn the HATCH layer ON
objCurrentLayer.LayerOn = True
' Thaw the HATCH layer
objCurrentLayer.Freeze = False
' Unlock the HATCH layer
objCurrentLayer.Lock = False
' Make the HATCH layer the current
' active layer in this drawing.
ThisDrawing.ActiveLayer = objCurrentLayer
' end of if checking for HATCH being the current layer.
End If
' check for AutoCAD dimension commands..
Case "DIMALIGNED", "DIMANGULAR", "DIMCENTER", _
"DIMCONTINUE", "DIMDIAMETER", "DIMLINEAR", "LEADER", _
"DIMORDINATE", "DIMRADIUS", "DIM", "DIM1"
If Not ThisDrawing.ActiveLayer.Name = "4" Then
Set objCurrentLayer = ThisDrawing.Layers.Add("4")
objCurrentLayer.Color = acCyan
objCurrentLayer.LayerOn = True
objCurrentLayer.Freeze = False
Drawing Layer Manager
http://www.afralisp.com/vbaa/drawman.htm (3 of 5) [23/03/2005 05:45:52 p.m.]
objCurrentLayer.Lock = False
ThisDrawing.ActiveLayer = objCurrentLayer
' end of if checking for DIM being the current layer.
End If
' end of the Select
End Select
' end of Private Sub AcadDocument_BeginCommand
End Sub
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
' Check for the folowing cases of the AutoCAD command that has just ended.
Select Case CommandName
' check for a match on the following AutoCAD commands
Case "HATCH", "BHATCH", "TEXT", "MTEXT", "DTEXT", "DIMALIGNED", "DIMANGULAR",
"DIMCENTER", _
"DIMCONTINUE", "DIMDIAMETER", "DIMLINEAR", "LEADER", _
"DIMORDINATE", "DIMRADIUS", "DIM", "DIM1"
' make the current active AutoCAD layer the previously saved layer.
ThisDrawing.ActiveLayer = objPreviousLayer
' clear the objCurrentLayer
Set objPreviousLayer = Nothing
End Select
' clear the objCurrentLayer
Set objCurrentLayer = Nothing
' end Private Sub AcadDocument_EndCommand
End Sub
Would you like the coding for this routine? Then put one leg in the air,
close one eye, scream as loud as you can and click here. Enjoy.......

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Drawing Layer Manager
http://www.afralisp.com/vbaa/drawman.htm (4 of 5) [23/03/2005 05:45:52 p.m.]
Search
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Drawing Layer Manager
http://www.afralisp.com/vbaa/drawman.htm (5 of 5) [23/03/2005 05:45:52 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Save Manager
The Autosave feature in AutoCAD does not save the drawing you are working on, but saves a copy of your drawing
to a directory stored in the Savefilepath system variable. This drawing does not have the same name as your
drawing file and can be overwritten with subsequent Autosaves. Here's a little VBA application which I wrote that
will save your drawings at a user determined interval. (or very close.) It basically takes the time from the system
clock and stores it in one of the User system variables. Every time you select "Line," "Pline," or "Zoom," the
application checks to see if 15 minutes have passed. If it hasn't, it does nothing. If it has, it saves the drawing and
then resets the stored time to the system time. (Phew!)
Stick this coding in a module, save it as "SaveMan.dvb," and add it to your startup suitcase.
'<--Start Coding Here
Option Explicit
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
Dim OldTime
Dim NewTime
'trigger when user selects
Case "LINE", "PLINE", "ZOOM"
'get the time now
NewTime = (Hour(Time) * 60) + Minute(Time)
'get the time stored in USERI2
OldTime = ThisDrawing.GetVariable("Useri2")
'If the time has not been set
If OldTime = 0 Then
'set the time
ThisDrawing.SetVariable ("Useri2"), NewTime
'then end
End
End If
'if the difference is greater that 15 minutes
If (NewTime - OldTime) > 15 Then
'save the drawing
ThisDrawing.Save
'and then reset Useri2
ThisDrawing.SetVariable ("Useri2"), NewTime
End If
' end of the Select
End Select
Save Manager
http://www.afralisp.com/vbaa/saveman.htm (1 of 2) [23/03/2005 05:45:54 p.m.]
End
End Sub
'End Coding Here-->
If you wish, you can download the source coding here. (4Kb)
Sorry!! I mean Here. (4Kb)

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Save Manager
http://www.afralisp.com/vbaa/saveman.htm (2 of 2) [23/03/2005 05:45:54 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Attributes and VBA
You can find the AutoLisp equivalent to this application here.
When you want to edit attributes in AutoCAD most of us use the "Attedit" command. Firstly,
we must select the attribute we would like to edit. Then the "Edit Attribute" dialogue box
appears which allows us to add or change the values of our attribute. Personally, I think this
dialogue leaves a lot to be desired. You cannot customise it in any way, and it displays all
attributes whether you want them or not. As well, if you have a lot of attributes you need to
page your way through numerous dialogues before reaching the attribute you want to edit.
In this tutorial we are going to have a look at extracting attribute data from a block,
displaying the data in a custom dialogue box, and then updating the attribute data on exit.
Right, what do we need to do?
Find the block containing the attribute data. (Why select it when we can get AutoCAD
to find it for us.)
G
Extract the attribute data and display it in a dialogue box. G
Allow the user to change the data if he so wishes. G
Update the attribute data with the new information entered into the dialogue box. G
O.K. fire up AutoCAD and open the drawing Attab.dwg.
Alright, I admit that it's not much of a title block, but it's enough to give you the general idea.
Load run run the macro.
This dialogue should appear :
Change some of the data and then press the "OK" button.
The title block data should be updated. Clever hey?
Attributes and VBA
http://www.afralisp.com/vba/attabvba.htm (1 of 4) [23/03/2005 05:45:57 p.m.]
You can expand on this routine as much as you like using the following coding as a
template.
Hint : You don't have to display all the attribute data stored in a block. Only display what you
want the user to modify. As well, you can split your data over multiple dialogue boxes. eg.
One for title block, one for revisions, one for reference drawings, etc. All the data though is
contained in one attribute.
Here's the coding :
'CODING STARTS HERE
'All Tutorials and Code are provided "as-is" for purposes of instruction and
'utility and may be used by anyone for any purpose entirely at their own risk.
'Please respect the intellectual rights of others.
'All material provided here is unsupported and without warranty of any kind.
'No responsibility will be taken for any direct or indirect consequences
'resulting from or associated with the use of these Tutorials or Code.
'*******************************************************************************
' AfraLisp
' http://www.afralisp.com
' afralisp@afralisp.com
' afralisp@mweb.com.na
'*******************************************************************************
'This application will extract attributes from a block and display them in a
'dialog box. The attributes will then be updated.
Option Explicit
Public Tatts As Variant
Public ssnew As Object
Private Sub CommandButton1_Click()

'Update the attribute values
UpdateAttrib 0, UserForm1.TextBox1.Text
UpdateAttrib 1, UserForm1.TextBox2.Text
UpdateAttrib 2, UserForm1.TextBox3.Text
UpdateAttrib 3, UserForm1.TextBox4.Text
UpdateAttrib 4, UserForm1.TextBox5.Text

'update the block
ssnew.Item(0).Update

'delete the selection set
ThisDrawing.SelectionSets.Item("TBLK").Delete

End

End Sub
Private Sub CommandButton2_Click()
'delete the selection set
ThisDrawing.SelectionSets.Item("TBLK").Delete
End
End Sub
Private Sub UserForm_Initialize()
Attributes and VBA
http://www.afralisp.com/vba/attabvba.htm (2 of 4) [23/03/2005 05:45:57 p.m.]
Dim EntGrp(0) As Integer
Dim EntPrp(0) As Variant
Dim BlkObj As Object
Dim Pt1(0) As Double
Dim Pt2(0) As Double

'define error function
On Error GoTo Err_Control

'create a selection set
Set ssnew = ThisDrawing.SelectionSets.Add("TBLK")

'Filter for Group code 2, the block name
EntGrp(0) = 2

'The name of the block to filter for
EntPrp(0) = "attab-info"

'find the block
ssnew.Select acSelectionSetAll, Pt1, Pt2, EntGrp, EntPrp

'If a block is found
If ssnew.Count >= 1 Then

'Get the block's attributes
Tatts = ssnew.Item(0).GetAttributes

'display the attributes in the dialogue
UserForm1.TextBox1.Text = (LTrim(Tatts(0).TextString))
UserForm1.TextBox2.Text = (LTrim(Tatts(1).TextString))
UserForm1.TextBox3.Text = (LTrim(Tatts(2).TextString))
UserForm1.TextBox4.Text = (LTrim(Tatts(3).TextString))
UserForm1.TextBox5.Text = (LTrim(Tatts(4).TextString))

'set the focus to TextBox1 and highlight the text
UserForm1.TextBox1.SetFocus
UserForm1.TextBox1.SelStart = 0
UserForm1.TextBox1.SelLength = Len(UserForm1.TextBox1.Text)

Else
'no attribute block, inform the user
MsgBox "No Title Block Attributes - Use Manual Edit..", vbCritical, "AfraLisp Title Block"

'delete the selection set
ThisDrawing.SelectionSets.Item("TBLK").Delete

End

End If

Exit Sub

Err_Control:
'display error number and description
MsgBox Err.Number & " " & Err.Description

End

End Sub
Attributes and VBA
http://www.afralisp.com/vba/attabvba.htm (3 of 4) [23/03/2005 05:45:57 p.m.]
Sub UpdateAttrib(TagNumber As Integer, BTextString As String)

'This procedure checks to see if the text box has a value.
'If it does, it applies the text to the attribute.
'If not, it applies an empty string to the attribute.
If BTextString = "" Then

Tatts(TagNumber).TextString = ""

Else

Tatts(TagNumber).TextString = BTextString

End If

End Sub
'CODING ENDS HERE
OK, I know you can't type. Here's the coding.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Attributes and VBA
http://www.afralisp.com/vba/attabvba.htm (4 of 4) [23/03/2005 05:45:57 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Attributes and Dialog Boxes
You can find the VBA equivalent to this application here.
When you want to edit attributes in AutoCAD most of us use the "Attedit" command.
Firstly, we must select the attribute we would like to edit. Then the "Edit Attribute"
dialogue box appears which allows us to add or change the values of our attribute.
Personally, I think this dialogue leaves a lot to be desired. You cannot customise it in any
way, and it displays all attributes whether you want them or not. As well, if you have a lot
of attributes you need to page your way through numerous dialogues before reaching the
attribute you want to edit.
In this tutorial we are going to have a look at extracting attribute data from a block,
displaying the data in a custom dialogue box, and then updating the attribute data on
exit.
Right, what do we need to do?
1. Find the block containing the attribute data. (Why select it when we can get AutoCAD
to find it for us.)
2. Extract the attribute data and display it in a dialogue box.
3. Allow the user to change the data if he so wishes.
4. Update the attribute data with the new information entered into the dialogue box.
O.K. fire up AutoCAD and open the drawing Attab.dwg.
Alright, I admit that it's not much of a title block, but it's enough to give you the general
idea.
Now, at the command prompt type (load "Addat") and then enter.
Now, type "Addat" and press enter again.
This dialogue should appear :
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (1 of 8) [23/03/2005 05:45:59 p.m.]
Change some of the data and then press the "OK" button.
The title block data should be updated. Clever hey?
You can expand on this routine as much as you like using the following coding as a
template.
Hint : You don't have to display all the attribute data stored in a block. Only display what
you want the user to modify. As well, you can split your data over multiple dialogue
boxes. eg. One for title block, one for revisions, one for reference drawings, etc. All the
data though is contained in one attribute.
Here's the coding, DCL code first :
attab : dialog {
label = "Drawing Title Block";
: edit_box {
label = "&Drawing Number";
key = "eb1";
edit_width = 30;
}
: edit_box {
label = "&Revision";
key = "eb2";
edit_width = 30;
}
: edit_box {
label = "Drawn &By";
key = "eb3";
edit_width = 30;
}
: edit_box {
label = "D&ate";
key = "eb4";
edit_width = 30;
}
: edit_box {
label = "&Title";
key = "eb5";
edit_width = 30;
}
ok_cancel ;
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (2 of 8) [23/03/2005 05:45:59 p.m.]
:text_part {
label = "AfraLisp - http://www.afralisp.com";
}

}
And now the AutoLisp coding with plenty of in-line comments to assist you :
;CODING STARTS HERE
;
;All Tutorials and Code are provided "as-is" for purposes of instruction and
;utility and may be used by anyone for any purpose entirely at their own risk.
;Please respect the intellectual rights of others.
;All material provided here is unsupported and without warranty of any kind.
;No responsibility will be taken for any direct or indirect consequences
;resulting from or associated with the use of these Tutorials or Code.
;*******************************************************************************
; AfraLisp
; http://www.afralisp.com
; afralisp@afralisp.com
; afralisp@mweb.com.na
;*******************************************************************************
;This application will extract attributes from a block and display them in a
;dialog box. The attributes will then be updated. Attab.dcl and Attab.dwg are
;required and must be within the AutoCAD search path.
;
;Usage : Open Attab.dwg then load and run Attab.lsp.
;*******************************************************************************
(prompt "\nATTAB Loaded....Type ATTAB to run.....")
(defun c:attab (/)
;first find all the blocks with attributes in the drawing
(setq ss1 (ssget "X" '((0 . "INSERT")(66 . 1))))
;if there are blocks
(if ss1
;do the following
(progn
;set up the counter
(setq count 0
emax (sslength ss1)
)
;extract the block name
(while (< count emax)
(setq en (ssname ss1 count)
ed (entget en)
blkn (dxf 2 ed)
)
;check if it is our block
(if (= "attab-info" blkn)
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (3 of 8) [23/03/2005 05:45:59 p.m.]
;if it is, switch off the counter
;and set the found flag
(setq count emax
found T
)
;it's not our block, increment the counter
;and loop
(setq count (1+ count))
);if
);while
;if we find our block
(if found
;display the dialog
(ddisplay)
;cannot find our block
(alert
"\nDrawing Sheet has No Attributes
\n Use Manual Edit"
)
);if
);progn
;there are no blocks in the drawing
(alert
"\nIncorrect Drawing Sheet
\n Use Manual Edit"
)
);if
;finish clean
(princ)
);defun
;;;**********************************************************
(defun ddisplay (/)
;load the dialog
(setq dcl_id (load_dialog "attab.dcl"))
;check it exists
(if (not (new_dialog "attab" dcl_id))
(exit)
);if
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (4 of 8) [23/03/2005 05:45:59 p.m.]
;get the block entity data
(setq edata (entget en))
;get the first attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;get the drawing number
(setq eb1 (dxf 1 edata))
;get the second attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;get the revision
(setq eb2 (dxf 1 edata))
;get the third attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;get the name
(setq eb3 (dxf 1 edata))
;get the fourth attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;get the date
(setq eb4 (dxf 1 edata))
;get the fifth attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;get the title
(setq eb5 (dxf 1 edata))
;put the info into the dialog
(set_tile "eb1" eb1)
(set_tile "eb2" eb2)
(set_tile "eb3" eb3)
(set_tile "eb4" eb4)
(set_tile "eb5" eb5)
;set the focus to the drawing number
(mode_tile "eb1" 2)
;if cancel selected exit
(action_tile
"cancel"
"(done_dialog) (setq userclick nil)"
)
;if OK selected, retrieve the tile values
(action_tile
"accept"
(strcat
"(progn (setq eb1a (get_tile \"eb1\"))"
"(setq eb2a (get_tile \"eb2\"))"
"(setq eb3a (get_tile \"eb3\"))"
"(setq eb4a (get_tile \"eb4\"))"
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (5 of 8) [23/03/2005 05:45:59 p.m.]
"(setq eb5a (get_tile \"eb5\"))"
" (done_dialog)(setq userclick T))"
)
)
;start the dialog
(start_dialog)
;unload the dialog
(unload_dialog dcl_id)
;if OK was selected
(if userclick
(progn
;get the block entity data
(setq edata (entget en))
;get the first attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;change the list with the new values, if any
(setq el (subst (cons 1 eb1a) (assoc 1 edata) edata))
;update the attribute
(entmod el)
;get the second attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;change the list with the new values, if any
(setq el (subst (cons 1 eb2a) (assoc 1 edata) edata))
;update the attribute
(entmod el)
;get the third attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;change the list with the new values, if any
(setq el (subst (cons 1 eb3a) (assoc 1 edata) edata))
;update the attribute
(entmod el)
;get the fourth attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
;change the list with the new values, if any
(setq el (subst (cons 1 eb4a) (assoc 1 edata) edata))
;update the attribute
(entmod el)
;get the fifth attribute entity list
(setq edata (entget (entnext (dxf -1 edata))))
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (6 of 8) [23/03/2005 05:45:59 p.m.]
;change the list with the new values, if any
(setq el (subst (cons 1 eb5a) (assoc 1 edata) edata))
;update the attribute
(entmod el)
;regen the drawing
(command "REGEN")
);progn
);if
(princ)
);defun
;;;***********************************************************

(defun dxf (code elist)
(cdr (assoc code elist))
);defun
;;;**********************************************************
;load clean
(princ)
;;;**********************************************************
;
;CODING ENDS HERE
Please note that there is no error checking in this routine and I have left all variables as
global to assist you in checking their values whilst you are analyzing the code.
If you are too lazy to type, and don't know how to copy and paste, you can download the
coding and sample drawing by very gently placing your cursor here and clicking once.
"Ouch, I did say gentle!!!!

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (7 of 8) [23/03/2005 05:45:59 p.m.]
Search
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Attributes and Dialog Boxes
http://www.afralisp.com/lisp/attab.htm (8 of 8) [23/03/2005 05:45:59 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoCAD and HTML
This article first appeared in the September 2002 issue of "CAD Encoding."
In this article, we are going to have a look at extracting information from AutoCAD and displaying the
results in an HTML file.
Just to be clever, and to keep everybody happy, we'll be writing the coding using VBA, AutoLisp, Visual
Lisp and last but not least VB. Each of the routines will be slightly different to give you an idea of the
capabilities of each language.
Let's have a look at VBA first.
This wee routine will extract all the layer names contained within a drawing, create an HTML file on the
fly, and list all the layer names :
Insert a Userform and add a listbox and two buttons, retaining their default names :
UserForm1 G
ListBox1 G
CommandButton1 G
Commandbutton2 G
Add the following coding to the General Declarations section :
(I recommend you download the source coding for this project as word-wrapping can cause major
problems. The download link is at the end of Page IV.)
Option Explicit
'-----------------------------------------------------
Public AllLayers As AcadLayers
'-----------------------------------------------------
Private Sub CommandButton1_Click()
Dim nFile As Integer
Dim Layer As AcadLayer
Dim dName As String
Dim mylen As Integer
Dim dPrefix As String
'if there is an error
Cad Encoding - Layers to HTML
http://www.afralisp.com/lisp/html1.htm (1 of 4) [23/03/2005 05:46:05 p.m.]
On Error GoTo Err_Control
'hide the dialog
Me.hide
'get the drawing name
dName = ThisDrawing.GetVariable("DWGNAME")
'get the drawing name
dPrefix = ThisDrawing.GetVariable("DWGPREFIX")
'get the length of the filename
mylen = Len(dName)
'subtract the .DWG Extension
mylen = mylen - 4
'retrieve the drawing name
dName = Left(dName, mylen)
'get the next free file number
nFile = FreeFile
'open the html file to write to
Open dPrefix & dName & " - AllLayers.htm" _
For Output As #nFile
'write the header
Print #nFile, "<html><head><title> _
Cad Encoding - Layers to HTML</title></head>
<body><h3>Layers - Drawing No : " & dPrefix & _
dName & "</h3><hr>"
'process each layer
For Each Layer In AllLayers
'write to the HTML file
Print #nFile, "Layer Name = " & Layer.Name & "<p>"
'process next layer
Next
'write the footer
Print #nFile, "<hr><h3>Created by CAD Encoding</h3> _
</body></html>"
'close the file
Close #nFile
'display message box
MsgBox ("Layers written to HTML File :" & vbCr & _
dPrefix & dName &" - AllLayers.htm"), , "Layers to HTML"
'error control
Exit_Here:
Exit Sub
Err_Control:
MsgBox Err.Description
Cad Encoding - Layers to HTML
http://www.afralisp.com/lisp/html1.htm (2 of 4) [23/03/2005 05:46:05 p.m.]
Resume Exit_Here

End Sub
'----------------------------------------------------
Private Sub CommandButton2_Click()
End
End Sub
'---------------------------------------------------
Private Sub UserForm_Initialize()
Dim Layer As AcadLayer
'if there is an error
On Error GoTo Err_Control
'get the layers collection
Set AllLayers = ThisDrawing.Layers
'process each layer
For Each Layer In AllLayers
'display each layer name in the list box
ListBox1.AddItem Layer.Name

'process next layer
Next

'error control
Exit_Here:
Exit Sub

Err_Control:
MsgBox Err.Description
Resume Exit_Here

End Sub
Now insert a new Module and add this :
Sub AllLayers()
UserForm1.Show
End Sub
Save this as "AllLayers.dvb."
Now open any drawing and run the macro.
The List Box should be populated with the drawings Layer names.
Select the "HTML" button. A dialog should appear informing you that an HTML file has been created.
Navigate to the directory containing the HTML file and open it.
A list of all the Layers in your drawing should have been created.
On the next page we'll have a look at something similar, but this time using AutoLisp.
Cad Encoding - Layers to HTML
http://www.afralisp.com/lisp/html1.htm (3 of 4) [23/03/2005 05:46:05 p.m.]
Home Page II Page III Page IV

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Cad Encoding - Layers to HTML
http://www.afralisp.com/lisp/html1.htm (4 of 4) [23/03/2005 05:46:05 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoCAD and HTML - Page II
This time we're going to have a look at creating an HTML file that lists a directory of DWF drawings
using AutoLisp. To select the DWF files and the relevant directory, we are going to make use of a very
powerful DosLib function "dos_filem." Oh, before I forget, you will need to have the DosLib library
installed on your workstation. If you don't have DosLib, you can download the latest version from
Robert McNeel & Associates.
I'd like to thank Andy Canfield(Cornbread) for his ideas and input into this routine. Andy wrote about
90% of this program and in fact, gave me the initial idea for this article. I've changed a couple of things
and tidied it up for publishing, but Andy did the major work. Any errors or typos are from my desk.
Right, enough waffle, lets get on with it. Copy and paste this into Notepad and then save it as
"Dwf-Html.lsp."
(defun C:Dwf-Html ( / flag thelist thedir nfiles thefile fn ctr dname)
;set the flag
(setq flag T)
;check Doslib is loaded
(if (not (member "doslib2k.arx" (arx)))
(progn
(if (findfile "doslib2k.arx")
(arxload "doslib2k")
(progn
(alert "DosLib not installed")
(setq flag nil)
);progn
);if
);progn
);if
;if DosLib is installed and loaded
(if flag
;do the following
(progn
;select the DWF files
(setq thelist (dos_getfilem "Select Drawings"
"C:\\" "DWF Files (*.dwf)|*.dwf"))
;retrieve the directory
(setq thedir (car thelist))
;retrieve the file names
(setq thelist (cdr thelist))
;get the number of files
(setq nfiles (length thelist))
;create the HTML file
AutoCAD and HTML - Page II
http://www.afralisp.com/lisp/html2.htm (1 of 3) [23/03/2005 05:46:06 p.m.]
(setq thefile (strcat thedir "Dwf-Html.html"))
;open the HTML file
(setq fn (open thefile "w"))
;write the header information
(write-line "<html><head>
<title>AutoCAD and HTML</title>
</head><body>" fn)
;give it a title
(write-line "<h1>AutoCAD and HTML</h1><hr>" fn)
;set the counter
(setq ctr 0)
;start the loop
(repeat nfiles
;get the drawing name
(setq dname (nth ctr thelist))
;create the HTML link
(write-line (strcat "<a href =" "\""
thedir dname "\"" ">" thedir dname "
</a><br>") fn)
;increment the counter
(setq ctr (1+ ctr))
);end repeat
;write the HTML footer
(write-line "<hr><h3>Brought to you by CAD Encoding</h3>
</body></html>" fn)
;close the file
(close fn)
;inform the user
(alert (strcat "File saved as" "\n" thedir "Dwf-Html.html"))
);progn
);if flag
;finish clean
(princ)
);defun
;load clean
(princ)
Now, load and run this routine.
A file dialog will appear. Choose the directory your DWf files are located in, and then select the DWF
files you would like listed in the HTML report.
The HTML file will be created and stored in the same directory as your DWF files and will be named
"Dwf-Html.html." Open this file in your browser. You should have a list of links to all the DWF files you
selected.
As I mentioned earlier, we make use of the DosLib function "dos_filem" to allow the user to select the
DWF files that he/she/it wants to process.
The "dos_filem" function displays a file open dialog box that allows for multiple file selection. The
function returns a list of filenames if successful. The first element of the list is a qualified path to the
selected directory. eg.
(setq thedir (car thelist))
returns the file directory and
AutoCAD and HTML - Page II
http://www.afralisp.com/lisp/html2.htm (2 of 3) [23/03/2005 05:46:06 p.m.]
(setq thelist (cdr thelist))
returns a list of file names. Do yourself a favour and read the help file that comes with DosLib as you'll
find a lot of useful functions that will make your AutoLisp coding a lot easier.
Right, now let's have a look at doing something with HTML using Visual Lisp.
Home Page I Page III Page IV

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD and HTML - Page II
http://www.afralisp.com/lisp/html2.htm (3 of 3) [23/03/2005 05:46:06 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoCAD and HTML - Page III
Time for another wee bit of a break for me. By sleuth of hand and the use of threats to various
appendages stuck on his body, I finally conned someone else into writing the next section for me. Say
hi to David Stein everyone, ("Hi Dave!!")
If you don't know Dave, well he is the gentleman responsible for "DSX Tools" and the "Visual Lisp
Bible." You can find his new permanent home at http://www.dsxcad.com. Pop along as it's well worth
the visit. (just check for your wife and wallet when you leave.)
Okey dokey. Dave is the author of this nice little program written using Visual Lisp that will not only
write the Layer Names to an HTML file, but will also write the Layer properties and status. Let's have a
look at the coding.
Copy and paste this into Notepad and save it as "DumpLayers.lsp."
;; This example involves the task of producing an HTML report of all
;; layers in the current drawing, including their properties (color, linetype, etc.)
;; and opening the report in a web browser after completion.
;; When loaded, the command is DUMPLAYERS.
(defun C:DUMPLAYERS
( / acad doc dwg layers name col ltp lwt pst onoff frz dat
path olist outfile output)
;load the VL extensions
(vl-load-com)
;get reference to AutoCAD
(setq acad (vlax-get-acad-object)
;reference the drawing
doc (vla-get-activedocument acad)
;get the drawing name
dwg (vla-get-name doc)
;get the drawing path
path (vla-get-path doc)
;get the layers cpllection
layers (vla-get-layers doc)
);setq
;process each layer
(vlax-for each layers
;get the layer name
(setq name (vla-get-name each)
;get the layer color
col (itoa (vla-get-color each))
;get the linetype
ltp (vla-get-linetype each)
;get the lineweight
lwt (itoa (vla-get-lineweight each))
;get the plotstyle
pst (vla-get-plotstylename each)
;on-off status
AutoCAD and HTML - Pge III
http://www.afralisp.com/lisp/html3.htm (1 of 3) [23/03/2005 05:46:08 p.m.]
onoff (if (= :vlax-true (vla-get-layeron each))
"ON" "OFF")
;frozen-thawed status
frz (if (= :vlax-true (vla-get-freeze each))
"FROZEN" "THAWED")
;list them
dat (list name col ltp lwt pst onoff frz)
;add to main list
olist (cons dat olist)
);setq
); vlax-for
;release all objects
(vlax-release-object layers)
(vlax-release-object doc)
(vlax-release-object acad)
;create the HTML file
(cond
( olist
(setq outfile (strcat (vl-filename-base dwg) ".htm"))
(setq outfile (strcat path outfile))
(cond
( (setq output (open outfile "w"))
(write-line "<html>" output)
(write-line "<head><title>" output)
(write-line (strcat "Layer Dump: " dwg) output)
(write-line "</title></head><body>" output)
(write-line (strcat "<b>Drawing: " dwg "</b><br>") output)
(write-line "<table border=1>" output)
(foreach layset olist
(write-line "<tr>" output)
(foreach prop layset
(write-line (strcat "<td>" prop "</td>") output)
)
(write-line "</tr>" output)
); foreach layer set
(write-line "</table></body></html>" output)
(close output)
(setq output nil)
;inform the user
(princ "\nReport finished! Opening in browser...")
;open the HTML report in the browser
(vl-cmdf "_.browser" outfile)
)
( T (princ "\nUnable to open output file.") )
)
)
( T (princ "\nUnable to get layer table information.") )
)
);defun
(princ)
Load and run this routine. The HTML file should automatically open in your browser.
Hey, is that not nice? All your layers, layer properties and status all nicely tabulated in a report! By the
way, if you are not very clued up on Visual Lisp, there are a whole set of Tutorials posted on AfraLisp
that you can use to familiarise yourself with this powerful addition to the AutoLisp language.
Okay, one more page to go. (phew.)
Now let's look at AutoCAD and HTML using Visual Basic. (Oooh, I can hear you say.)
Home Page I Page II Page IV
AutoCAD and HTML - Pge III
http://www.afralisp.com/lisp/html3.htm (2 of 3) [23/03/2005 05:46:08 p.m.]

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD and HTML - Pge III
http://www.afralisp.com/lisp/html3.htm (3 of 3) [23/03/2005 05:46:08 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoCAD and HTML - Page IV
Programming for AutoCAD using Visual Basic brings quite a few advantages as well as a few
disadvantages. The main advantage is having full access to all the Visual Basic functions, tools,
controls, etc. The biggest disadvantage is having to make sure that the target computer has all the
support and system files necessary to run your program.
One area that Visual Basic stands out is in Batch Processing. In this example, we're going to design a
simple little standalone Visual Basic program that will "plot" a directory of drawings to DWF files. and
then create an HTML web page with a list of links to these DWF files.
By the way, this program can very easily be modified to suit any type of Batch Processing that your little
heart desires.
Open Visual Basic and create a new Standard.exe Project.
Firstly, you will need to insert a new Form with the following controls :
DriveListBox - Drive1 G
DirListBox - Dir1 G
FileListBox - File1 G
5 Labels - Label1 to Label5 G
CommandButton - btnExport G
CommandButton - btnCancel G
Now enter the following coding under the General Declarations section :
(I recommend you download the source coding for this project as word-wrapping can cause major
problems. The download link is at the bottom of this page.)
AutoCAD and HTML - Page IV
http://www.afralisp.com/lisp/html4.htm (1 of 5) [23/03/2005 05:46:11 p.m.]
Option Explicit
'----------------------
Private Sub btnCancel_Click()
End
'End the Application
End Sub
'----------------------
Private Sub btnExport_Click()
'declare variables
Dim acadApp As Object
Dim acadDoc As Object
Dim filename As String
Dim dirname As String
Dim pViewport As Object
Dim mylen As Integer
Dim filename1 As String
Dim nFile As Integer
Dim MMode As Integer
'test for root directory
If Right(File1.Path, 1) <> "\" Then
'if not root add \
dirname = File1.Path & "\"
Else
'if root directory do nothing
dirname = File1.Path
End If
'check if A:Drive has been choosen
If UCase(dirname) = "A:\" Then
'Hide the dialogue box
Me.Hide
'inform the user
MsgBox ("Insufficient Space to Process Drawings on Drive A:"), 16, _
"DWF Batcher"
'end the application
End
End If
'inform the user that we are about to connect to AutoCAD
Label5.Caption = "Please Wait......" & vbCr & "Connecting to AutoCAD"
'if error carry on with next line
On Error Resume Next
'set reference to AutoCAD Application
Set acadApp = GetObject(, "AutoCAD.Application")
'if there is an error (AutoCAD not open)
If Err Then
'clear the error
Err.Clear
'open AutoCAD
Set acadApp = CreateObject("Autocad.Application")
AutoCAD and HTML - Page IV
http://www.afralisp.com/lisp/html4.htm (2 of 5) [23/03/2005 05:46:11 p.m.]
'set reference to AutoCAD Application
Set acadApp = GetObject(, "AutoCAD.Application")
'if there is another error
If Err Then
'inform user
MsgBox Err.Description
'exit application
Exit Sub
End If
End If
'Make Autocad Visible
acadApp.Visible = True
'set reference to active document
Set acadDoc = acadApp.ActiveDocument
'Retrieve the SDI mode
MMode = acadDoc.GetVariable("SDI")
'Check SDI
If MMode = 0 Then
'Switch it on
acadDoc.SetVariable "SDI", 1
End If
'Hide the dialogue box
Me.Hide
'get the next free file number
nFile = FreeFile
'open the html file to write to
Open dirname & "DWFBatcher.htm" For Output As #nFile
'write the header
Print #nFile, "<html><head><title>WMF Batcher</title></head><body> _
<h3>DWF _ Batcher</h3>"
'retrieve the first entry
filename = Dir(dirname, vbNormal)
'start the loop
Do While filename <> ""
'ignore files that do not end with .DWG
If UCase(Right$(filename, 4)) = ".DWG" Then
'use bitwise comparison to make sure filename is not a directory
If (GetAttr(dirname & filename) And vbNormal) = vbNormal Then
'if drawing not saved
If Not acadDoc.Saved Then
'save the drawing
acadDoc.Save
End If
End If
'*******************************************************************
'This is the section of the program where you process each drawing.
'You can do anything your little heart desires........
AutoCAD and HTML - Page IV
http://www.afralisp.com/lisp/html4.htm (3 of 5) [23/03/2005 05:46:11 p.m.]
'open drawing to process
acadDoc.Open dirname & filename
'get the length of the filename
mylen = Len(filename)
'subtract the .DWG Extension
mylen = mylen - 4
'retrieve the drawing name
filename1 = Left(filename, mylen)
'write the DWF file name link
Print #nFile, "<a href=" & dirname & filename1 & ".DWF" & ">" & _
dirname & filename1 & ".DWF" & "</a>" & "<p>"
'set reference to the viewports
Set pViewport = acadDoc.ActiveViewport
'zoom to extents
pViewport.ZoomExtents
'create the DWF file
'commands shown are for the default DWFOUT settings
'you may need to replace to suit your requirements
acadDoc.SendCommand "DWFOUT" & vbCr & vbCr & vbCr & vbCr & _
vbCr & vbCr
'save the drawing
acadDoc.Save
End If
'get the next entry
filename = Dir
'carry on looping
Loop
'write the footer
Print #nFile, "</body></html>"
'close the file
Close #nFile
'reset SDI
acadDoc.SetVariable "SDI", MMode
'Close Autocad
acadApp.Quit
're-display the dialog
Me.Show
'inform the user
Label5.Caption = "Process Complete......" & vbCr & _
"Select another Directory or Cancel"
End Sub
'-------------------------------
Private Sub Dir1_Change()
'retrieves the drive and directory name
File1.Path = Dir1.Path
'displays it in the dialog
Label4.Caption = Dir1.Path
End Sub
'--------------------------------
AutoCAD and HTML - Page IV
http://www.afralisp.com/lisp/html4.htm (4 of 5) [23/03/2005 05:46:11 p.m.]
Private Sub Drive1_Change()
'retrieves the drive name
Dir1.Path = Drive1.Drive
End Sub
'---------------------------------
Private Sub Form_Load()
'Populate the labels
Label1.Caption = "Directory to Process :"
Label2.Caption = "Choose Drive and Directory"
Label3.Caption = "Brought to you by CAD Encoding"
End Sub
Save your Project as "DwfBatcher." When you run this program, a dialog will appear as shown above.
Choose the drive and directory containing the drawings you would like to process, then select "Go for
it." If AutoCAD is not already open, it will be opened and each drawing will be plotted as a DWF file. On
completion, an HTML file will be created in the same directory as the drawings.
To download the source coding for all four of these routines, put the index finger of your left hand in
your right nostril, stick your tongue out, and then click here.
Home Page I Page II Page III

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD and HTML - Page IV
http://www.afralisp.com/lisp/html4.htm (5 of 5) [23/03/2005 05:46:11 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Publishing Coding
Okay, you've written your coding, it works great, your boss and your workmates think you're brilliant,
but now you would like to share your coding with the whole wide world.
So, off you go and organise yourself some web space, start your first page, put some witty comments
at the top, and then plonk in your coding.
Then this is what happens :
(defun c:al-move ( / util BP PT2) (vl-load-com) ;get a reference to the Utilities Object : (setq util (vla-get-utility
(vla-get-activedocument (vlax-get-acad-object)))) ;select the object (vla-getentity util 'theobj 'ip "\nSelect Object:
") ;get the base point (setq BP (vla-getpoint util nil "\nSpecify base point or displacement: ")) ;get the
displacement (setq PT2 (vla-getpoint util BP "\nSpecify second point of displacement: ")) ;move the object
(vla-move theobj BP PT2) (princ) );defun (princ)
All your beautifully formatted coding has become a jumbled mess because all the white space and line breaks have
been removed.
The solution though, is an easy one to explain.
Simply wrap your coding using the <pre> tags :
<pre>
Your coding goes here
</pre>
Your coding will now look like this :
(defun c:al-move ( / util BP PT2)
(vl-load-com)
;get a reference to the Utilities Object :
(setq util (vla-get-utility
(vla-get-activedocument
(vlax-get-acad-object))))
;select the object
(vla-getentity util 'theobj 'ip "\nSelect Object: ")
;get the base point
(setq BP (vla-getpoint util nil
"\nSpecify base point or displacement: "))
;get the displacement
(setq PT2 (vla-getpoint util BP
"\nSpecify second point of displacement: "))
;move the object
(vla-move theobj BP PT2)
(princ)
);defun
(princ)
Publishing Coding
http://www.afralisp.com/html/publishing_coding_I.htm (1 of 4) [23/03/2005 05:46:12 p.m.]
An even better way, is to place your coding within the <pre> tags, AND within a table :
(defun c:al-move ( / util BP PT2)
(vl-load-com)
;get a reference to the Utilities Object :
(setq util (vla-get-utility
(vla-get-activedocument
(vlax-get-acad-object))))
;select the object
(vla-getentity util 'theobj 'ip "\nSelect Object: ")
;get the base point
(setq BP (vla-getpoint util nil
"\nSpecify base point or displacement: "))
;get the displacement
(setq PT2 (vla-getpoint util BP
"\nSpecify second point of displacement: "))
;move the object
(vla-move theobj BP PT2)
(princ)
);defun
(princ)
Much easier to read and quite nice to look at if I may say so myself.
Here's the HTML coding for the table :
<table border="3" cellpadding="3" cellspacing="0" width="500" bgcolor="#00FFFF">
<tr>
<td>
<pre>
Your coding goes here
</pre>
</td>
</tr>
</table>
Now let's get really clever and place our coding into an Inline Frame :
[Netscape users should click here to see what they are missing]
Hey Kenny, now you're really cooking!!
The HTML coding for an Inline Frame looks like this :
<IFRAME
frameBorder=1 height=200 width=550 marginHeight=0 marginWidth=1 src="code.htm">[Netscape users should
click <a href="code.htm">here</a>
to see what they are missing]
</IFRAME>
Publishing Coding
http://www.afralisp.com/html/publishing_coding_I.htm (2 of 4) [23/03/2005 05:46:12 p.m.]
You will find the HTML coding for the frame page "code.htm" here.
But, the ultimate is to make use of Randall Rath's Language Formatter which will result in something like this :
[Netscape users should click here to see what they are missing]
The Language Formatter will convert your AutoLisp/VBA Coding into HTML, colour code it, and even add line
numbers if you so wish.
If you would like a standalone application that colour codes AutoLisp coding, have a look at "wLsp2html" written
by Mark Duenas.
Oh, just one more thing before I pop off to the fridge for another beer, would you like to strip all the white space out
of your AutoLisp coding?
Open a new file in Notepad and add these lines :
<HTML>
<HEAD>
<TITLE>Strip White Space</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
Now add you code between the <BODY> and </BODY> tags :
<HTML>
<HEAD>
<TITLE>Strip White Space</TITLE>
</HEAD>
<BODY>
(defun c:al-move ( / util BP PT2)
(vl-load-com)
;get a reference to the Utilities Object :
(setq util (vla-get-utility
(vla-get-activedocument
(vlax-get-acad-object))))
;select the object
(vla-getentity util 'theobj 'ip "\nSelect Object: ")
;get the base point
(setq BP (vla-getpoint util nil
"\nSpecify base point or displacement: "))
;get the displacement
(setq PT2 (vla-getpoint util BP
"\nSpecify second point of displacement: "))
;move the object
(vla-move theobj BP PT2)
(princ)
);defun
(princ)
</BODY>
</HTML>
Save this file as "STRIP.HTML".
Now open this file in your browser.
Copy the text that appears in your browser and paste it into Notepad.
All the white space has been stripped from your coding.
Publishing Coding
http://www.afralisp.com/html/publishing_coding_I.htm (3 of 4) [23/03/2005 05:46:12 p.m.]
The above AutoLisp coding will now look like this :
(defun c:al-move ( / util BP PT2) (vl-load-com) ;get a reference to the Utilities Object : (setq util (vla-get-utility
(vla-get-activedocument (vlax-get-acad-object)))) ;select the object (vla-getentity util 'theobj 'ip "\nSelect Object: ") ;get
the base point (setq BP (vla-getpoint util nil "\nSpecify base point or displacement: ")) ;get the displacement (setq PT2
(vla-getpoint util BP "\nSpecify second point of displacement: ")) ;move the object (vla-move theobj BP PT2) (princ)
);defun (princ)

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Publishing Coding
http://www.afralisp.com/html/publishing_coding_I.htm (4 of 4) [23/03/2005 05:46:12 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
(defun c:al-move ( / util BP PT2)
(vl-load-com)
;get a reference to the Utilities Object :
(setq util (vla-get-utility
(vla-get-activedocument
(vlax-get-acad-object))))
;select the object
(vla-getentity util 'theobj 'ip "\nSelect Object: ")
;get the base point
(setq BP (vla-getpoint util nil
"\nSpecify base point or displacement: "))
;get the displacement
(setq PT2 (vla-getpoint util BP
"\nSpecify second point of displacement: "))
;move the object
(vla-move theobj BP PT2)
(princ)
);defun
(princ)
Coding
http://www.afralisp.com/html/code.htm (1 of 2) [23/03/2005 05:46:13 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Coding
http://www.afralisp.com/html/code.htm (2 of 2) [23/03/2005 05:46:13 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
(defun c:al-move ( / util BP PT2)
(vl-load-com)
;get a reference to the Utilities Object :
(setq util (vla-get-utility
(vla-get-activedocument
(vlax-get-acad-object))))
;select the object
(vla-getentity util 'theobj 'ip "\nSelect Object: ")
;get the base point
(setq BP (vla-getpoint util nil
"\nSpecify base point or displacement: "))
;get the displacement
(setq PT2 (vla-getpoint util BP
"\nSpecify second point of displacement: "))
;move the object
(vla-move theobj BP PT2)
(princ)
);defun
(princ)
code2.htm
http://www.afralisp.com/html/code2.htm (1 of 2) [23/03/2005 05:46:14 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
code2.htm
http://www.afralisp.com/html/code2.htm (2 of 2) [23/03/2005 05:46:14 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Lisp to HTML
Download wLsp2html.zip (201 kB)
Here's a handy little program that will convert an AutoLisp file into HTML and create the web page. It
was written by a gentleman named Mark Duenas.
While you're here, pop along here and have a look at Mark's Guitar site :
http://www.cableone.net/mdeunas/guitar/default.htm
wLsphtml.exe is a windows version of Lsphtml.exe! (an upgrade of sorts) AutoLISP to HTML converter.
To use this program double click on wlsphtml.exe to run the dialog G
Next click on the button next to the input file edit box to choose a single or multiple .LSP files to
convert to HTML.
G
Next click on the button next to the output file edit box to choose an output directory. G
[optional] Next click on the button next to the Background Graphics File edit box to choose a
background image for the html file(s). This is optional so if you dont have a background to
include you may ignore this field.
G
[optional] The Include Visual Lisp Functions check box includes the keywords for Visual Lisp
(over 1500 of them) in the conversion. So if you dont use them and you have many files to
convert it would be faster not to check this check box.
G
[optional] The Exit after convert just exits the program after converting the file or files. G
Questions, Comments, Bugs:
Please let me know how this program could better serve your needs. Thanks!
Mark Duenas
2698 N. Robie Ave.
Meridian, ID 83642
markduenas@cableone.net
Here's an example of wLsp2html in action :
Lisp to HTML
http://www.afralisp.com/lisp/lsp2htlm.htm (1 of 5) [23/03/2005 05:46:17 p.m.]
(defun c:batchpurge ( / CNTR DPATH DWGPATH FILE1 FLAG FLEN FNAME
FNAME1 LEN1 MESSAGE NFILES NFILES1 SCRFILE
UFILES)
;;;Firstly we need to check if DOSLib is loaded.
(cond
((= (atoi (substr (getvar "acadver") 1 2)) 13)
(if (not (member "doslib13.arx" (arx)))
(arxload (findfile "doslib13.arx"))))
((= (atoi (substr (getvar "acadver") 1 2)) 14)
(if (not (member "doslib14.arx" (arx)))
(arxload (findfile "doslib14.arx"))))
((= (atoi (substr (getvar "acadver") 1 2)) 15)
(if (not (member "doslib2k.arx" (arx)))
(arxload (findfile "doslib2k.arx"))))
);cond
;;;This, first checks the version of AutoCAD in use.
;;;It then checks to see if that version of Doslib is loaded.
;;;If it is not, it searches the AutoCAD search path for the
;;;relevant version, and then loads it.
;;;Now, we need to retrieve the names of the files that we would
;;;like to make slides from.
(setq dwgpath (getvar "dwgprefix"))
;get the path to the current directory
(setq ufiles (dos_getfilem "Select Drawings"
dwgpath "Drawing Files (*.DWG)|*.DWG"))
;display the file dialogue box
(if (not ufiles)
;if no files selected or Cancel

(exit)
;exit the application
);
;;;The first item in the list "ufiles" is the directory path
;;;The remaining items are the file names.
;;;First, let's retrieve the directory path.
(setq dpath (nth 0 ufiles))
;retrieve the directory path - the first item.
;;;Next, let's get the number of items in the list,
;;;and make sure that the user wants to continue.
(setq nfiles (length ufiles))
;get the length of the list
(setq nfiles1 (itoa (- nfiles 1)))
;count only the file names and convert to a string
(setq message (strcat "You have choosen " nfiles1 " files.
Lisp to HTML
http://www.afralisp.com/lisp/lsp2htlm.htm (2 of 5) [23/03/2005 05:46:17 p.m.]
\nDo you want to continue?"))
;set up the message
(setq flag (dos_msgbox message "AfraLisp Batch Purge" 4 4))
;display the message box
(if (= flag 6)
;if Yes selected
(progn
;do the following
;;;We'll now open an external file to write our script to.
(setq scrfile (strcat dpath "batdir.scr"))
;add the path to the script file name
(setq file1 (open scrfile "w"))
;open the file to write
(setq cntr 1)
;set the counter
;;;We'll now start the loop, format the file names, and add
;;;the commands to the script file.
(repeat (- nfiles 1)
;start the loop
(setq fname (nth cntr ufiles))
;get the file name
(setq fname (strcat dpath fname))
;add the path to the file name.
;"fname" will be used to open each
;drawing.
;(setq flen (strlen fname))
;get the length of file name
;(setq len1 (- flen 4))
;take away the last 4 characters (.DWG)
;(setq fname1 (substr fname 1 len1))
;get just the filename without the extension.
;"fname1" will be used as our slide file name.
;;;write the commands to the script file
(write-line (strcat "open " fname) file1)
;open the drawing
;write it to the script file
(write-line (strcat "filedia" " 0") file1)
;switch off dialogues
;write it to the script file
(write-line (strcat "purge") file1)
Lisp to HTML
http://www.afralisp.com/lisp/lsp2htlm.htm (3 of 5) [23/03/2005 05:46:17 p.m.]
;purge the drawing
;write it to the script file
(write-line (strcat "A") file1)
;purge ALL
;write it to the script file
(write-line (strcat "*") file1)
;purge EVERYTHING
;write it to the script file
(write-line (strcat "N") file1)
;NO
;write it to the script file
(write-line (strcat "filedia" " 1") file1)
;switch on dialogues
;write it to the script file
(write-line "qsave" file1)
;save the drawing
;write it to the script file

(setq cntr (1+ cntr))
;increment the counter
);repeat
;;;now that we've finished writing the commands to the script
;;;file, we must remember to close it.
(close file1)
;close the script file
(command "script" scrfile)
;run the script file and sit back and have a beer.
);progn
);if
(princ)
);defun
(princ)

Lisp to HTML
http://www.afralisp.com/lisp/lsp2htlm.htm (4 of 5) [23/03/2005 05:46:17 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Lisp to HTML
http://www.afralisp.com/lisp/lsp2htlm.htm (5 of 5) [23/03/2005 05:46:17 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Creating a Toolbar DLL (14Kb)
Are you sick and tired of having all those Toolbar Bitmap Files floating around?
And, what a pain it is having to remember to attach the bitmaps along with the
Toolbar menu file every time you send it to someone, or install the menu on another workstation.
(Smiley Faces here we come..)
The solution to this, is to store the Bitmaps in an ActiveX DLL file. (The same as
AutoCAD do with their Toolbar Bitmaps.) Here's the steps to construct your own,
customized Toolbar DLL.
Unfortunately, you will require the Visual Basic Resource Editor which is only
included with VB6. (I do believe though, that the Resource Editor is available as a plug-in for VB5.)
Firstly, you need to build your Toolbar along with all relevant Bitmaps and test it within AutoCAD. Here is
the menu file for the VBA Toolbar which is in the downloadable sample file :
***MENUGROUP=VBA
***TOOLBARS
ID_VBA_0 [_Toolbar("VBA", _Floating, _Show, 350, 246, 1)]
ID_VBA_1 [_Button("VBA Load", "vbaload.bmp", "vbaload32.bmp")]^C^C_vbaload
ID_VBA_2 [_Button("VBA Macro", "vbamacro.bmp", "vbamacro32.bmp")]^C^C_vbarun
ID_VBA_3 [_Button("VBA Editor", "vbaide.bmp", "vbaide32.bmp")]^C^C_vbaide
ID_VBA_4 [_Button("VBA Manager", "vbaman.bmp", "vbaman32.bmp")]^C^Cvbaman
***HELPSTRINGS
ID_VBA_1 [Load VBA Project]
ID_VBA_2 [Run VBA Macro]
ID_VBA_3 [Load VBA Editor]
ID_VBA_4 [Load VBA Manager]
Your Toolbar should look like this :
Now, do yourself a favour and store the Menu file and all Bitmaps into their own sub-directory. If you don't,
you will find it a problem later on when editing the DLL file to locate all the VB support files.
Now fire up VB6 and start a new ActiveX DLL project. Next, open the VB6 Resource Editor. If it is not
loaded, go to the Add-In Manager and load it.
Creating a Toolbar DLL
http://www.afralisp.com/vbaa/vba15.htm (1 of 3) [23/03/2005 05:46:20 p.m.]
Once in the Resource Editor, load each of your Bitmap Files, renaming each Bitmap to match that of the
relevant name in the menu. (Right-Click on each name and select Properties.) Now save your project. (Save it
using the same name as your Menu and to the same sub-directory.)
Finally, choose "File" - "Make YourMenuName.DLL", again saving it to the same directory. (It is important
that the DLL file has the same name as the Menu.)
You can now exit VB6. (saving any files if prompted.)
One final step. (Well, a couple!!) Open up your Menu file and remove the .BMP extension from the Bitmap
file names. It should look like this :
***MENUGROUP=VBA
***TOOLBARS
ID_VBA_0 [_Toolbar("VBA", _Floating, _Show, 350, 246, 1)]
ID_VBA_1 [_Button("VBA Load", "vbaload", "vbaload32")]^C^C_vbaload
ID_VBA_2 [_Button("VBA Macro", "vbamacro", "vbamacro32")]^C^C_vbarun
ID_VBA_3 [_Button("VBA Editor", "vbaide", "vbaide32")]^C^C_vbaide
ID_VBA_4 [_Button("VBA Manager", "vbaman", "vbaman32")]^C^Cvbaman
***HELPSTRINGS
ID_VBA_1 [Load VBA Project]
ID_VBA_2 [Run VBA Macro]
ID_VBA_3 [Load VBA Editor]
ID_VBA_4 [Load VBA Manager]
Then copy your Menu file and the DLL file to any of your AutoCAD support path
directories. You now need to re-compile your Menu file. To do this, first delete all MNS, MNC and MNR files
with the same name as your menu. Then fire up AutoCAD and load your menu. Hopefully, no smiley
faces......
From now on, all you need to do to distribute your menu is to include the DLL file
along with the Menu file. Bye, Bye Bitmaps.....

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Creating a Toolbar DLL
http://www.afralisp.com/vbaa/vba15.htm (2 of 3) [23/03/2005 05:46:20 p.m.]
Search
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Creating a Toolbar DLL
http://www.afralisp.com/vbaa/vba15.htm (3 of 3) [23/03/2005 05:46:20 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Creating a Toolbar DLL Re-Visited
A big problem for AutoCAD uses when creating or custumising toolbars is ensuring that all the
bitmap files used by the toolbar are available and within the AutoCAD search path. In my tutorial
"Creating a Toolbar DLL" I explained how to create a DLL file to store all your toolbar bitmaps
using the Visual Basic Resource Editor. Now this is great if you're lucky enough to have VB6, but
what if you haven't? Well, I was introduced to a great little FREE application the other day that
will allow you to create and edit DLL files without having VB6 installed. This application, called
"Resource Hacker," was written by Angus Johnson and you can find it at :
http://www.users.on.net/johnson/resourcehacker/
AutoCAD Usage :
Before you start, please unload the relevant menu file from AutoCAD and then delete the MNC,
MNS and MNR files belonging to the menu. You should be left with just your MNU file. This is to
prevent AutoCAD from getting confused.
First you must install "Resource Hacker."
Secondly have all your toolbar bitmap files ready and in one directory.
As far as I know, you cannot create a new DLL file using the "Resource Hacker," so I have
supplied an empty DLL file called "AfraLisp.dll." I would suggest you place this file in the same
directory as your bitmap files.
I have supplied some sample bitmaps and a sample AutoCAD Toolbar menu to use as an example.
O.K. away we go. Fire up the "Resource Hacker."
From the pulldown menu select "File" -> "Open" and select "AfraLisp.dll."
Next, select "Action" -> "Add a new Resource."
Creating a Toolbar DLL Re-Visited
http://www.afralisp.com/vbaa/vbadll.htm (1 of 5) [23/03/2005 05:46:29 p.m.]
The "Add a New Resource" dialogue will appear:
Click the "Open file with new resource" button, and select your first bitmap file.
In the "Resource Name" text box, enter the name of your bitmap, excluding the file extension:
Next, click on the "Add Resource" button:
Creating a Toolbar DLL Re-Visited
http://www.afralisp.com/vbaa/vbadll.htm (2 of 5) [23/03/2005 05:46:29 p.m.]
Under the resource list your bitmap file will appear.
Repeat this process for all additional bitmap files.
When you have finished, the resource list should look like this:

Now, choose "File" -> "Save As" and save the file as "vbatoolbar.dll."
Now this is extremely important. The DLL file must have EXACTLY the same name as your menu
name and MUST be in the same directory. Copy the DLL file to the same directory as your MNU
file.
O.K. we've now created out Menu DLL file, but we still have to make some changes to our menu
file.
Open the menu file "vbatoolbar.mnu." It should look like this :
***MENUGROUP=VBA
***TOOLBARS
ID_VBA_0 [_Toolbar("VBA", _Floating, _Show, 350, 246, 1)]
Creating a Toolbar DLL Re-Visited
http://www.afralisp.com/vbaa/vbadll.htm (3 of 5) [23/03/2005 05:46:29 p.m.]
ID_VBA_1 [_Button("VBA Load", "vbaload.bmp", "vbaload32.bmp")]^C^C_vbaload
ID_VBA_2 [_Button("VBA Macro", "vbamacro.bmp", "vbamacro32.bmp")]^C^C_vbarun
ID_VBA_3 [_Button("VBA Editor", "vbaide.bmp", "vbaide32.bmp")]^C^C_vbaide
ID_VBA_4 [_Button("VBA Manager", "vbaman.bmp", "vbaman32.bmp")]^C^Cvbaman
***HELPSTRINGS
ID_VBA_1 [Load VBA Project]
ID_VBA_2 [Run VBA Macro]
ID_VBA_3 [Load VBA Editor]
ID_VBA_4 [Load VBA Manager]
You now need to remove the file extension from all of the bitmap references. Your menu file should
now look like this :
***MENUGROUP=VBA
***TOOLBARS
ID_VBA_0 [_Toolbar("VBA", _Floating, _Show, 350, 246, 1)]
ID_VBA_1 [_Button("VBA Load", "vbaload", "vbaload32")]^C^C_vbaload
ID_VBA_2 [_Button("VBA Macro", "vbamacro", "vbamacro32")]^C^C_vbarun
ID_VBA_3 [_Button("VBA Editor", "vbaide", "vbaide32")]^C^C_vbaide
ID_VBA_4 [_Button("VBA Manager", "vbaman", "vbaman32")]^C^Cvbaman
***HELPSTRINGS
ID_VBA_1 [Load VBA Project]
ID_VBA_2 [Run VBA Macro]
ID_VBA_3 [Load VBA Editor]
ID_VBA_4 [Load VBA Manager]
You are now ready to try out your menu. Load and run it. Your toolbar should appear and look
like this :
That's it, no more "smiley faces." Simple hey?
You can now remove all your bitmap files. Do yourself a favour though, keep them somewhere safe
so that if you have to re-compile your DLL files, you still have your source bitmaps.
To download the source files for this tutorial including the empty DLL file,
just click here - Download VbaDll.Zip (8kB)

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Creating a Toolbar DLL Re-Visited
http://www.afralisp.com/vbaa/vbadll.htm (4 of 5) [23/03/2005 05:46:29 p.m.]
Search
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Creating a Toolbar DLL Re-Visited
http://www.afralisp.com/vbaa/vbadll.htm (5 of 5) [23/03/2005 05:46:29 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
ResourceTool.exe
Ed Jobe 2003
ResourceTool is a tool for use with VB to help with compiling resource dll's for a menu.
Normally, if you use the Resource Editor add-in and you load a
bmp, the editor assings a sequential number as the resource ID.
This means that if you want to continue referring to icons in your
menu by a name, you have to rename all the ID's in the RES file.
This tool avoids that using the rc.exe tool that comes with Visual
Studio. This utility can compile a C++ resource file (*.rc) into a
VB resource file (*.RES).
This program requires you to act in a specific sequence.
Specify a source folder where the bmp's reside. I suggest creating
a folder for your menu where you keep all the resources (the
bmp's, rc, res, vbp and dll). When finished, copy the dll to the
menu folder.
G
Specify an *.rc filename. Be sure to include the extension. G
Click on the "Create *.rc file" button. The program then scans the folder for all the bmp's and builds an *.RC file in
the folder specified in step 1, opening it in Notepad.
You can check it for accuracy or delete a line, etc.
G
Click on the "Compile RES file" button. The program compiles this file from the RC file. G
All you have to do then is, add the RES file to your dll project and compile the dll. G
Download ResourceTool.exe
AfraLisp - Resource Manager
http://www.afralisp.com/lispb/resourced.htm (1 of 2) [23/03/2005 05:46:31 p.m.]
For step-by-step instructions on getting the dll to work with your menu, see :
Create a Toolbar DLL. G
Create a Toobar DLL Re-Visited G

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AfraLisp - Resource Manager
http://www.afralisp.com/lispb/resourced.htm (2 of 2) [23/03/2005 05:46:31 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Batch Purge 2002
Batch Purge 2002 will batch purge ALL from a selected list of drawings.
You will need to have AutoCAD installed on your system, but will run without AutoCAD being open.
Updated for R2002 but should run fine on R2000 and R2000i.
Written in Visual Basic 6. Click here to download all VB6 source files.
Usage :
There are three ways of selecting files to purge. You can use the "Select All" button to select all
the drawing files in the current directory, you can double click on individual files, or you can
select a file and use the "Add Files" button. All files selected will be added to the Purge File List
Box.
G
You can select files from multiple directories. G
You can remove files from the Purge File List box by choosing "Remove All", double-clicking on a
file, or choosing a file and clicking the "Remove File" button.
G
Once you are happy with the your file selection, select the "Purge" button to start the Batch Purge
Process. AutoCAD does not have to be open for the process to proceed.
G
You can also selected the "Delete BAK Files" check box to have these files automatically deleted. G

Batch Purge 2002


http://www.afralisp.com/vba/bp2002.htm (1 of 2) [23/03/2005 05:46:35 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Batch Purge 2002
http://www.afralisp.com/vba/bp2002.htm (2 of 2) [23/03/2005 05:46:35 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Batch Purge 2004
Batch Purge 2004 will batch purge ALL from a selected list of drawings.
You will need to have AutoCAD 2004 installed on your system, but will run without AutoCAD being
open. Updated for R2004.
Written in Visual Basic 6. Click here to download all VB6 source files.
Usage :
There are three ways of selecting files to purge. You can use the "Select All" button to select all
the drawing files in the current directory, you can double click on individual files, or you can
select a file and use the "Add Files" button. All files selected will be added to the Purge File List
Box.
G
You can select files from multiple directories. G
You can remove files from the Purge File List box by choosing "Remove All", double-clicking on a
file, or choosing a file and clicking the "Remove File" button.
G
Once you are happy with the your file selection, select the "Purge" button to start the Batch Purge
Process. AutoCAD does not have to be open for the process to proceed.
G
You can also selected the "Delete BAK Files" check box to have these files automatically deleted. G

Batch Purge 2004


http://www.afralisp.com/vba/bp2004.htm (1 of 2) [23/03/2005 05:46:39 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Batch Purge 2004
http://www.afralisp.com/vba/bp2004.htm (2 of 2) [23/03/2005 05:46:39 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
RC-Batcher (67Kb)
This application was sent to me by Ramn Castro.
It basically allows you to run any AutoLISP routine against a selected set of drawings.
Usage

Open the application. G


Choose the files to be processed.
(You can choose files from multiple directories.)
G
Select "Browse". G
A new dialogue will open. G
Select the lisp file to use. G
Select O.K. G
RC-Batcher
http://www.afralisp.com/vbaa/vba14.htm (1 of 2) [23/03/2005 05:46:43 p.m.]
Select "Run". G
In the downloadable Zip file, I have included a sample lisp file (Slidem.lsp) that will create slides
from a selection of drawings.
This application is written in Visual Basic 6, so you may require MSVBVM60.DLL to run. Contact
Ramn or myself if you require it.
Ramn Castro is a Survey CADD Technician for City of Fort Lauderdale Engineering.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
RC-Batcher
http://www.afralisp.com/vbaa/vba14.htm (2 of 2) [23/03/2005 05:46:43 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Drawing Export (9 Kb)
AcadExport.Exe is a stand alone application written in Visual Basic for AutoCAD Release 14.
This routine will Export a selected directory of drawings.
Formats available for export are WMF, DXF, EPS and BMP.
If AutoCAD is not open when you run the application, it will automatically open AutoCAD. You
can also run it from within Autocad.
Usage :
Open the application by double clicking on AcadExport.Exe.
A dialogue box will appear. Select the directory where the drawings you wish to Export reside.
Select the format you wish to export the file as from the radio buttons and then Select "OK".
If you wish to run it from within AutoCAD type the following at the command prompt :
(startapp "....directory path..../acadexport.exe")
Please note that you cannot Export Drawings to Drive A:.
The VBA Code
The following must be placed under the event procedure of the Drive List Box:
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
'retrieves the drive name
End Sub
Next, place this coding under the event procedure of the Directory List Box:
Private Sub Dir1_Change()
Drawing Export
http://www.afralisp.com/vbaa/vba3.htm (1 of 6) [23/03/2005 05:46:46 p.m.]
File1.Path = Dir1.Path
'retrieves the drive and directory name
End Sub
The main routine of the function is within the event procedure of the "Export" button:
Private Sub btnExport_Click()
Dim acadApp As Object
Dim acadDoc As Object
Dim filename As String
Dim dirname As String
Dim sset As Object
Dim pViewport As Object
'declare variables

If Right(File1.Path, 1) <> "\" Then
'test for root directory
dirname = File1.Path & "\"
'if not root add \
Else
dirname = File1.Path
'if root directory do nothing
End If
If UCase(dirname) = "A:\" Then
'check if A:Drive has been choosen
Me.Hide
'Hide the dialogue box

MsgBox ("Insufficient Space to Export Drawings on Drive A:"),_
16, "Drawing Export"
'inform the user

End
'end the application

End If


On Error Resume Next
'if error carry on with next line
Set acadApp = GetObject(, "AutoCAD.Application")
'setq reference to AutoCAD Application
If Err Then
'if there is an error (AutoCAD not open)
Err.Clear
'clear the error
Set acadApp = CreateObject("Autocad.Application")
'open AutoCAD
Drawing Export
http://www.afralisp.com/vbaa/vba3.htm (2 of 6) [23/03/2005 05:46:46 p.m.]
Set acadApp = GetObject(, "AutoCAD.Application")
'setq reference to AutoCAD Application
If Err Then
'if there is another error
MsgBox Err.Description
'inform user
Exit Sub
'exit application
End If
End If
acadApp.Visible = True
'Make Autocad Visible
Set acadDoc = acadApp.ActiveDocument
'set reference to active document
Me.Hide
'Hide the dialogue box

filename = Dir(dirname, vbNormal)
'retrieve the first entry
Do While filename <> ""
'start the loop
If UCase(Right$(filename, 4)) = ".DWG" Then
'ignore files that do not end with .DWG
If (GetAttr(dirname & filename) And vbNormal) = vbNormal Then
'use bitwise comparison to make sure filename is not a directory
If Not acadDoc.Saved Then
'if drawing not saved
If MsgBox("OK to Save Drawing?", 52, "Drawing Export") = vbNo Then
'give user choice to save drawing and continue, or exit application
End
'end if user selects No
Else
'or else
acadDoc.Save
'if Yes, save drawing
End If
Drawing Export
http://www.afralisp.com/vbaa/vba3.htm (3 of 6) [23/03/2005 05:46:46 p.m.]
End If
acadDoc.Open dirname & filename
'open drawing to purge
mylen = Len(filename)
'get the length of the filename
mylen = mylen - 4
'subtract the .DWG Extension
filename1 = Left(filename, mylen)
'retrieve the drawing name
Set pViewport = acadDoc.ActiveViewport
'set reference to the viewports
pViewport.ZoomExtents
'zoom to extents
Set sset = acadDoc.SelectionSets.Add("NEWSS")
'set reference to election set
sset.Select acSelectionSetAll
'select the whole drawing
If Option1.Value = True Then
'if radio button selected
acadDoc.Export dirname & filename1, "WMF", sset
'export the drawing
End If
If Option2.Value = True Then
'if radio button selected
acadDoc.Export dirname & filename1, "DXF", sset
'export the drawing
End If
If Option3.Value = True Then
'if radio button selected
acadDoc.Export dirname & filename1, "DWF", sset
'export the drawing
End If
If Option4.Value = True Then
'if radio button selected
acadDoc.Export dirname & filename1, "SAT", sset
'export the drawing
End If
Drawing Export
http://www.afralisp.com/vbaa/vba3.htm (4 of 6) [23/03/2005 05:46:46 p.m.]
If Option5.Value = True Then
'if radio button selected
acadDoc.Export dirname & filename1, "EPS", sset
'export the drawing
End If
If Option6.Value = True Then
'if radio button selected
acadDoc.Export dirname & filename1, "BMP", sset
'export the drawing
End If
acadDoc.Save
'save the drawing
End If
End If
filename = Dir
'get the next entry
Loop
'carry on looping
acadApp.Quit
'Close Autocad
MsgBox ("Drawing Export Complete"), , "Drawing Export"
'inform user that we have finished
End
'Close VBA Application
End Sub
Finally, this coding goes under the event procedure of the "Cancel" button:
Private Sub btnCancel_Click()
End
'end the routine
End Sub

Drawing Export
http://www.afralisp.com/vbaa/vba3.htm (5 of 6) [23/03/2005 05:46:46 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Drawing Export
http://www.afralisp.com/vbaa/vba3.htm (6 of 6) [23/03/2005 05:46:46 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Batch Purge (7 Kb)
BatchPurge.Exe is a stand alone application written in Visual Basic for AutoCAD Release 14.
This routine will Batch Purge (Purge All) a selected directory of drawings.
If AutoCAD is not open when you run the application, it will automatically open AutoCAD. You
can also run it from within Autocad.
Usage :
Open the application by double clicking on BatchPurge.Exe.
A dialogue box will appear. Select the directory where the drawings you wish to Purge reside. Select
"OK".
If you wish to run it from within AutoCAD type the following at the command prompt :
(startapp "....directory path..../batchpurge.exe")
The VBA Code
The following must be placed under the event procedure of the Drive List Box:
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
'retrieves the drive name
End Sub
Next, place this coding under the event procedure of the Directory List Box:
Private Sub Dir1_Change()
File1.Path = Dir1.Path
'retrieves the drive and directory name
End Sub
Batch Purge
http://www.afralisp.com/vbaa/vba2.htm (1 of 4) [23/03/2005 05:46:48 p.m.]
The main routine of the function is within the event procedure of the "Start Purge" button :
Private Sub Command1_Click()
Dim acadApp As Object
Dim acadDoc As Object
Dim filename As String
Dim dirname As String
'declare variables

If Right(File1.Path, 1) <> "\" Then
'test for root directory
dirname = File1.Path & "\"
'if not root add \
Else
dirname = File1.Path
'if root directory do nothing
End If
If UCase(dirname) = "A:\" Then
'check if A:Drive has been choosen
Me.Hide
'Hide the dialogue box

MsgBox ("Insufficient Space to Batch Purge Drawings on Drive A:"),_
16, "Batch Purge"
'inform the user

End
'end the application

End If


On Error Resume Next
'if error carry on with next line
Set acadApp = GetObject(, "AutoCAD.Application")
'setq reference to AutoCAD Application
If Err Then
'if there is an error (AutoCAD not open)
Err.Clear
'clear the error
Set acadApp = CreateObject("Autocad.Application")
'open AutoCAD
Set acadApp = GetObject(, "AutoCAD.Application")
'setq reference to AutoCAD Application
If Err Then
Batch Purge
http://www.afralisp.com/vbaa/vba2.htm (2 of 4) [23/03/2005 05:46:48 p.m.]
'if there is another error
MsgBox Err.Description
'inform user
Exit Sub
'exit application
End If
End If
acadApp.Visible = True
'Make Autocad Visible
Set acadDoc = acadApp.ActiveDocument
'set reference to active document
Me.Hide
'Hide the dialogue box

filename = Dir(dirname, vbNormal)
'retrieve the first entry
Do While filename <> ""
'start the loop
If UCase(Right$(filename, 4)) = ".DWG" Then
'ignore files that do not end with .DWG
If (GetAttr(dirname & filename) And vbNormal) = vbNormal Then
'use bitwise comparison to make sure filename is not a directory
If Not acadDoc.Saved Then
'if drawing not saved
If MsgBox("OK to Save Drawing?", 52, "Batch Purge") = vbNo Then
'give user choice to save drawing and continue, or exit application
End
'end if user selects No
Else
'or else
acadDoc.Save
'if Yes, save drawing
End If
End If
acadDoc.Open dirname & filename
'open drawing to purge
acadDoc.PurgeAll
'purge the drawing
Batch Purge
http://www.afralisp.com/vbaa/vba2.htm (3 of 4) [23/03/2005 05:46:48 p.m.]
acadDoc.Save
'save the drawing
End If
End If
filename = Dir
'get the next entry
Loop
'carry on looping
acadApp.Quit
'Close Autocad
MsgBox ("Batch Purge Complete"), , "Purge All"
'inform user that we have finished
End
'Close VBA Application
End Sub
Finally, this coding goes under the event procedure of the "Cancel" button :
Private Sub btnCancel_Click()
End
'end the routine
End Sub

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Batch Purge
http://www.afralisp.com/vbaa/vba2.htm (4 of 4) [23/03/2005 05:46:48 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp Drawing Backup
Do you need to transfer drawing files from one directory or drive to another?
Do you work on your local drives then transfer them to a network drive at the end of the
day? Or do you not trust your I.T. department and prefer to make your own backup of
critical files?
Then the AfraLisp Drawing Backup is for you. What does it do? Have a sneak preview :
Choose the directories you would like to back up from the Drive/Directory list boxes on the right,
clicking on "Add Folders >>" to add them to the "Folders Selected" list box. Highlight a directory
in the "Folders Selected" list box and select the "<< Clear Items" button to remove, or select "<<
Clear List" to remove all directories.
Next, select the "Browse" button to the right of the "Target" text box :
AfraLisp Drawing Backup
http://www.afralisp.com/vbaa/afraback.htm (1 of 3) [23/03/2005 05:46:55 p.m.]
Select the target directory you would like your drawings to be backed up to and then select "OK."
You will return to the main screen.
Now select "Start Backup" to process your selection. The text box at the bottom will give you a
running status of progress.
When the backup is complete the Report Dialogue will appear listing the backup results :
Click on the "View Log File" to open the Backup Log File, or select "Continue" to process
additional backups.
AfraLisp Drawing Backup
http://www.afralisp.com/vbaa/afraback.htm (2 of 3) [23/03/2005 05:46:55 p.m.]
Select the "Backup All Files" check box on the main screen if you want to backup all files
including drawing files.
You can also view the Log File from recent Backups by selecting the "View Log File" from the
main screen.
Download "AfraBack.zip" (173kb)
"AfraLisp Drawing Backup" was written using Visual Basic 6.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AfraLisp Drawing Backup
http://www.afralisp.com/vbaa/afraback.htm (3 of 3) [23/03/2005 05:46:55 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
How To Write Unmaintainable Code
Originally published at http://mindprod.com/unmain.html. Reprinted by special permission from the
author. Further reprints, without the express permission of the author are prohibited. Last updated
Thursday, 05-Apr-2001 03:41:36 PDT by Roedy Green 1997-2001 Canadian Mind Products.
Introduction
Never ascribe to malice, that which can be explained by incompetence.
Napoleon
In the interests of creating employment opportunities in the Java programming field, I am passing on
these tips from the masters on how to write code that is so difficult to maintain, that the people who
come after you will take years to make even the simplest changes. Further, if you follow all these rules
religiously, you will even guarantee yourself a lifetime of employment, since no one but you has a hope
in hell of maintaining the code. Then again, if you followed all these rules religiously, even you wouldn't
be able to maintain the code!
You don't want to overdo this. Your code should not look hopelessly unmaintainable, just be that way.
Otherwise it stands the risk of being rewritten or refactored.
General Principles
Quidquid latine dictum sit, altum videtur.
Whatever is said in Latin sounds profound.
To foil the maintenance programmer, you have to understand how he thinks. He has your giant
program. He has no time to read it all, much less understand it. He wants to rapidly find the place to
make his change, make it and get out and have no unexpected side effects from the change.
He views your code through a tube taken from the centre of a roll of toilet paper. He can only see a tiny
piece of your program at a time. You want to make sure he can never get at the big picture from doing
that. You want to make it as hard as possible for him to find the code he is looking for. But even more
important, you want to make it as awkward as possible for him to safely ignore anything.
Programmers are lulled into complacency by conventions. By every once in a while subtly violating
convention you force him to read every line of your code with a magnifying glass.
You might get the idea that every language feature makes code unmaintainable -- not so, only if properly
misused.
Naming
"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I
choose it to mean - neither more nor less."
Lewis Carroll -- Through the Looking Glass, Chapter 6
Much of the skill in writing unmaintainable code is the art of naming variables and methods. They don't
matter at all to the computer. That gives you huge latitude to use them to befuddle the maintenance
programmer.

New Uses For Names For Baby 1.


How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (1 of 19) [23/03/2005 05:47:00 p.m.]
20,001 Names For Baby
0-380-78047-X
Carol McD. Wallace
Buy a copy of a baby naming book and you'll never be at a loss for variable names. Fred is a
wonderful name, and easy to type. If you're looking for easy to type variable names, try adsf.

Single Letter Variable Names


If you call your variables a, b, c, then it will be impossible to search for instances of them using a
simple text editor. Further, nobody will be able to guess what they are for. If anyone even hints at
breaking the tradition honoured since FRTRAN of using i, j, and k for indexing variables,
replacing them with ii, jj and kk, warn them about what the Spanish Inquisition did to heretics.
2.
Creative Missspelling
If you must use descriptive variable and function names, misspell them. By misspelling in some
function and variable names, and spelling it correctly in others (such as SetPintleOpening
SetPintalClosing) we effectively negate the use of grep or CodeWright search techniques. It works
amazingly well. Add an international flavor by spelling theater and theatre in different situations.
3.
Be Abstract
In naming functions and variables, make heavy use of abstract words like it, everything, data,
handle, stuff, do, routine, perform and the digits e.g. routineX48, PerformDataFunction, DoIt,
HandleStuff and do_args_method.
4.
A.C.R.O.N.Y.M.S.
Use acronyms to keep the code terse. Real men never define acronyms; they understand them
genetically.
5.
Thesaurus Surrogatisation
To break the boredom, use a thesaurus to look up as much alternate vocabulary as possible to
refer to the same action, e.g. display, show, present. Vaguely hint there is some subtle difference,
where none exists. However, if there are two similar functions that have a crucial difference,
always use the same word in describing both functions (e.g. print to mean write to a file, and to a
print on a laser, and to display on the screen). Under no circumstances, succumb to demands to
write a glossary with the special purpose project vocabulary unambiguously defined. Doing so
would be unprofessional breach of the structured design principle of information hiding.
6.
Use Plural Forms From Other Languages
A contributor was the proud author of a VMS script that kept track of the "statii" returned from
various "Vaxen". Esperanto, Klingon and Hobbitese qualify as languages for these purposes. For
pseudo-Esperanto pluraloj, add oj. You will be doing your part toward world peace.
7.
CapiTaliSaTion
If you use intercapitalization for function names (capitalize the first letter of each word), randomly
capitalize the first letter of a syllable in the middle of a word. For example:
ComputeRasterHistoGram().
8.
Recycle Classnames as Member Names 9.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (2 of 19) [23/03/2005 05:47:00 p.m.]
In C/C++: Make sure to create parameters and local variables that have the same name as member
variables of the class whose method they appear in. For extra points, create nested local
variables inside {} blocks that have the same name as these local variables. The goal is for careful
examination of scope to be the only way to tell which context is actually being used.
ccented Letters
Use accented characters on variable names. E.g.

typedef struct { int i; } nt;


where the second int's i is actually iacute. Since these are structures the three int's are not
interchangeable, but with an 8-bit aware editor it's nearly impossible to distinguish the slant of
the accent mark. Insist the new "ints " are for some specific, but very obscure, situation where a
standard int won't suffice. It helps to toss extra stuff into the structure before making that claim!
10.
Exploit Compiler Name Length Limits
If the compiler will only distinguish the first, say, 8 characters of names, then always use more
characters, but vary the endings e.g. var_unit_update() in one case and var_unit_setup() in
another.
11.
Underscore, a Friend Indeed
Use _ or __ as an identifier.

12.
Mix English and Bahasa Indonesia
If English is your second language, use English for variable names, functions, messages
appearing on-screen, and comments. However randomly intersperse them with words chosen
from your native language. If your boss insists you use English tell him you can organize your
thoughts better in your own language, or allege racial discrimination and threaten to sue your
employers for a vast sum of money. Now that your boss does not understand your code you can
use obscuration techniques that you would never get away with otherwise and will foil a future
maintenance programmer even if she is also a native speaker or is equipped with a bilingual
dictionary.
13.
Extended ASCII
Extended ASCII characters are perfectly valid as variable names, including , , and characters.
They are quite impossible to type without copying/pasting.
14.
Deutch, Franais, Esperanto
If you cannot find the right English word to convey the meaning of a temporary variable (and you
ignore the other suggestions about not giving meaningful names to variables), you may use a
foreign language word as the name of the variable. For example, instead of using variable "p" for
a "point", you may use "punkt", which is the German word for it. Maintenance coders without
your firm grasp of German will enjoy the multicultural experience of deciphering the meaning. It
breaks the tedium of an otherwise tiring and thankless job.
15.
Consider equals As A Variable Name
Choose variable names that are English versions of operators, to get statements like:

openParen = (slash + asterix) / equals;


16.
Bedazzling Variable Names
Choose all variable names to be words that have no association whatsoever with the actual
function of the program but which have strong inherent meaning as words. For example, you
could end up with statements like:

17.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (3 of 19) [23/03/2005 05:47:00 p.m.]
marypoppins = (julieAndrews + starship) / mailbox;
This confuses the reader because they have difficulty disassociating the concepts of the words
from the logic they're trying to think about. (Combine this with the above method and it's basically
impossible to recover, because search and replace becomes impossible.)
Rename and Reuse
This trick works especially well in Ada, a language immune to many of the standard obfuscation
techniques. The people who originally named all the objects and packages you use were morons.
Rather than try to convince them to change, just use renames and subtypes to rename everything
to names of your own devising. Make sure to leave a few references to the old names in, as a trap
for the unwary.
18.
Reuse Names
Java lets you create methods that have the same name as the class, but that are not constructors.
Exploit this to sow confusion.
19.
When To Use i
Never use i for the innermost loop variable. Use anything but. Use i liberally for any other purpose
especially for non-int variables. Similarly use n as a loop index.
20.
Conventions Schemtions
Ignore the conventions in Java for where to use upper case in variable and class names i.e.
Classes start with upper case, variables with lower case, constants are all upper case, with
internal words capitalised. After all, Sun does (e.g. instanceof vs isInstanceOf, Hashtable). Not to
worry, the compiler won't even issue a warning to give you away. If your boss forces you to use
the conventions, when there is any doubt about whether an internal word should be capitalised,
avoid capitalising or make a random choice, e.g. use both inputFileName and outputfilename. You
can of course drive your team members insane by inventing your own insanely complex naming
conventions then berate others for not following them. The ultimate technique is to create as
many variable names as possible that differ subtlely from each other only in case.
21.
Lower Case l Looks A Lot Like Digit 1
Use lower case l to indicate long constants. e.g. 10l is more likely to be mistaken for 101 that 10L
is.
22.
Reuse of Global Names as Private
Declare a global array in module A, and a private one of the same name in the header file for
module B, so that it appears that it's the global array you are using in module B, but it isn't. Make
no reference in the comments to this duplication.
23.
Recycling Revisited
Use scoping as confusingly as possible by recycling variable names in contradictory ways. For
example, suppose you have global variables A and B, and functions foo and bar. If you know that
variable A will be regularly passed to foo and B to bar, make sure to define the functions as
function foo(B) and function bar(A) so that inside the functions A will always be referred to as B
and vice versa. With more functions and globals, you can create vast confusing webs of mutually
contradictory uses of the same names.
24.
Recycle Your Variables
Wherever scope rules permit, reuse existing unrelated variable names. Similarly, use the same
temporary variable for two unrelated purposes (purporting to save stack slots). For a fiendish
variant, morph the variable, for example, assign a value to a variable at the top of a very long
method, and then somewhere in the middle, change the meaning of the variable in a subtle way,
such as converting it from a 0-based coordinate to a 1-based coordinate. Be certain not to
document this change in meaning.
25.
Cd wrttn wtht vwls s mch trsr
When using abbreviations inside variable or method names, break the boredom with several
26.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (4 of 19) [23/03/2005 05:47:00 p.m.]
variants for the same word, and even spell it out longhand once in while. This helps defeat those
lazy bums who use text search to understand only some aspect of your program. Consider
variant spellings as a variant on the ploy, e.g. mixing International colour, with American color
and dude-speak kulerz. If you spell out names in full, there is only one possible way to spell each
name. These are too easy for the maintenance programmer to remember. Because there are so
many different ways to abbreviate a word, with abbreviations, you can have several different
variables that all have the same apparent purpose. As an added bonus, the maintenance
programmer might not even notice they are separate variables.
Misleading names
Make sure that every method does a little bit more (or less) than its name suggests. As a simple
example, a method named isValid(x) should as a side effect convert x to binary and store the
result in a database.
27.
m_
a naming convention from the world of C++ is the use of "m_" in front of members. This is
supposed to help you tell them apart from methods, so long as you forget that "method" also
starts with the letter "m".
28.
o_apple obj_apple
Use an "o" or "obj" prefix for each instance of the class to show that you're thinking of the big,
polymorphic picture.
29.
Hungarian Notation
Hungarian Notation is the tactical nuclear weapon of source code obfuscation techniques; use it!
Due to the sheer volume of source code contaminated by this idiom nothing can kill a
maintenance engineer faster than a well planned Hungarian Notation attack. The following tips
will help you corrupt the original intent of Hungarian Notation:

30.
Insist on using "c" for const in C++ and other languages that directly enforce the
const-ness of a variable.
Seek out and use Hungarian warts that have meaning in languages other than your current
language. For example insist on the PowerBuilder "l_" and "a_ " {local and argument}
scoping prefixes and always use the VB-esque style of having a Hungarian wart for every
control type when coding to C++. Try to stay ignorant of the fact that megs of plainly visible
MFC source code does not use Hungarian warts for control types.
Always violate the Hungarian principle that the most commonly used variables should
carry the least extra information around with them. Achieve this end through the
techniques outlined above and by insisting that each class type have a custom wart prefix.
Never allow anyone to remind you that no wart tells you that something is a class. The
importance of this rule cannot be overstated: if you fail to adhere to its principles the
source code may become flooded with shorter variable names that have a higher
vowel/consonant ratio. In the worst case scenario this can lead to a full collapse of
obfuscation and the spontaneous reappearance of English Notation in code!
Flagrantly violate the Hungarian-esque concept that function parameters and other high
visibility symbols must be given meaningful names, but that Hungarian type warts all by
themselves make excellent temporary variable names.
Insist on carrying outright orthogonal information in your Hungarian warts. Consider this
real world example: "a_crszkvc30LastNameCol". It took a team of maintenance engineers
nearly 3 days to figure out that this whopper variable name described a const, reference,
function argument that was holding information from a database column of type
Varchar[30] named "LastName" which was part of the table's primary key. When properly
combined with the principle that "all variables should be public" this technique has the
power to render thousands of lines of source code obsolete instantly!
Use to your advantage the principle that the human brain can only hold 7 pieces of
information concurrently. For example code written to the above standard has the following
properties:

A single assignment statement carries 14 pieces of type and name information.


How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (5 of 19) [23/03/2005 05:47:00 p.m.]
A single function call that passes three parameters and assigns a result carries 29 pieces
of type and name information.
Seek to improve this excellent, but far too concise, standard. Impress management and
coworkers by recommending a 5 letter day of the week prefix to help isolate code written
on 'Monam' and 'FriPM'.
It is easy to overwhelm the short term memory with even a moderately complex nesting
structure, especially when the maintenance programmer can't see the start and end of each
block on screen simultaneously.

Hungarian Notation Revisited


One follow on trick in the Hungarian notation is "change the type of a variable but leave the
variable name unchanged". This is almost invariably done in windows apps with the migration
from Win16 :- WndProc(HWND hW, WORD wMsg, WORD wParam, LONG lParam) to Win32
WndProc(HWND hW, UINT wMsg, WPARAM wParam, LPARAM lParam) where the w values hint
that they are words, but they really refer to longs. The real value of this approach comes clear
with the Win64 migration, when the parameters will be 64 bits wide, but the old "w" and "l"
prefixes will remain forever.
1.
Obscure film references
Use constant names like LancelotsFavouriteColour instead of blue and assign it hex value of
$0204FB. The color looks identical to pure blue on the screen, and a maintenance programmer
would have to work out 0204FB (or use some graphic tool) to know what it looks like. Only
someone intimately familiar with Monty Python and the Holy Grail would know that Lancelot's
favorite color was blue. If a maintenance programmer can't quote entire Monty Python movies
from memory, he or she has no business being a programmer.
2.
Camouflage
The longer it takes for a bug to surface, the harder it is to find.
Roedy
Much of the skill in writing unmaintainable code is the art of camouflage, hiding things, or making
things appear to be what they are not. Many depend on the fact the compiler is more capable at making
fine distinctions than either the human eye or the text editor. Here are some of the best camouflaging
techniques.

Code That Masquerades As Comments and Vice Versa


Include sections of code that is commented out but at first glance does not appear to be.

for(j=0; j<array_len; j+ =8)


{
total += array[j+0 ];
total += array[j+1 ];
total += array[j+2 ]; /* Main body of
total += array[j+3]; * loop is unrolled
total += array[j+4]; * for greater speed.
total += array[j+5]; */
total += array[j+6 ];
total += array[j+7 ];
}
Without the colour coding would you notice that three lines of code are commented out?
1.
Arbitrary Names That Masquerade as Keywords
When documenting, and you need an arbitrary name to represent a filename use "file ". Never use
an obviously arbitrary name like "Charlie.dat" or "Frodo.txt". In general, in your examples, use
arbitrary names that sound as much like reserved keywords as possible. For example, good
names for parameters or variables would be: "bank", "blank", "class", "const ", "constant",
"input", "key", "keyword", "kind", "output", "parameter" "parm", "system", "type", "value", "var"
2.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (6 of 19) [23/03/2005 05:47:00 p.m.]
and "variable ". If you use actual reserved words for your arbitrary names, which would be
rejected by your command processor or compiler, so much the better. If you do this well, the
users will be hopelessly confused between reserved keywords and arbitrary names in your
example, but you can look innocent, claiming you did it to help them associate the appropriate
purpose with each variable.
Code Names Must Not Match Screen Names
Choose your variable names to have absolutely no relation to the labels used when such
variables are displayed on the screen. E.g. on the screen label the field "Postal Code" but in the
code call the associated variable "zip".
3.
How to Hide Forbidden Globals
Since global variables are "evil", define a structure to hold all the things you'd put in globals. Call
it something clever like EverythingYoullEverNeed. Make all functions take a pointer to this
structure (call it handle to confuse things more). This gives the impression that you're not using
global variables, you're accessing everything through a "handle". Then declare one statically so
that all the code is using the same copy anyway.
4.
Long Similar Variable Names
Use very long variable names or class names that differ from each other by only one character, or
only in upper/lower case. An ideal variable name pair is swimmer and swimner. Exploit the failure
of most fonts to clearly discriminate between ilI1| or oO08 with identifier pairs like parselnt and
parseInt or D0Calc and DOCalc. l is an exceptionally fine choice for a variable name since it will,
to the casual glance, masquerade as the constant 1. In many fonts rn looks like an m. So how
about a variable swirnrner. Create variable names that differ from each other only in case e.g.
HashTable and Hashtable.
5.
Similar-Sounding Similar-Looking Variable Names
Although we have one variable named xy_z, there's certainly no reason not to have many other
variables with similar names, such as xy_Z, xy__z, _xy_z, _xyz, XY_Z, xY_z, and Xy_z.
Variables that resemble others except for capitalization and underlines have the advantage of
confounding those who like remembering names by sound or letter-spelling, rather than by exact
representations.
6.
Documentation
Any fool can tell the truth, but it requires a man of some sense to know how to lie well.
Samuel Butler (1835 - 1902)

Incorrect documentation is often worse than no documentation.


Bertrand Meyer
Since the computer ignores comments and documentation, you can lie outrageously and do everything
in your power to befuddle the poor maintenance programmer.
Lie in the comments
You don't have to actively lie, just fail to keep comments as up to date with the code.

1.
Document the obvious
Pepper the code with comments like /* add 1 to i */ however, never document wooly stuff like the
overall purpose of the package or method.

2.
Avoid Documenting the "Obvious"
If, for example, you were writing an airline reservation system, make sure there are at least 25
places in the code that need to be modified if you were to add another airline. Never document
where they are. People who come after you have no business modifying your code without
thoroughly understanding every line of it.

3.
On the Proper Use Of Documentation Templates
Consider function documentation prototypes used to allow automated documentation of the
code. These prototypes should be copied from one function (or method or class) to another, but
4.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (7 of 19) [23/03/2005 05:47:00 p.m.]
never fill in the fields. If for some reason you are forced to fill in the fields make sure that all
parameters are named the same for all functions, and all cautions are the same but of course not
related to the current function at all.

On the Proper Use of Design Documents


When implementing a very complicated algorithm, use the classic software engineering principles
of doing a sound design before beginning coding. Write an extremely detailed design document
that describes each step in a very complicated algorithm. The more detailed this document is, the
better.
In fact, the design doc should break the algorithm down into a hierarchy of structured steps,
described in a hierarchy of auto-numbered individual paragraphs in the document. Use headings
at least 5 deep. Make sure that when you are done, you have broken the structure down so
completely that there are over 500 such auto-numbered paragraphs. For example, one paragraph
might be: (this is a real example)
1.2.4.6.3.13 - Display all impacts for activity where selected mitigations can apply (short
pseudocode omitted).
then... (and this is the kicker) when you write the code, for each of these paragraphs you write a
corresponding global function named:

Act1_2_4_6_3_13()
Do not document these functions. After all, that's what the design document is for!
Since the design doc is auto-numbered, it will be extremely difficult to keep it up to date with
changes in the code (because the function names, of course, are static, not auto-numbered.) This
isn't a problem for you because you will not try to keep the document up to date. In fact, do
everything you can to destroy all traces of the document.
Those who come after you should only be able to find one or two contradictory, early drafts of the
design document hidden on some dusty shelving in the back room near the dead 286 computers.

5.
Gotchas
Never document gotchas in the code. If you suspect there may be a bug in a class, keep it to
yourself. If you have ideas about how the code should be reorganised or rewritten, for heaven's
sake, do not write them down. Remember the words of Thumper in the movie Bambi "If you can't
say anything nice, don't say anything at all". What if the programmer who wrote that code saw
your comments? What if the owner of the company saw them? What if a customer did? You could
get yourself fired. An anonymous comment that says "This needs to be fixed!" can do wonders,
especially if it's not clear what the comment refers to. Keep it vague, and nobody will feel
personally criticized.

6.
Documenting Variables
Neverput a comment on a variable. Facts about how the variable is used, its bounds, its legal
values, its implied/displayed number of decimal points, its units of measure, its display format, its
data entry rules (e.g. total fill, must enter), when its value can be trusted etc. should be gleaned
from the procedural code. If your boss forces you to write comments, lard method bodies with
them, but never comment a variable, not even a temporary!

7.
Disparage In the Comments
Discourage any attempt to use external maintenance contractors by peppering your code with
insulting references to other leading software companies, especial anyone who might be
contracted to do the work. e.g.:

/* The optimised inner loop.


This stuff is too clever for the dullard at Software Services Inc., who would
probably use 50 times as memory & time using the dumb routines in .
8.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (8 of 19) [23/03/2005 05:47:00 p.m.]
*/
class clever_SSInc

{
.. .
}

If possible, put insulting stuff in syntactically significant parts of the code, as well as just the
comments so that management will probably break the code if they try to sanitize it before
sending it out for maintenance.

COMMENT AS IF IT WERE CBL ON PUNCH CARDS


Always refuse to accept advances in the development environment arena. Disbelieve rumors that
all functions and variables are never more than one click away and always assume that code
developed in Visual Studio 6.0 will be maintained by someone using edlin or vi. To this end insist
on Draconian commenting rules that bury the source code.

9.
Monty Python Comments
On a method called makeSnafucatedinsert only the comment /* make snafucated */. Never define
what snafucatedmeans anywhere. Only a fool does not already know, with complete certainty,
what snafucated means. For classic examples of this technque, consult the Sun AWT JavaDOC.
10.

Program Design
The cardinal rule of writing unmaintainable code is to specify each fact in as many places
as possible and in as many ways as possible.
Roedy

The key to writing maintainable code is to specify each fact about the application in only one
place. To change your mind, you need change it in only one place, and you are guaranteed the
entire program will still work. Therefore, the key to writing unmaintainable code is to specify a
fact over and over, in as many places as possible, in as many variant ways as possible. Happily,
languages like Java go out of their way to make writing this sort of unmaintainable code easy. For
example, it is almost impossible to change the type of a widely used variable because all the
casts and conversion functions will no longer work, and the types of the associated temporary
variables will no longer be appropriate. Further, if the variable is displayed on the screen, all the
associated display and data entry code has to be tracked down and manually modified. The Algol
family of languages which include C and Java treat storing data in an array, Hashtable, flat file
and database with totally different syntax. In languages like Abundance, and to some extent
Smalltalk, the syntax is identical; just the declaration changes. Take advantage of Java's
ineptitude. Put data you know will grow too large for RAM, for now into an array. That way the
maintenance programmer will have a horrendous task converting from array to file access later.
Similarly place tiny files in databases so the maintenance programmer can have the fun of
converting them to array access when it comes time to performance tune.

1.
Never Validate
Never check input data for any kind of correctness or discrepancies. It will demonstrate that you
absolutely trust the company's equipment as well as that you are a perfect team player who trusts
all project partners and system operators. Always return reasonable values even when data
inputs are questionable or erroneous.

2.
Be polite, Never Assert
Avoid the assert() mechanism, because it could turn a three-day debug fest into a ten minute one.
3.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (9 of 19) [23/03/2005 05:47:00 p.m.]

Avoid Encapsulation
In the interests of efficiency, avoid encapsulation. Callers of a method need all the external clues
they can get to remind them how the method works inside.

4.
Clone & Modify
In the name of efficiency, use cut/paste/clone/modify. This works much faster than using many
small reusable modules. This is especially useful in shops that measure your progress by the
lines of code you've written.

5.
Use Static Arrays
If a module in a library needs an array to hold an image, just define a static array. Nobody will
ever have an image bigger than 512 x 512, so a fixed-size array is OK. For best precision, make it
an array of doubles. Bonus effect for hiding a 2 Meg static array which causes the program to
exceed the memory of the client's machine and thrash like crazy even if they never use your
routine.

6.
Dummy Interfaces
Write an empty interface called something like "WrittenByMe", and make all of your classes
implement it. Then, write wrapper classes for any of Java's built-in classes that you use. The idea
is to make sure that every single object in your program implements this interface. Finally, write
all methods so that both their arguments and return types are WrittenByMe. This makes it nearly
impossible to figure out what some methods do, and introduces all sorts of entertaining casting
requirements. For a further extension, have each team member have his/her own personal
interface (e.g., WrittenByJoe); any class worked on by a programmer gets to implement his/her
interface. You can then arbitrary refer to objects by any one of a large number of meaningless
interfaces!

7.
Use Three Dimensional Arrays
Lots of them. Move data between the arrays in convoluted ways, say, filling the columns in arrayB
with the rows from arrayA. Doing it with an offset of 1, for no apparent reason, is a nice touch.
Makes the maintenance programmer nervous.

8.
Wrap, wrap, wrap
Whenever you have to use methods in code you did not write, insulate your code from that other
dirty code by at least one layer of wrapper. After all, the other author might some time in the
future recklessly rename every method. Then where would you be? You could of course, if he did
such a thing, insulate your code from the changes by writing a wrapper or you could let VAJ
handle the global rename. However, this is the perfect excuse to preemptively cut him off at the
pass with a wrapper layer of indirection, before he does anything idiotic. One of Java's main
faults is that there is no way to solve many simple problems without dummy wrapper methods
that do nothing but call another method of the same name, or a closely related name. This means
it is possible to write wrappers four-levels deep that do absolutely nothing, and almost no one will
notice. To maximise the obscuration, at each level, rename the methods, selecting random
synonyms from a thesaurus. This gives the illusion something of note is happening. Further, the
renaming helps ensure the lack of consistent project terminology. To ensure no one attempts to
prune your levels back to a reasonable number, invoke some of your code at the application level
via each of the levels.

9.
Wrap Wrap Wrap Some More
Make sure all API functions are wrapped at least 6-8 times, with function definitions in separate
source files.

10.
No Secrets!
Declare every method and variable public. After all, somebody, sometime might want to use it.
11.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (10 of 19) [23/03/2005 05:47:00 p.m.]
Once a method has been declared public, it can't very well be retracted, now can it? This makes it
very difficult to later change the way anything works under the covers. It also has the delightful
side effect of obscuring what a class is for. If the boss asks if you are out of your mind, tell him
you are following the classic principles of transparent interfaces.

The Kama Sutra


This technique has the added advantage of driving any users or documenters of the package to
distraction as well as the maintenance programmers. Create a dozen overloaded variants of the
same method that differ in only the most minute detail. I think it was Oscar Wilde who observed
that positions 47 and 115 of the Kama Sutra were the same except in 115 the woman had her
fingers crossed. Users of the package then have to carefully peruse the long list of methods to
figure out just which variant to use. The technique also balloons the documentation and thus
ensures it will more likely be out of date. If the boss asks why you are doing this, explain it is
solely for the convenience of the users. Again for the full effect, clone any common logic and sit
back and wait for it the copies to gradually get out of sync.

12.
Permute and Baffle
Reverse the parameters on a method called drawRectangle(height, width) to
drawRectangle(width, height) without making any change whatsoever to the name of the method.
Then a few releases later, reverse it back again. The maintenance programmers can't tell by
quickly looking at any call if it has been adjusted yet. Generalisations are left as an exercise for
the reader.

13.
Theme and Variations
Instead of using a parameter to a single method, create as many separate methods as you can.
For example instead of setAlignment(int alignment) where alignment is an enumerated constant,
for left, right, center, create three methods: setLeftAlignment, setRightAlignment, and
setCenterAlignment. Of course, for the full effect, you must clone the common logic to make it
hard to keep in sync.

14.
Cargill's Quandry
Take advantage of Cargill's quandary (I think this was his): "any design problem can be solved by
adding an additional level of indirection, except for too many levels of indirection." Decompose
OO programs until it becomes nearly impossible to find a method which actually updates
program state. Better yet, arrange all such occurrences to be activated as callbacks from by
traversing pointer forests which are known to contain every function pointer used within the
entire system. Arrange for the forest traversals to be activated as side-effects from releasing
reference counted objects previously created via deep copies which aren't really all that deep.

15.
Packratting
Keep all of your unused and outdated methods and variables around in your code. After all - if
you needed to use it once in 1976, who knows if you will want to use it again sometime? Sure the
program's changed since then, but it might just as easily change back, you "don't want to have to
reinvent the wheel" (supervisors love talk like that). If you have left the comments on those
methods and variables untouched, and sufficiently cryptic, anyone maintaining the code will be
too scared to touch them.

16.
The Magic Of Global Variables
The use of global variables is so obvious that no one thought to mention it until this point.
Instead of using exceptions to handle error processing, have your error message routine set a
global variable. Then make sure that every long-running loop in the system checks this global
flag and terminates if an error occurs. Add another global variable to signal when a user presses
the 'reset' button. Of course all the major loops in the system also have to check this second flag.
Hide a few loops that don't terminate on demand.

17.
Globals, We Can't Stress These Enough! 18.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (11 of 19) [23/03/2005 05:47:00 p.m.]
If God didn't want us to use global variables, he wouldn't have invented them. Rather than
disappoint God, use and set as many global variables as possible. Each function should use and
set at least two of them, even if there's no reason to do this. After all, any good maintenance
programmer will soon figure out this is an exercise in detective work, and she'll be happy for the
exercise that separates real maintenance programmers from the dabblers.

Globals, One More Time, Boys


Global variables save you from having to specify arguments in functions. Take full advantage of
this. Elect one or more of these global variables to specify what kinds of processes to do on the
others. Maintenance programmers foolishly assume that C functions will not have side effects.
Make sure they squirrel results and internal state information away in global variables.

19.
Local Variables
Never use local variables. Whenever you feel the temptation to use one, make it into an instance
or static variable instead to unselfishly share it with all the other methods of the class. This will
save you work later when other methods need similar declarations. C++ programmers can go a
step further by making all variables global.

20.
Bloated classes
To ensure your classes are bounded in the most obtuse way possible, make sure you include
peripheral, obscure methods and attributes in every class. For example, a class that defines
astrophysical orbit geometry really should have a method that computes ocean tide schedules
and attributes that comprise a Crane weather model. Not only does this over-define the class, it
makes finding these methods in the general system code like looking for a guitar pick in a landfill.

21.
Testing
I don't need to test my programs. I have an error-correcting modem.
Om I. Baud
Leaving bugs in your programs gives the maintenance programmer who comes along later something
interesting to do. A well done bug should leave absolutely no clue as to when it was introduced or
where. The laziest way to accomplish this is simply never to test your code.
Never Test
Never test any code that handles the error cases, machine crashes, or OS glitches. Never check
return codes from the OS. That code never gets executed anyway and slows down your test
times. Besides, how can you possibly test your code to handle disk errors, file read errors, OS
crashes, and all those sorts of events? Why, you would have to either an incredibly unreliable
computer or a test scaffold that mimicked such a thing. Modern hardware never fails, and who
wants to write code just for testing purposes? It isn't any fun. If users complain, just blame the
OS or hardware. They'll never know.

1.
Never, Ever Do Any Performance Testing
Hey, if it isn't fast enough, just tell the customer to buy a faster machine. If you did do
performance testing, you might find a bottleneck, which might lead to algorithm changes, which
might lead to a complete redesign of your product. Who wants that? Besides, performance
problems that crop up at the customer site mean a free trip for you to some exotic location. Just
keep your shots up-to-date and your passport handy.

2.
Never Write Any Test Cases
Never perform code coverage or path coverage testing. Automated testing is for wimps. Figure
out which features account for 90% of the uses of your routines, and allocate 90% of the tests to
those paths. After all, this technique probably tests only about 60% of your source code, and you
have just saved yourself 40% of the test effort. This can help you make up the schedule on the
back-end of the project. You'll be long gone by the time anyone notices that all those nice
"marketing features" don't work. The big, famous software companies test code this way; so
should you. And if for some reason, you are still around, see the next item.
3.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (12 of 19) [23/03/2005 05:47:00 p.m.]

Testing is for cowards


A brave coder will bypass that step. Too many programmers are afraid of their boss, afraid of
losing their job, afraid of customer hate mail and afraid of being sued. This fear paralyzes action,
and reduces productivity. Studies have shown that eliminating the test phase means that
managers can set ship dates well in advance, an obvious aid in the planning process. With fear
gone, innovation and experimentation can blossom. The role of the programmer is to produce
code, and debugging can be done by a cooperative effort on the part of the help desk and the
legacy maintenance group.
If we have full confidence in our coding ability, then testing will be unnecessary. If we look at this
logically, then any fool can recognize that testing does not even attempt to solve a technical
problem, rather, this is a problem of emotional confidence. A more efficient solution to this lack of
confidence issue is to eliminate testing completely and send our programmers to self-esteem
courses. After all, if we choose to do testing, then we have to test every program change, but we
only need to send the programmers to one course on building self-esteem. The cost benefit is as
amazing as it is obvious.

4.
Ensuring It Only Works In Debug Mode
If you've defined TESTING as 1

#define TESTING 1
this gives you the wonderful opportunity to have separate code sections, such as

#if TESTING==1
#endif
which can contain such indispensable tidbits as

x = rt_val;
so that if anyone resets TESTING to 0, the program won't work. And with the tiniest bit of
imaginative work, it will not only befuddle the logic, but confound the compiler as well.
5.
Choice Of Language
Philosophy is a battle against the bewitchment of our intelligence by means of language.
Ludwig Wittgenstein
Computer languages are gradually evolving to become more fool proof. Using state of the art languages
is unmanly. Insist on using the oldest language you can get away with, octal machine language if you
can (Like Hans und Frans, I am no girlie man; I am so virile I used to code by plugging gold tipped wires
into a plugboard of IBM unit record equipment (punch cards), or by poking holes in paper tape with a
hand punch), failing that assembler, failing that FORTRAN or COBOL, failing that C, and BASIC, failing
that C++.
FRTRAN
Write all your code in FORTRAN. If your boss ask why, you can reply that there are lots of very
useful libraries that you can use thus saving time. However the chances of writing maintainable
code in FORTRAN are zero, and therefore following the unmaintainable coding guidelines is a lot
easier.

1.
Avoid Ada
About 20% of these techniques can't be used in Ada. Refuse to use Ada. If your manager presses
you, insist that no-one else uses it, and point out that it doesn't work with your large suite of tools
like lint and plummer that work around C's failings.

2.
Use ASM 3.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (13 of 19) [23/03/2005 05:47:00 p.m.]
Convert all common utility functions into asm.

Use QBASIC
Leave all important library functions written in QBASIC, then just write an asm wrapper to handle
the large->medium memory model mapping.

4.
Inline Assembler
Sprinkle your code with bits of inline assembler just for fun. Almost no one understands
assembler anymore. Even a few lines of it can stop a maintenance programmer cold.

5.
MASM call C
If you have assembler modules which are called from C, try to call C back from the assembler as
often as possible, even if it's only for a trivial purpose and make sure you make full use of the
goto, bcc and other charming obfuscations of assembler.
6.
Dealing With Others
Hell is other people.
Jean-Paul Sartre -- No Exit 1934
There are many hints sprinkled thoroughout the tips above on how to rattle maintenance programmers
though frustration, and how to foil your boss's attempts to stop you from writing unmaintainable code,
or even how to foment an RWAR that involves everyone on the topic of how code should be formatted
in the repository.
Your Boss Knows Best
If your boss thinks that his or her 20 year old FORTRAN experience is an excellent guide to
contemporary programming, rigidly follow all his or her recommendations. As a result, the boss
will trust you. That may help you in your career. You will learn many new methods to obfuscate
program code.

1.
Subvert The Help Desk
One way to help ensure the code is full of bugs is to ensure the maintenance programmers never
hear about them. This requires subverting the help desk. Never answer the phone. Use an
automated voice that says "thank you for calling the helpline. To reach a real person press "1" or
leave a voice mail wait for the tone". Email help requests should be ignored other than to assign
them a tracking number. The standard response to any problem is " I think your account is locked
out. The person able to authorise reinstatement is not available just now."

2.
Keep Your Mouth Shut
Be never vigilant of the next Y2K. If you ever spot something that could sneak up on a fixed
deadline and destroy all life in the western hemisphere then do not openly discuss it until we are
under the critical 4 year till event window of panic and opportunity. Do not tell friends, coworkers,
or other competent people of your discovery. Under no circumstances attempt to publish
anything that might hint at this new and tremendously profitable threat. Do send one normal
priority, jargon encrypted, memo to upper management to cover-your-a$$. If at all possible attach
the jargon encrypted information as a rider on an otherwise unrelated plain-text memo pertaining
to a more immediately pressing business concern. Rest assured that we all see the threat too.
Sleep sound at night knowing that long after you've been forced into early retirement you will be
begged to come back at a logarithmically increased hourly rate!

3.
Baffle 'Em With Bullshit
Subtlety is a wonderful thing, although sometimes a sledge-hammer is more subtle than other
tools. So, a refinement on misleading comments: create classes with names like FooFactory
containing comments with references to the GoF creational patterns (ideally with http links to
bogus UML design documents) that have nothing to do with object creation. Play off the
maintainer's delusions of competence. More subtly, create Java classes with protected
4.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (14 of 19) [23/03/2005 05:47:00 p.m.]
constructors and methods like Foo f = Foo.newInstance()that return actual new instances, rather
than the expected singleton. The opportunities for side-effects are endless.

Book Of The Month Club


Join a computer book of the month club. Select authors who appear to be too busy writing books
to have had any time to actually write any code themselves. Browse the local bookstore for titles
with lots of cloud diagrams in them and no coding examples. Skim these books to learn obscure
pedantic words you can use to intimidate the whippersnappers that come after you. Your code
should impress. If people can't understand your vocabulary, they must assume that you are very
intelligent and that your algorithms are very deep. Avoid any sort of homely analogies in your
algorithm explanations.
5.
Tricks In Offbeat Languages
Programming in Basic causes brain damage.
Edsger Wybe Dijkstra
SQL Aliasing
Alias table names to one or two letters. Better still alias them to the names of other unrelated
existing tables.

G
SQL Outer Join
Mix the various flavours of outer join syntax just to keep everyone on their toes.

G
JavaScript Scope
"Optimise" JavaScript code taking advantage of the fact a function can access all local variables
in the scope of the caller.

G
Visual Basic Declarations
Instead of:

dim Count_num as string


dim Color_var as string
dim counter as integer
use:

Dim Count_num$, Color_var$, counter%

G
Visual Basic Madness
If reading from a text file, read 15 characters more than you need to then embed the actual text
string like so:

ReadChars = .ReadChars (29,0)


ReadChar = trim(left(mid(ReadChar,len(ReadChar)-15,len(ReadChar)-5),7))
If ReadChars = "alongsentancewithoutanyspaces"
Mid,14,24 = "withoutanys"
and left,5 = "without"

G
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (15 of 19) [23/03/2005 05:47:00 p.m.]
Miscellaneous Techniques
If you give someone a program, you will frustrate them for a day; if you teach them
how to program, you will frustrate them for a lifetime.
Anonymous

Don't Recompile
Let's start off with probably the most fiendish technique ever devised: Compile the code to
an executable. If it works, then just make one or two small little changes in the source
code...in each module. But don't bother recompiling these. You can do that later when you
have more time, and when there's time for debugging. When the hapless maintenance
programmer years later makes a change and the code no longer works, she will
erroneously assume it must be something she recently changed. You will send her off on a
wild goose chase that will keep her busy for weeks.

CANI
Constant And Never-ending Improvement. Make "improvements" to your code often, and
force users to upgrade often - after all, no one wants to be running an outdated version.
Just because they think they're happy with the program as it is, just think how much
happier they will be after you've "fixed" it! Don't tell anyone what the differences between
versions are unless you are forced to - after all, why tell someone about bugs in the old
version they might never have noticed otherwise?

1.
About Box
The About Box should contain only the name of the program, the names of the coders and
a copyright notice written in legalese. Ideally it should link to several megs of code that
produce an entertaining animated display. However, it should never contain a description
of what the program is for, its minor version number, or the date of the most recent code
revision, or the website where to get the updates, or the author's email address. This way
all the users will soon all be running on different versions, and will attempt to install
version N+2 before installing version N+1.

2.
Ch ch ch Changes
The more changes you can make between versions the better, you don't want users to
become bored with the same old API or user interface year after year. Finally, if you can
make this change without the users noticing, this is better still - it will keep them on their
toes, and keep them from becoming complacent.

3.
No Skill Required
You don't need great skill to write unmaintainable code. Just leap in and start coding. Keep
in mind that management still measures productivity in lines of code even if you have to
delete most of it later.

4.
Carry Only One Hammer
Stick with what you know and travel light; if you only carry a hammer then all problems are
nails.

5.
Standards Schmandards
Whenever possible ignore the coding standards currently in use by thousands of
developers in your project's target language and environment. For example insist on STL
style coding standards when writing an MFC based application.

6.
Third Party Libraries 7.
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (16 of 19) [23/03/2005 05:47:00 p.m.]
Include powerful third party libraries in your project and then don't use them. With practice
you can remain completely ignorant of good tools and add the unused tools to your resume
in your "Other Tools" section.

Avoid Libraries
Feign ignorance of libraries that are directly included with your development tool. If coding
in Visual C++ ignore the presence of MFC or the STL and code all character strings and
arrays by hand; this helps keep your pointer skills sharp and it automatically foils any
attempts to extend the code.

8.
Collect Coding Standards
Find all the tips you can on writing maintainable code such as these ones the Square Box
Suggestions and flagrantly violate them.

9.
Combine Bug Fixes With Upgrades
Never put out a "bug fix only" release. Be sure to combine bug fixes with database format
changes, complex user interface changes, and complete rewrites of the administration
interfaces. That way, it will be so hard to upgrade that people will get used to the bugs and
start calling them features. And the people that really want these "features" to work
differently will have an incentive to upgrade to the new versions. This will save you
maintenance work in the long run, and get you more revenue from your customers.

10.
Change File Formats With Each Release Of Your Product
Yeah, your customers will demand upwards compatibility, so go ahead and do that. But
make sure that there is no backwards compatibility. That will prevent customers from
backing out the newer release, and coupled with a sensible bug fix policy (see above), will
guarantee that once on a newer release, they will stay there. Extra bonus points: Figure out
how to get the old version to not even recognize files created by the newer versions. That
way, they not only can't read them, they will deny that they are even created by the same
application! Hint: PC word processors provide a useful example of this sophisticated
behaviour.

11.
Compensate For Bugs
Don't worry about finding the root cause of bugs in the code. Simply put in compensating
code in the higher-level routines. This is a great intellectual exercise, akin to 3D chess, and
will keep future code maintainers entertained for hours as they try to figure out whether the
problem is in the low-level routines that generate the data or in the high-level routines that
change various cases all around. This technique is great for compilers, which are
inherently multi-pass programs. You can completely avoid fixing problems in the early
passes by simply making the later passes more complicated. With luck, you will never have
to speak to the little snot who supposedly maintains the front-end of the compiler. Extra
bonus points: make sure the back-end breaks if the front-end ever generates the correct
data.

12.
It's The Size That Counts
It almost goes without saying that the larger a function is, the better it is. And the more
jumps and GOTOs the better. That way, any change must be analysed through many
scenarios. It snarls the maintenance programmer in the spaghettiness of it all. And if the
function is truly gargantuan, it becomes the Godzilla of the maintenance programmers,
stomping them mercilessly to the ground before they have an idea of what's happened.

13.
A Picture is a 1000 Words; A Function is 1000 Lines
Make the body of every method as long as possible - hopefully you never write any
methods or functions with fewer than a thousand lines of code, deeply nested, of course.
14.
Philosophy
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (17 of 19) [23/03/2005 05:47:00 p.m.]
The people who design languages are the people who write the compilers and system classes.
Quite naturally they design to make their work easy and mathematically elegant. However, there
are 10,000 maintenance programmers to every compiler writer. The grunt maintenance
programmers have absolutely no say in the design of languages. Yet the total amount of code
they write dwarfs the code in the compilers.
An example of the result of this sort of elitist thinking is the JDBC interface. It makes life easy for
the JDBC implementor, but a nightmare for the maintenance programmer. It is far clumsier than
the FORTRAN interface that came out with SQL three decades ago.
Maintenance programmers, if somebody ever consulted them, would demand ways to hide the
housekeeping details so they could see the forest for the trees. They would demand all sorts of
shortcuts so they would not have to type so much and so they could see more of the program at
once on the screen. They would complain loudly about the myriad petty time-wasting tasks the
compilers demand of them.
There are some efforts in this direction: NetRexx, Bali, and visual editors (e.g. IBM's Visual Age is
a start) that can collapse detail irrelevant to the current purpose.

The Shoemaker Has No Shoes


Imagine having an accountant as a client who insisted on maintaining his general ledgers using a
word processor. You would do you best to persuade him that his data should be structured. He
needs validation with cross field checks. You would persuade him he could do so much more
with that data when stored in a database, including controlled simultaneous update.
Imagine taking on a software developer as a client. He insists on maintaining all his data with a
text editor. He is not yet even exploiting the word processor's colour, type size or fonts.
Think of what might happen if we started storing source code as structured data. We could view
the same source code in many alternate ways, e.g. as Java, as NextRex, as a decision table, as a
flow chart, as a loop structure skeleton (with the detail stripped off), as Java with various levels of
detail or comments removed, as Java with highlights on the variables and method invocations of
current interest, or as Java with generated comments about argument names and/or types. We
could display complex arithmetic expressions in 2D, the way TeX and mathematicians do. You
could see code with additional or fewer parentheses, (depending on how comfortable you feel
with the precedence rules ). Parenthesis nests could use varying size and colour to help matching
by eye. With changes as transparent overlay sets that you can optionally remove or apply, you
could watch in real time as other programmers on your team, working in a different country,
modified code in classes that you were working on too.
You could use the full colour abilities of the modern screen to give subliminal clues, e.g. by
automatically assigning a portion of the spectrum to each package/class using a pastel shades as
the backgrounds to any references to methods or variables of that class. You could bold face the
definition of any identifier to make it stand out.
You could ask what methods/constructors will produce an object of type X? What methods will
accept an object of type X as a parameter? What variables are accessible in this point in the
code? By clicking on a method invocation or variable reference, you could see its definition,
helping sort out which version of a given method will actually be invoked. You could ask to
globally visit all references to a given method or variable, and tick them off once each was dealt
with. You could do quite a bit of code writing by point and click.
Some of these ideas would not pan out. But the best way to find out which would be valuable in
practice is to try them. Once we had the basic tool, we could experiment with hundreds of similar
ideas to make life easier for the maintenance programmer.

How To Write Unmaintainable Code


http://www.afralisp.com/vbaa/unmain.htm (18 of 19) [23/03/2005 05:47:00 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
How To Write Unmaintainable Code
http://www.afralisp.com/vbaa/unmain.htm (19 of 19) [23/03/2005 05:47:00 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Shadow Control
Would you like to place shadows on your controls?
Would you like to give your forms a 3D appearance?
The here we go......

'coding starts here


Option Explicit
Public Sub Shadow(f As Form, c As Control, clr As Long)
'This SubRoutine draws a shadow below and to the
'the right of a control. It's quite a simple example
'of drawing in form !
'Example : Shadow Me,Text1,vbBlack
Const shWidth = 3 'Width of the shadow
Dim oldWidth As Integer 'Save old DrawWidth
Dim oldScale As Integer 'Save old ScaleMode
f.AutoRedraw = True 'optional, but otherwise
'shadow won't remain when form is repainted
'or call from the Form_Paint() sub
oldWidth = f.DrawWidth 'Remember current DrawWidth
oldScale = f.ScaleMode 'Remember current ScaleMode
f.ScaleMode = 3 'Set to pixel scaling
f.DrawWidth = 1 '1 pixel width lines
'Draws the shadow by drawing a box behind the control
f.Line (c.Left + shWidth, c.Top + shWidth)- _
Step(c.Width - 1, c.Height - 1), clr, BF
f.DrawWidth = oldWidth 'Restore old DrawWidth
Shadow Control
http://www.afralisp.com/vba/shadow.htm (1 of 2) [23/03/2005 05:47:02 p.m.]
f.ScaleMode = oldScale 'Restore old ScaleMode
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Shadow Me, Label1, vbBlack
Shadow Me, Text1, vbBlack
Shadow Me, Command1, vbBlack
Shadow Me, Command2, vbBlack
End Sub
'coding ends here
Download source coding here.

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Shadow Control
http://www.afralisp.com/vba/shadow.htm (2 of 2) [23/03/2005 05:47:02 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Custom Application Setup
You've written your AutoLisp and VBA routines, you've set up your Block Libraries and your Custom
Partial Menu is now complete. Everything has been tested but now you hit another snag. You'd like to
distribute your custom application to other drawing officers, or maybe you have 50 machines in your
office that you would like to install it on but you have one big problem. Having to set up each individual
machine is a real pain. There are directories to be created, support paths to be added, menu's to be
loaded, etc, etc. And if you are distributing it outside the office, you now have to try and put your setup
into words that can be clearly understood by the poor guy on the other end.
In this tutorial we are going to have a look at automating the whole process. We are going to make use
of two remarkable software applications that will make this a breeze, namely "Inno Setup" and "Acad
Install".
"Inno Setup" will be used to install our required support files, and "Acad Install" will do the job of
configuring AutoCAD for us, all with a lovely user interface.
Firstly though, we have a bit of forward planning to do before we start compiling our Custom
Application Setup.
Step 1
All your programs, menu's, etc. must be fully tested and free of errors. Test them on as many operating
systems and AutoCAD versions as possible to ensure they are bug free.
Step 2
Create a dedicated folder, with sub-folders for your application. The example we will be using here looks
like this :
This is a very simple directory structure with only three sub-folders. You can though, create as many as
you wish to suit your needs. Oh, before I forget, all your files need to be placed within these folders
AND, now this is important, if you want to install a partial menu, this MUST reside in the root folder. eg.
afralisp2004_install.
Step 3
Now we need to download some software. Pop along to both of these sites and download the latest
version of "Inno Setup" and "Acad Install".
Inno Setup
Jordan Russell's Software - http://www.jrsoftware.org
Acad Install
Custom Application Setup
http://www.afralisp.com/lisp/install1.htm (1 of 4) [23/03/2005 05:47:06 p.m.]
CADWERX - http://www.cadwerx.net/
Don't worry, they are both absolutely FREE.
Once you've download both applications install "Inno Setup" first.
Then install "Acad Install" to any directory of your choosing OTHER THAN your Application folder. Now,
from this directory, copy "ACADINST.EXE" and "ACADINST.INI" to the root folder of your Application
eg. afralisp2004_install. Do not copy "ACADINST.CHM" as we do not want to include this in our
compiled setup file.
In fact, now is maybe a good time to have a wee read of the "Inno Setup" and the "Acad Install" help
files to familiarise yourself with the software and give yourself a basic understanding of what we are
doing.
Step 4
As you have probably noticed when installing other software, during installation certain pages such as
a License notice or a ReadMe notice appear. Well now we need to create 3 files to go along with our
installation application - A License Notice, a Warning Notice and a Config Notice. You can use plain old
Notepad for this task, saving them as straight forward TXT files. This is what our example files look like.
License Notice :
AfraLisp AutoCAD 2004 Custom Menu
==================================
Except where otherwise noted, all of the documentation
and software included in the AfraLisp AutoCAD 2004 Custom
Menu package is copyrighted by AfraLisp.
Copyright (C) 2003 AfraLisp. All rights reserved.
Be it hereby known that all the functions, programs and
applications contained in this here menu system, together
with but not excluding all those other parts and utterances
thereunto, shall not be warranted against all defects,
failures and malfunctions as shall occur between now and
Thursday afternoon shortly before 2:00 am, during which
time AfraLisp will maybe, at no charge to you or the other
person who complained before you, send the culprit application
to our Programmers, who will emerge from their caves and engage
in rituals designed to cleanse the menu system of evil spirits.
This warranty does not cover attractive blonde females (not male)
who may happen to use this menu system or whatever you would like
to call it.
Please respect the intellectual rights of others, or we will hunt
you down and do nasty things to you!!!
=========================
AfraLisp
afralisp@mweb.com.na
http://www.afralisp.com
=========================
Warning Notice :
Custom Application Setup
http://www.afralisp.com/lisp/install1.htm (2 of 4) [23/03/2005 05:47:06 p.m.]
WARNING!
==========
Please close all Windows applications, ESPECIALLY any Autodesk
software applications (AUTOCAD, MECHANICAL DESKTOP, etc.)
before proceeding with installation.
---------------
If you have these applications open during the installation
process, the software will not install or function properly.
And our Config Notice :
AfraLisp AutoCAD 2004 Custom Menu
==================================
AutoCAD has automatically been configured for the AfraLisp
2004 Custom Menu. The installer has performed the following
configuration tasks :
1) Added the required folders to your AutoCAD Support Path.
2) Added the AfraLisp AutoCAD 2004 Custom Menu to your menu bar,
and installed any applicable Toolbars.
3) Created a new AfraLisp Profile and made it current.
4) Created an icon on your desktop which will start AutoCAD
with the appropriate profile.
Okay, that seems to be everything ready. Let's just have a quick look at what our root folder looks like
and the files therein :
Notice my Afralisp.mnu, AfraLisp.dll and AcadDoc.lsp are within this folder!!
Okay, now let's create our Setup Script. See you on the next page........
Page I Page II Page III Page IV Page V

Custom Application Setup


http://www.afralisp.com/lisp/install1.htm (3 of 4) [23/03/2005 05:47:06 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Custom Application Setup
http://www.afralisp.com/lisp/install1.htm (4 of 4) [23/03/2005 05:47:06 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Custom Application Setup II
Welcome back everyone. So are you ready to create your Setup Script?
You are!! Okay fire up "Inno Setup". This dialog should appear :
For the sake of simplicity, and 'cos it's less work, select the "Create a new script file using the Script
Wizard" option button and then select "OK".
Custom Application Setup II
http://www.afralisp.com/lisp/install2.htm (1 of 6) [23/03/2005 05:47:22 p.m.]
The Wizard will then appear. Say hello, ask how Harry Potter is and then select "Next".
Fill in each edit box replacing the contents with your own details if you so wish.
Select "Next".
Custom Application Setup II
http://www.afralisp.com/lisp/install2.htm (2 of 6) [23/03/2005 05:47:22 p.m.]
We would like our Application to be installed in the Program Files directory and we are happy with the
Application Directory name. You can uncheck the "Allow user to change the application directory" if
you wish. Click on "Next" again.
Okay, this is the important part. Firstly you need to select AcadInst.exe as the "Application main
executable file". This is the file that will run after the installation is complete. You then need to select
ALL files AND directories that you want to include within the installation. DO NOT forget the AcadInst.ini
file.
Once finished with your selections, press "Next".
Custom Application Setup II
http://www.afralisp.com/lisp/install2.htm (3 of 6) [23/03/2005 05:47:22 p.m.]
Now we need to set up our icons. We would like to "Create an Internet shortcut in the Start Menu
folder", and we would like to "Create an Uninstall icon in the Start Menu folder". We DO NOT want to
"Allow user to create a desktop icon". "Acad Install" will take care of that for us. Select "Next" yet again.
This is where we include our License, Warning and Config text files.
Yep, you've guessed, press "Next" again.
Custom Application Setup II
http://www.afralisp.com/lisp/install2.htm (4 of 6) [23/03/2005 05:47:22 p.m.]
Right, that's us about done. Now just for a change, select the "Finish" button.
No, we do not want to compile our script as of yet as we have a few tweeks to take care of. Select "No".
Looks nice hey. Have a look at these lines under the [Files] section :
Source: "C:\afralisp2004_Install\Lib2004\*.*"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Lisp2004\*.*"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Templates\*.*"; DestDir: "{app}"; Flags: ignoreversion
For some inexplicable reason, the Wizard does not add the sub-folder paths to the DestDir (Destination
Directory). This means that we need to add them by hand. This is what needs to be added to your script.
Source: "C:\afralisp2004_Install\Lib2004\*.*"; DestDir: "{app}\Lib2004"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Lisp2004\*.*"; DestDir: "{app}\Lisp2004"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Templates\*.*"; DestDir: "{app}\Templates"; Flags: ignoreversion
As we do not want "Acad Install" to run at this time, you now need to comment out the following
section. You comment it out by placing a semi-colon ( ; ) at the beginning of the line.
;[Run]
;Filename: "{app}\AcadInst.exe"; Description: "Launch AfraLisp 2004 Custom Menu"; Flags: nowait postinstall
skipifsilent
Your script will look something like this. (I've added the comments by the way).
Now save your script as "AfraLisp.iss" into the root folder of your application.
Okey Doke, it's now time to test our script. Let's do that on the next page.
Exciting hey??
Custom Application Setup II
http://www.afralisp.com/lisp/install2.htm (5 of 6) [23/03/2005 05:47:22 p.m.]
Page I Page II Page III Page IV Page V

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Custom Application Setup II
http://www.afralisp.com/lisp/install2.htm (6 of 6) [23/03/2005 05:47:22 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
AppName=AfraLisp 2004 Custom Menu
;the name of the application
AppVerName=AfraLisp 2004 Custom Menu Version 1.5
;the version of the application
AppPublisher=AfraLisp
;the publisher
AppPublisherURL=http://www.afralisp.com
;the publishes web address
AppSupportURL=http://www.afralisp.com
;the publishes support address
AppUpdatesURL=http://www.afralisp.com
;the publishes update address
DefaultDirName={pf}\AfraLisp 2004 Custom Menu
;the default installation folder
;(pf) denotes "Program Files"
DefaultGroupName=AfraLisp 2004 Custom Menu
;the group name
DisableProgramGroupPage=yes
;we do not want a group page
LicenseFile=C:\afralisp2004_Install\license.txt
;path to the License file
InfoBeforeFile=C:\afralisp2004_Install\warning.txt
;path to the Warning file
InfoAfterFile=C:\afralisp2004_Install\config.txt
;path to the Config file
[Files]
;Path to source files/folders and Destination folders.
;(app) denotes The application directory, which the user
Inno Setup Script
http://www.afralisp.com/lisp/install2-inno.htm (1 of 3) [23/03/2005 05:47:23 p.m.]
;selects on the Select Destination Directory.
Source: "C:\afralisp2004_Install\AcadInst.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\AcadInst.ini"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\acaddoc.lsp"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\AfraLisp.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\AfraLisp.mnu"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Lib2004\*.*"; DestDir: "{app}\Lib2004"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Lisp2004\*.*"; DestDir: "{app}\Lisp2004"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Templates\*.*"; DestDir: "{app}\Templates"; Flags: ignoreversion
[INI]
Filename: "{app}\AcadInst.url"; Section: "InternetShortcut"; Key: "URL"; String: "http://www.afralisp.com"
[Icons]
;shortcut icons
Name: "{group}\AfraLisp 2004 Custom Menu"; Filename: "{app}\AcadInst.exe"
Name: "{group}\AfraLisp 2004 Custom Menu on the Web"; Filename: "{app}\AcadInst.url"
Name: "{group}\Uninstall AfraLisp 2004 Custom Menu"; Filename: "{uninstallexe}"
;[Run]
; NOTE: The following entry contains an English phrase ("Launch"). You are free to translate it into another
language if required.
;Filename: "{app}\AcadInst.exe"; Description: "Launch AfraLisp 2004 Custom Menu"; Flags: nowait postinstall
skipifsilent
[UninstallDelete]
;delete these files on uninstall
Type: files; Name: "{app}\AcadInst.url"
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Inno Setup Script
http://www.afralisp.com/lisp/install2-inno.htm (2 of 3) [23/03/2005 05:47:23 p.m.]
Search
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Inno Setup Script
http://www.afralisp.com/lisp/install2-inno.htm (3 of 3) [23/03/2005 05:47:23 p.m.]
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Custom Application Setup III
To test our set up script, we first need to compile the script. Re-open "AfraLisp.iss" and choose "File" "Compile"
from the pull down menu. Bells will ring and buzzes will buzz and at the end of it your script will be compiled. Have
a look at your application folder structure now :
You should have a new sub-folder entitled "Output". Within this folder you will find a file named "Setup.exe".
Double click on it. This should appear :
After you've had a wee read click on "Next".
Custom Application Setup III
http://www.afralisp.com/lisp/install3.htm (1 of 6) [23/03/2005 05:47:37 p.m.]
Ha, ha!! Our License!! Select "I accept the agreement" and then "Next".
And next our "Warning". Select "Next" again.
Custom Application Setup III
http://www.afralisp.com/lisp/install3.htm (2 of 6) [23/03/2005 05:47:37 p.m.]
Just default through this unless you really want to change the Destination Directory.
Select "Next" again. Phew!!
Happy with everything? Select "Install".
A progress bar will appear as your files are installed. Once complete, this will appear :
Custom Application Setup III
http://www.afralisp.com/lisp/install3.htm (3 of 6) [23/03/2005 05:47:37 p.m.]
Just some instructions to let the user know what has happened in regards to the AutoCAD configuration. Nothing
has happened though, because we disabled the "Acad Install" section of the script. Click on the "Next" button.
Select the "Finish" button to complete the installation.
Let's pop along to "Program Files" and see what we can find.
Custom Application Setup III
http://www.afralisp.com/lisp/install3.htm (4 of 6) [23/03/2005 05:47:37 p.m.]
Hey, all our Folders, sub-folders and files have been installed.
This is magic!!!
Now look under "Start" "Programs" for "AfraLisp 2004 Custom Menu".
Select "Uninstall AfraLisp 2004 Custom Menu".
Before we go any further, we need to tweek our setup script just a wee bit more to integrate with "Acad Install".
Under the [Run] section of AfraLisp.iss you will find this line :
;[Run]
;the program to run
;Filename: "{app}\AcadInst.exe"; Description: "Launch AfraLisp 2004 Custom Menu"; Flags: nowait postinstall
skipifsilent
Remove the semi-colons from the beginning of the lines and make these changes :
Filename: "{app}\AcadInst.exe"; Description: "Configure AutoCAD"; Parameters: {app}; Flags: waituntilidle
Now add this to the bottom of the script :
[UninstallRun]
;run this program on uninstall
Filename: "{app}\AcadInst.exe"; Parameters: -U
Your script file should now look like this.
Okay, that's our script file complete. Now save it.
We now need to configure "Acad Install" to integrate with our setup application.
This we will do on the next page.
Page I Page II Page III Page IV Page V

Custom Application Setup III


http://www.afralisp.com/lisp/install3.htm (5 of 6) [23/03/2005 05:47:37 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Custom Application Setup III
http://www.afralisp.com/lisp/install3.htm (6 of 6) [23/03/2005 05:47:37 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
AppName=AfraLisp 2004 Custom Menu
;the name of the application
AppVerName=AfraLisp 2004 Custom Menu Version 1.5
;the version of the application
AppPublisher=AfraLisp
;the publisher
AppPublisherURL=http://www.afralisp.com
;the publishes web address
AppSupportURL=http://www.afralisp.com
;the publishes support address
AppUpdatesURL=http://www.afralisp.com
;the publishes update address
DefaultDirName={pf}\AfraLisp 2004 Custom Menu
;the default installation folder
;(pf) denotes "Program Files"
DefaultGroupName=AfraLisp 2004 Custom Menu
;the group name
DisableProgramGroupPage=yes
;we do not want a group page
LicenseFile=C:\afralisp2004_Install\license.txt
;path to the License file
InfoBeforeFile=C:\afralisp2004_Install\warning.txt
;path to the Warning file
InfoAfterFile=C:\afralisp2004_Install\config.txt
;path to the Config file
[Files]
;Path to source files/folders and Destination folders.
;(app) denotes The application directory, which the user
Inno Setup Script
http://www.afralisp.com/lisp/install2-inno2.htm (1 of 3) [23/03/2005 05:47:38 p.m.]
;selects on the Select Destination Directory.
Source: "C:\afralisp2004_Install\AcadInst.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\AcadInst.ini"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\acaddoc.lsp"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\AfraLisp.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\AfraLisp.mnu"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Lib2004\*.*"; DestDir: "{app}\Lib2004"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Lisp2004\*.*"; DestDir: "{app}\Lisp2004"; Flags: ignoreversion
Source: "C:\afralisp2004_Install\Templates\*.*"; DestDir: "{app}\Templates"; Flags: ignoreversion
[INI]
Filename: "{app}\AcadInst.url"; Section: "InternetShortcut"; Key: "URL"; String: "http://www.afralisp.com"
[Icons]
;shortcut icons
Name: "{group}\AfraLisp 2004 Custom Menu"; Filename: "{app}\AcadInst.exe"
Name: "{group}\AfraLisp 2004 Custom Menu on the Web"; Filename: "{app}\AcadInst.url"
Name: "{group}\Uninstall AfraLisp 2004 Custom Menu"; Filename: "{uninstallexe}"
[Run]
the program to run after install
Filename: "{app}\AcadInst.exe"; Description: "Configure AutoCAD"; Parameters: {app}; Flags: waituntilidle
[UninstallDelete]
;delete these files on uninstall
Type: files; Name: "{app}\AcadInst.url"
[UninstallRun]
;run this program on uninstall
Filename: "{app}\AcadInst.exe"; Parameters: -U
Inno Setup Script
http://www.afralisp.com/lisp/install2-inno2.htm (2 of 3) [23/03/2005 05:47:38 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Inno Setup Script
http://www.afralisp.com/lisp/install2-inno2.htm (3 of 3) [23/03/2005 05:47:38 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Custom Application Setup IV
Let's review what we've done so far.
We've set up our folders and sub-folders for our custom application. G
We've used the "Inno Setup" Wizard to create our setup script. G
We've tweeked the setup script to integrate with "Acad Install". G
Now we need to configure our "AcadInst.ini" file. G
Lets have a look at the "AcadInst.ini" file which should be in your application root folder :
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Usage Notes: ;
; See AcadInst.chm help file for instructions on sections and values ;
[PRODUCT]
Name=MyAcadApp
RegPath=MyCompany\MyAcadApp\MyAppVersion
License=
Silent=
[AUTOCAD]
Versions=R15.0,R16.0
Products=
SerialNumbers=
AddPath=|1
Silent=
[AUTOCAD LT]
Versions=R2000
Products=
SerialNumbers=
AddPath=
Silent=
[ARX]
Install=CdWxMyAppArx
Uninstall=
Description=My app's arx description
LoadCtrls=13
Loader=MyAppArx
Groups=GROUP1:GROUP1
Commands=COMMAND1:COMMAND1,COMMAND2:COMMAND2
[ARX2]
Custom Application Setup IV
http://www.afralisp.com/lisp/install4.htm (1 of 4) [23/03/2005 05:47:38 p.m.]
Install=CdWxMyAppArx2
Uninstall=
Description=My app's other arx description
LoadCtrls=13
Loader=MyAppArx2
Groups=GROUP1:GROUP1
Commands=COMMAND3:COMMAND3,COMMAND4:COMMAND4
[MENU]
MenuGroups=MyMainMenu:MyMenuFile:1:3,MyOtherMenu:MyMenuFile
Toolbars=MyMainMenu.TB_MAIN
[APPLOAD]
StartupSuite=\MyAppVlx.vlx
History=\MyAppVlx.vlx
[ACADDOC]
Line1=(alert "Pie is good!")
Line2=(princ "\nThe path to my app is ")
[STARTAPP]
[NEWPROFILE]
Name=MyProfile
Description=My profile for my AutoCAD application.
CopyFrom=
MakeDefault=T
DesktopShortcut=T
QuickLaunchButton=T
[General]
;Blipmode=1
;TemplatePath=\Templates
First, let's strip out what we won't need or will not be using. Your AcadInst.ini file should now look like
this :
[PRODUCT]
Name=MyAcadApp
RegPath=MyCompany\MyAcadApp\MyAppVersion
[AUTOCAD]
Versions=R15.0,R16.0
AddPath=|1
[MENU]
MenuGroups=MyMainMenu:MyMenuFile:1:3,MyOtherMenu:MyMenuFile
Toolbars=MyMainMenu.TB_MAIN
[NEWPROFILE]
Name=MyProfile
Custom Application Setup IV
http://www.afralisp.com/lisp/install4.htm (2 of 4) [23/03/2005 05:47:38 p.m.]
Description=My profile for my AutoCAD application.
CopyFrom=
MakeDefault=T
DesktopShortcut=T
QuickLaunchButton=T
[General]
TemplatePath=\Templates
Now make these changes as shown in red. I've added comments to each change to explain what is going
on :
[PRODUCT]
Name=AfraLisp2004 Custom Menu
;the name of our application.
[AUTOCAD]
Versions=R15.0,R16.0
;the AutoCAD version/s to be configured
AddPath=<InstallPath>|1;<InstallPath>\Lib2004|2;<InstallPath>\Lisp2004|3
;the support paths to be added and their positions
[MENU]
MenuGroups=AFRALISP:AFRALISP:1:50
;the pull down menu to be added
Toolbars=AFRALISP.LAYMAN
;the toolbar to be added
[NEWPROFILE]
Name=AfraLisp
;the name of the profile to be added
Description=AfraLisp 2004 Menu Profile.
;the description of the profile
CopyFrom=<CURRENT>
;copy the profile from the current profile
MakeDefault=T
;make it the default profile;make it the default profile
DesktopShortcut=T
;yes we want a desktop shortcut
ShortcutName=AfraLisp Profile
;name of the shortcut
ShortcutComment=AfraLisp Custom Menu Profile
;the tooltip
ShortcutArgs=/p "AfraLisp"
;the arguments on startup
ShortcutWorkingDir=C:\drawings
;the working directory
[<PROFILE>General]
TemplatePath=<STRING><InstallPath>\Templates
;the template file path
Custom Application Setup IV
http://www.afralisp.com/lisp/install4.htm (3 of 4) [23/03/2005 05:47:38 p.m.]
Let's have a look at our setup application in action. See you on the next page.
Page I Page II Page III Page IV Page V

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Custom Application Setup IV
http://www.afralisp.com/lisp/install4.htm (4 of 4) [23/03/2005 05:47:38 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Custom Application Setup V
To try out our full installation, we first need to re-compile our "setup.exe".
Re-open your "Acadlisp.iss" file and again choose "Files" - "Compile".
Again, open the "Output" folder and double click "setup.exe".
The installation will proceed as before until you reach this point and this dialog appears :
Select the profile that you would like to install your custom installation to, and then select "Okay" The
Config page and the "Finish" page will then appear.
That's it, your custom installation is complete. Let's check. First have a look on your desktop. You
should have a new shortcut icon entitled "AfraLisp Profile".
Right click on the icon and choose "Properties".
Custom Application Setup V
http://www.afralisp.com/lisp/install5.htm (1 of 4) [23/03/2005 05:47:45 p.m.]
Note that the arguments for the "Target:" have been inserted and the "Start in:" directory has been
configured.
Now open AutoCAD using your new icon.
A new toolbar should appear that looks like this :
Now choose "Tools" - "Options" from the pull down menu and select the "Files" tab:
Our new support file path has been inserted.
Let's check the "Template File" path :
Custom Application Setup V
http://www.afralisp.com/lisp/install5.htm (2 of 4) [23/03/2005 05:47:45 p.m.]
Yep, it's there. Let's have a look at our Profiles.
Select the "Profiles" tab :
Hey, a new profile all to myself!!
Close the Options dialog and have a look at your menu bar.
You should have a new pull down menu named "AfraLisp Menu".
Well that's it. Mission accomplished.
Of course, this is in no ways a full explanation of what "Inno Tools" or "Acad Install" are capable of.
They are both full of functions and capabilities that I haven't even touched on in this tutorial. Read the
help files, play around with them, have a wee bit of fun.
(Have a look here if you would like a more detailed look at "Acad Install".)
Sorry, coming soon!!
If you would like to download the all installation files for this tutorial, please feel free to click here.
Although "ACAD Install" was primarily written to work in conjunction with "Inno Setup" it can also be
used as a stand alone application. I find it particularly useful for configuring AutoCAD for a Network
environment.
In a Network environment there is no need for a full blown installation application, as all of the support
files, menu's, lisp files, etc. are already on the Network and are shared by each user. All we really
require is a method of configuring AutoCAD to suit our Network paths. This is where "Acad Install"
comes into play.
Read more about "Standing Alone with Acad Install".
Page I Page II Page III Page IV Page V

Custom Application Setup V


http://www.afralisp.com/lisp/install5.htm (3 of 4) [23/03/2005 05:47:45 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Custom Application Setup V
http://www.afralisp.com/lisp/install5.htm (4 of 4) [23/03/2005 05:47:45 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AutoCAD Command Line Switches
What are Command Line Switches Kenny?
Command Line Switches are parameters that you add to the acad.exe command line which enable
AutoCAD to perform additional operations when it starts. For example, AutoCAD can start with an
alternative configuration, run a script, load a template drawing and even open a drawing with a saved
view.
Personally, I feel that Command Line Switches are often neglected by the AutoCAD programmer/system
manager. Why? I don't know as they can drastically cut down on setting up workstations and help a hell
of a lot in enforcing drawing office standards.
Before we have a look at the Command Line Switches, let's have a look at how AutoCAD deals with
them :
If you use a Command Line Switch to specify an environment setting, the Command Line Switch
overrides the settings specified in either the Options dialog box or the environment value.
G
If a Command Line Switch is not set, the corresponding value set in the Options dialog box is
used.
G
If neither a Command Line Switch nor an Options value is set, the environment variable value is
used
G
Note : Command Line Switches and environment variables override Options values for the current
session only. They do not alter the system registry.
Okay dokey, now let's have a look at how we go about changing a Command Line Switch :
Make a backup copy of your AutoCAD 2002 icon. Right-click on the icon and then Copy and Paste it to a safe
location.
G
Again, Right-Click on the AutoCAD 2002 icon on your Desktop. G
Choose Properties G
In the AutoCAD 2002 Properties dialog, select the Shortcut tab. G
This is what it should look like :
AutoCAD Command Line Switches
http://www.afralisp.com/lisp/Switches.htm (1 of 3) [23/03/2005 05:47:48 p.m.]
The section that we are interested in is the "Target" edit box, which in this example contains "C:\AutoCAD
2002\acad.exe"
A word of warning though, when making changes to the Target box, make sure you don't accidentally remove any
section of the application path or filename itself, Make sure that there is a single space after the path and file
argument and before you switch. Also, ensure there is a space between each argument and your switch statements.
If your path or file names have spaces in them, you will have to surround the path or name with double quotes. In
fact, to be on the safe side, I surround all my paths and file names with double quotes.
Right, let's have a look at the switches :
Switch Syntax and Example Description
/b
path ["drawing file"] /b "script"
"C:\AutoCAD 2002\acad.exe" /b "C:\scripts\MyScript"
Open a drawing and runs a
Script. Drawing name is
optional.
/c
path /c "Configuration File"
"C:\AutoCAD 2002\acad.exe" /c "C:\myconfigs\MyConfig"
Specifies the hardware
configuration file to use.
/nologo
path /nologo
"C:\AutoCAD 2002\acad.exe" /nologo
Starts AutoCAD without the
splash screen.
/p
path /b profile
"C:\AutoCAD 2002\acad.exe" /p "C:\profiles\MyProfile"
Starts AutoCAD with the
specified Profile name. If the
Profile does not exist,
AutoCAD uses the current
Profile.
/r
path /r
"C:\AutoCAD 2002\acad.exe" /r
Resets all AutoCAD default
settings, printers and system
pointing device.
/s
path /s "Support Paths"
"C:\AutoCAD 2002\acad.exe" /s "C:\Blocks;C:\Lisp;C:\VBA"
Designates additional Support
Paths.
AutoCAD Command Line Switches
http://www.afralisp.com/lisp/Switches.htm (2 of 3) [23/03/2005 05:47:48 p.m.]
/t
path ["drawing file"] /t "Template File"
"C:\AutoCAD 2002\acad.exe" /t "C:\MyTemplates\MyTemplate"
Creates a new drawing based
on a Template or Prototype
drawing. Drawing name is
optional.
/v
path ["drawing file"] /v "View Name"
"C:\AutoCAD 2002\acad.exe" "MyDrawing" /v "MyView"
Opens a drawing with a
predefined view.
You can of course string the Command Line Switches together. For example, to open AutoCAD with no
splash screen using a user defined profile and template drawing, you would use the following syntax :
"C:\AutoCAD 2002\acad.exe" /nologo /p "C:\profiles\MyProfile" /t "C:\MyTemplates\MyTemplate"
Would you like AutoCAD to open in a specific directory every time?
You would? Good!!!
Then just place your directory path in the "Start In" edit box. Easy hey?

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
AutoCAD Command Line Switches
http://www.afralisp.com/lisp/Switches.htm (3 of 3) [23/03/2005 05:47:48 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
Standing Alone with Acad Install
Although "ACAD Install" was primarily written to work in conjunction with "Inno Setup" - see "Custom
Application Setups" - it can also be used as a stand alone application. I find it particularly useful for
configuring AutoCAD for a Network environment.
In a Network environment there is no need for a full blown installation application, as all of the support files,
menu's, lisp files, etc. are already on the Network and are shared by each user. All we really require is a
method of configuring AutoCAD to suit our Network paths. This is where "Acad Install" comes into play. So,
let's have a look at setting up "Acad Install" to configure AutoCAD.
This is what our Network directory structure looks like :
Pretty straight forward hey? "Network_Install" is the directory folder containing all our support folders and
files. You must remember that "AcadInst.exe" and "AcadInst.ini" must reside in the root folder of your
Network directory structure. The files in this folder will look something like this :
As you can see from the file listing above, "AcadInst"can now be renamed so that multiple installers can
coexist in same directory. The .ini file name should match .exe name
(AcadInst_1.exe/AcadInst_1.ini/AcadInst_2.exe/AcadInst_2.ini,...)
Any partial Menu must also reside in this folder as I haven't yet discovered a way to refer to a menu residing
in a sub-folder.
Okay, time to have a look at the "AcadIns.ini" file :
[PRODUCT]
Name=AfraLisp 2004 Custom Menu
Standing Alone with Acad-Install
http://www.afralisp.com/lisp/acadinst1.htm (1 of 7) [23/03/2005 05:47:59 p.m.]
;This is the applications name. This value is required and AcadInst.exe
; will display an error message if it is not included.
[AUTOCAD]
Versions=R16.0
;Comma-delimited string representing the versions of AutoCAD
; for which the application can/will* be installed.
;Valid strings are any key found under
;HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD in the registry.
;When left empty all profiles that match the other criteria are included.
;To avoid all versions enter NONE.
;Examples for AutoCAD are R14.0 for R14, R15.0 for 2000,
;2000i, & 2002, and R16.0 for 2004
;Examples for LT are R5.0 for LT98, R2000 for LT 2000,
;R7 for LT 2000i, and R8 for LT2002
AddPath=< InstallPath >\Admin|1;< InstallPath >\Lib2004|2;
< InstallPath >\Lisp2004|3;< InstallPath >\Sym2004|4
;Semi-colon delimited list of PATH|POSITION to add to the
;AutoCAD search path. To insert the path at the beginning use a
;POSITION of 1. If the POSITION is not specified, the path will be
;appended to the end.
;If the path is already part of the search path it will not be added again.
;You can use < InstallPath > to indicate the path the user installed to.
;Using this you can also add paths relative to the path where the user
;installed, for example
;< InstallPath >\Symbols:2 would add a sub-folder of the installed path
;named Symbols as the second entry ;in the support paths list.
[MENU]
MenuGroups=AFRALISP:AFRALISP:1:50
;Comma-delimited string of MENUGROUP:MENUFILE:POP:POSITION
;(without extensions) to be added to the Menu key for the profiles.
;The registry is searched and the first available Group number is used.
;If POSITION ;is greater than the number of installed pop menus,
;then it will be added to the end. To insert at the beginning
;use 1. To insert at the end use some large number like 50.
;If the POP and POSITION numbers are not included
;then no drop-down menu is installed for that menu.
;Example:
;MenuGroups=MyMainMenu:MyMenuFile:1:3,MyOtherMenu:MyMenuFile

;will setup MyMainMenu and MyOtherMenu from MyMenuFile to be
;loaded when AutoCAD starts up.
;POP1 menu from MyMainMenu will be placed as the third AutoCAD
;menu and MyOtherMenu will not be ;placed as a POP menu.
Toolbars=AFRALISP.LAYMAN
;Comma-delimited string of MENUGROUP.TOOLBAR pairs to be
;added to the AutoCAD GUI. If the user has previously closed one
;of the toolbars it will be forced to show itself again after
;running installer.
[APPLOAD]
Standing Alone with Acad-Install
http://www.afralisp.com/lisp/acadinst1.htm (2 of 7) [23/03/2005 05:47:59 p.m.]
StartupSuite=< InstallPath >\Lisp2004\doslib2004.arx,
< InstallPath >\Lisp2004\cerror.vlx
;A comma-delimited string of files (with ext) to be added to
;AutoCAD's Startup Suite.
;Only valid for post-R14, non-LT installations.
History=< InstallPath >\Lisp2004\doslib2004.arx,
< InstallPath >\Lisp2004\cerror.vlx
;A comma-delimited string of files (with ext) to be added to
;the Appload dialog's History list.
;Only valid for post-R14, non-LT installations.
;For both of these keys you must use < InstallPath > to insert the user
;specified path when appropriate.
;See the AddPath= key for more information.
[NEWPROFILE]
Name=AfraLisp
;Name for the new profile. If it already exists,
;the rest of the keys are skipped.
;A profile will be created for all AutoCAD apps specified in the
;[AUTOCAD] and [AUTOCAD LT] sections.
Description=AfraLisp 2004 Menu Profile.
;Description of New Profile
CopyFrom=< CURRENT >
;Copy from the current profile to retain existing configurations
MakeDefault=T
;Make it the default Profile
DesktopShortcut=T
;Add a shortcut to the desktop
ShortcutName=AfraLisp 2004 Menu Profile
;Shortcut Name
ShortcutComment=AfraLisp 2004 Menu Profile
;Tooltip
ShortcutArgs=/p "AfraLisp"
;the arguments on startup
ShortcutWorkingDir=< InstallPath >\Admin
;the working directory
[<PROFILE>General]
TemplatePath=< STRING >< InstallPath >\Tplts
;Template File Path
Do you notice how we make use of <InstallPath> to indicate the path the user installed to. Using this you can
also add paths relative to the path where the user installed, for example <InstallPath>\Symbols|2 would add a
sub-folder of the installed path named Symbols as the second entry in the support paths list.
Right, that's everything set up and ready. Double click on "AcadInst-admin.ini" and see what happens :
Standing Alone with Acad-Install
http://www.afralisp.com/lisp/acadinst1.htm (3 of 7) [23/03/2005 05:47:59 p.m.]
Would we like to install our custom menu. Of course we would!! Press "Yes."
Now it's asking us what Profile would we like to base our new Profile on, and which of our Installed AutoCAD
versions would we like to install too. Pick a Profile, any will do and then select "OK."
Mmmm, nothing really seemed to happen??
Don't worry, plenty did it's just that it all happened so fast.
Have a look at your desktop :
Ha, ha, we have a new desktop icon. Right-click on the icon and select "Properties" and then the "Shortcut"
tab :
Standing Alone with Acad-Install
http://www.afralisp.com/lisp/acadinst1.htm (4 of 7) [23/03/2005 05:47:59 p.m.]
Mmm, interesting!! Our "Target" arguments have been set, and our "Start In" directory has been configured.
Okay, now fire up AutoCAD.
A new Toolbar should appear looking like this :
This is getting more and more interesting. Now choose "Tools" - "Options" -"Files" and have a look at your
support path :
Good, our Support Paths have been added.
And the Template File Path? Well let's have a look:
Yep, there it is. Now choose the "Profiles" tab :
Yippee, it's there. Now where has our menu gone? Check out your menu bar :
Great, our pull down menu has also been loaded.
But didn't we ask for some files to be loaded in the Startup Suite? Let's have a wee look :
Standing Alone with Acad-Install
http://www.afralisp.com/lisp/acadinst1.htm (5 of 7) [23/03/2005 05:47:59 p.m.]
Yep, there are bet are they in our History List ?
Okay, that's our installation complete, but what happens when we want to uninstall?
To uninstall you can run it from the command line (Start->Run) passing -U as the single parameter :
Or you can do something like the following in a .bat file to uninstall :
ECHO OFF
CLS
ECHO Uninstalling from AutoCAD
PAUSE
AcadInst.exe -U
ECHO Files Uninstalled!
PAUSE
If you would like to download all the files involved in this tutorial then please feel free to click on this spot
here.

Standing Alone with Acad-Install


http://www.afralisp.com/lisp/acadinst1.htm (6 of 7) [23/03/2005 05:47:59 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Standing Alone with Acad-Install
http://www.afralisp.com/lisp/acadinst1.htm (7 of 7) [23/03/2005 05:47:59 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp's Tips 'n Tricks II
Page I Page III
Onsnap Menu
Here is a little trick that I did to my osnap cursor menu.I come across a lot of users who are not aware of this
function, 'Cal - Mee.
I used to use a 12 button puck & tablet and had this programmed on button #4. Now, in the modern world of the
InteliMouse, I have given up my beloved tablet, so here is what I have done to my AutoCad menu.
[&Object Snap Cursor Menu]
ID_Tracking [Temporary trac&k point]_tt
ID_From [&From]_from
ID_MnPointFi [->Poin&t Filters]
ID_PointFilx [.X].X
ID_PointFily [.Y].Y
ID_PointFilz [.Z].Z
[--]
ID_PointFixy [.XY].XY
ID_PointFixz [.XZ].XZ
ID_PointFiyz [<-.YZ].YZ
[--]
ID_OsnapEndp [&Endpoint]_endp
ID_OsnapMidp [&Midpoint]_mid
ID_OsnapInte [&Intersection]_int
ID_OsnapAppa [&Apparent Intersect]_appint
ID_OsnapExte [E&xtension]_ext
[--]
ID_OsnapCent [&Center]_cen
ID_OsnapQuad [&Quadrant]_qua
ID_OsnapTang [Tan&gent]_tan
[--]
ID_OsnapPerp [&Perpendicular]_per
ID_OsnapPara [Para&llel]_par
ID_OsnapNode [No&de]_nod
ID_OsnapInse [In&sert]_ins
ID_OsnapNear [Nea&rest]_nea
ID_OsnapNone [&None]_non
[--]
ID_Osnap [&Osnap Settings...]'_+dsettings 2
[--]
[Cal-Mee Expression]'cal;mee;
John Lauer
Command Line Problem
Q. Every time I open AutoCad Im down to one line of text in the command line. My profile specifies 4
lines. When I open Options/display 4 lines is specified. I can change the display to 4 lines, or whatever,
by stretching it with the mouse, but when I close AutoCad and open up again its back to one stingy
line.
A. If you use "Acad.lsp" or "Acaddoc.lsp" or similar at startup you could put the following piece of code
in one of these files; it will ensure that you get the number of command lines you want.
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (1 of 7) [23/03/2005 05:48:02 p.m.]
(setenv "CmdVisLines" "2")
;Sets the number of lines in the AutoCAD command line window
"CmdVisLines" must be written as is ie Upper & Lower case
"2" number of command lines you require ie 1, 2, 3.... etc
Random Number Generator.
Random number generation function - based on the linear congruential method as presented in Doug
Cooper's book Condensed Pascal, pp. 116-117.
Returns a random number between 0 and 1.
(defun randnum (/ modulus multiplier increment random)
(if (not seed)
(setq seed (getvar "DATE"))
)
(setq modulus 65536
multiplier 25173
increment 13849
seed (rem (+ (* multiplier seed) increment) modulus)
random (/ seed modulus)
)
)
Applying Points.
I received this from Roger Farley:
I was browsing your tips and tricks area and thought I would contribute a gem:
These four lines will give you the extreme four values in a points list:
where PointList is a list of 2D or 3D points (like a list of pline vertex points),
(setq X1 (apply 'min (mapcar 'car PointList)))
; The smallest 'X' value
(setq Y1 (apply 'min (mapcar 'cadr PointList)))
; The smallest 'Y' value
(setq X2 (apply 'max (mapcar 'car PointList)))
; The largest 'X' value
(setq Y2 (apply 'max (mapcar 'cadr PointList)))
; The largest 'Y' value
Then assemble like:
(setq LowerLeft (List X1 Y1))
(setq LowerRight (List X2 Y1))
(setq UpperRight (List X2 Y2))
(setq UpperLeft (List X1 Y2))
or
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (2 of 7) [23/03/2005 05:48:02 p.m.]
(setq CPWin (list (List X1 Y1) (list X2 Y1)
(list X2 Y2) (list X1 Y2)))
;A list of 4 points, can be passed to a 'ssget' function
I use the trick in finding an extents boundary around the objects
I am working with, or performing a zoom window around the work area.
Roger Farley
Saving and Restoring System Variables.
It is good practice (and manners) when writing Lisp routines to restore the system environment to the
state that your program found it in on completion of your application. Most AutoLisp routines start and
end like this :
(defun c:example ()
(setq oldhigh (getvar "Highlight")
oldsnap (getvar "Osmode")
oldblip (getvar "BlipMode")
oldecho (getvar "Cmdecho")
);setq
(setvar "Highlight" 0)
(setvar "Osmode" 517)
(setvar "Blipmode" 0)
(setvar "Cmdecho" 0)
Programme statements.............
.................................
(setvar "Highlight" oldhigh)
(setvar "Osmode" oldsnap)
(setvar "Blipmode "oldblip)
(setvar "Cmdecho" oldecho)
(princ)
);defun
;******************************************************
I must have written statements like this a thousand times in my Lisp routines.
The following example is designed to act as a global routine that first stores, then changes specific
system variables. On completion of the routine, the function is then called again and all system
variables are returned to their previous settings.
(defun varget ()
(setq lis '("HIGHLIGHT" "BLIPMODE" "CMDECHO"
"BLIPMODE" "OSMODE"))
;store names of system variables
(setq var (mapcar 'getvar lis))
;get the value of the system variables and
;store them as a list
(setq var1 '(0 0 0 0 517))
;store the new values of the system variables
(setq no 0)
;set counter to zero
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (3 of 7) [23/03/2005 05:48:02 p.m.]
(repeat (length lis)
;get the number of variables in the list
;to use as the counter control number
(setvar (nth no lis) (nth no var1))
;set the variables to their new values
(setq no (1+ no))
;move up one in the list
);repeat
(princ);finish quietly
);defun
;***************************************************************
(defun varset ()
(setq no 0)
;set counter to zero
(repeat (length lis)
;get the number of variables in the list
(setvar (nth no lis) (nth no var))
;reset the variables to their original values
(setq no (1+ no))
;move up one in the list
);repeat
(princ);finish quietly
);defun
;***************************************************************
(princ);load quietly
Our Autolisp routine could now look like this :
(defun c:example ()
(varget)
;store system variables and then reset them
Programme statements.............
.................................
(varset)
;restore system variables
(princ)
);defun
;******************************************************
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (4 of 7) [23/03/2005 05:48:02 p.m.]
As you can see, we have reduced the size of our routine by a lot and saved ourselves quite a bit of
typing. These two routines could both be loaded from our Acad.Lsp file so that they would be available
to all of your routines.
(getfiled) and (startapp).
Here is a handy little routine that displays a dialogue box that defaults to a user defined directory and
allows you to choose a Lisp file to edit. It then opens the file in Window's Notepad. When you have
finished editing, it automatically loads the relevant Lisp file.
It uses the (getfiled) function to locate and open the Lisp file, and the (startapp) function to run
Notepad.exe. You can change both path specifications to suit your setup.
(defun c:test ( / fl)
(setq fl
(getfiled "Select a Lisp File"
"d:/cadken/cadlisp14/NewLisp/"
"lsp" 0)
);setq
(startapp "c:/windows/notepad.exe" fl)
(load fl)
(alert (strcat "\n " fl " Loaded"))
(princ)
);defun
(princ)
Creating Defaults.
In many AutoCAD commands, AutoCAD remembers the last entry and puts that entry between angle
brackets (<>).
Then all you have to do is press Enter, and that value is used. You should use that technique whenever
you're creating your own defaults in AutoLISP.
First make sure that you haven't declared as local the variable that will hold the value. Then follow a
three-step process :
Require input from the user and assign that input to a second variable.
Test to see if the input is nil, and if it is nil, assign a global variable
to the real variable.
G
Finally, assign the real variable to the global variable. G
You're then ready for the next sequence. G
Here's an example :
(defun c:prog1 (/ a)
(if (= gv nil)
(setq gv 1.0)
);end if
(princ "\nEnter Distance <")
(princ gv)
(princ "> ")
(setq a (getdist))
(if (= a nil)
(setq a gv)
);end if
(setq gv a)
(princ "\nThe Distance is ")
(princ a)
(princ)
);defun
gv is the global variable.
No matter how often you run this routine while in the same drawing, it will maintain the last entry as the
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (5 of 7) [23/03/2005 05:48:02 p.m.]
default. The first time through the routine, gv is tested to see if it has a value. If it doesn't, the routine
assigns 1.0 as the default value.
Converting Strings to Uppercase.
There are many occasions when you'll need to convert a string variable to uppercase, especially when
you've requested a response and need to test it. It's much easier to test it against all-uppercase than to
try to test for every combination of uppercase and lowercase. The command for the conversion is
(strcase) :
(setq uc (strcase t))
This converts the value of the string variable t to uppercase and assigns
the new value to the variable uc.
Break @ Circle.
Have you ever tried breaking a Circle into 2 separate parts using the Break command? It doesn't work
does it? This routine allows you to separate a circle into two arcs by picking
two points on the circle.
(defun c:bcirc (/ os pt1 pt2 a pt3)
(setq os (getvar "osmode"))
(setvar "osmode" 512)
(setq pt1 (getpoint "\nFirst Break in Circle : "))
(setq pt2 (getpoint "\nSecond Break in Cricle : "))
(setq a (entget (ssname (ssget pt1) 0)))
(setq pt3 (cdr (assoc 10 a)))
(command "break" pt1 pt2)
(command "arc" pt1 "e" pt2 pt3)
(setvar "osmode" os)
(princ)
)
(princ)
Pick any 2 points on the a Circle.
The circle will look the same, but it will be broken into two arcs.
Restoring 2 Arcs to a Circle.
This routine will join 2 arcs back into a circle.
It will also complete a circle from an Arc.
(defun c:rcirc (/ os pt2 a pt1 ra pt3)
(setq os (getvar "osmode"))
(setvar "osmode" 512)
(setq pt2 (getpoint "\nPick one of the Arcs : "))
(setq a (entget (ssname (ssget pt2) 0)))
(setq pt1 (cdr (assoc 10 a)))
(setq ra (cdr (assoc 40 a)))
(command "erase" pt2 "")
(setq pt3 (getpoint "\nPick other Arc : "))
(setvar "osmode" os)
(command "erase" pt3 "")
(command "circle" pt1 ra)
(princ)
)
(princ)
Begin this routine with one or two arcs.
Pick either arc. That arc will disappear.
Pick the remaining arc if you started with two.
If you started with only one arc, pick any blank space on the screen or press Enter. Now the circle will
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (6 of 7) [23/03/2005 05:48:02 p.m.]
be restored or the single arc is turned into a complete circle.
Page I Page III

You are visitor number



Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
Tips and Tricks - Page II
http://www.afralisp.com/tips2.htm (7 of 7) [23/03/2005 05:48:02 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
AfraLisp's Tips 'n Tricks III
Page I Page II
Loading Partial Menu's
In AutoCAD R14 you have no problems in loading Partial Menu's.
AutoCAD Release 13, though is a different story!
Every time you re-start AutoCad you have to manually re-load the partial menu.
If you load it from your Acad.Lsp using the menuload command that works fine the first time you enter AutoCad. But
as soon as you open another drawing you get an error in your Acad.lsp file with Autocad telling you that the partial
menu is already loaded.
The following is an extract from the AutoCAD Custumization Manual :
To determine if a menu file is currently partially loaded, you can use the following syntax with any POP menu item (it
works with only a POP menu item) :
(menucmd "Gmenugroup.nametag=?")
If the menu file is currently loaded, this will return a nonnil value
otherwise it will return nil.
Example : Use the following code in your Acad.lsp file.
You must have a partial menu named TEST.MNU and a POP menu item called AMENUITEM. (You can, of course, use
your own Menu and POP names).
;;*-------------------------------------------------------------------
(defun S::STARTUP ()
;define Startup function
(setq temp (menucmd "GTEST.AMENUITEM=?"))
;is the POP item loaded?
(if (= temp nil)
;test it
(progn
;if it is not loaded
(setvar "filedia" 0)
;suppress dialog boxes
(command "menuload" "TEST")
;load Menu
(menucmd "P8=+TEST.POP1")
;load POP1
(menucmd "P9=+TEST.POP2")
;load POP2
(setvar "filedia" 1)
;restore dialogs
More Tips and Tricks - Page III
http://www.afralisp.com/tips3.htm (1 of 4) [23/03/2005 05:48:03 p.m.]
);progn
);if

(prompt "\nPartial Menu Loaded....\n")
;prompt user
(princ)
);defun
;*---------------------------------------------------------------------
Existing S::STARTUP
Because an S::STARTUP function can be defined in many places (an acad.lsp file, a .mnl file, or any other AutoLISP
file loaded from either of these), it's possible to overwrite a previously defined S::STARTUP function. The following
example shows one method of ensuring that
your start-up function works with other functions.
(defun MYSTARTUP ()
....Your Start Up Function....
)
(setq S::STARTUP (append S::STARTUP MYSTARTUP))
The previous code appends your start up function to that of an existing S::STARTUP funtion, and then redefines the
S::STARTUP function to include you startup code. This works properly regardless of the prior existence of an
S::STARTUP function.
Mapcar
Have you ever wondered where you would use the MAPCAR function?
Here is a perfect example :
Say you have a list of data stored in variable arglist
(setq arglist '(12.0 145.8 67.2 "M20"))
You want to place each item in the list in it's own variable to use in your routine. One way to do it would be as follows
:
(setq a (nth 0 arglist))
(setq b (nth 1 arglist))
(setq c (nth 2 arglist))
(setq d (nth 3 arglist))
This works, but is an extremely slow way of processing the data as each variable requires a program statement.
A much more efficient way is to use the MAPCAR technique.
(mapcar 'set '(a b c d) arglist)
This routine maps the SET function to each element of the first list and it's corresponding element of the second list.
SET is used instead of SETQ to evaluate each quoted element of the first list. With the currently set arglist it sets a to
12.0, b to 145.8, c to 67.2 and d to "M20".
*Error* Trap Routine
Once you have written your AutoLisp routine you will find a need for an error trap routine. There is nothing worse
than your program crashing or just being cancelled and finding that some of your system variables have been
modified and no longer work as they should.
The following routine basically takes your settings and stores them.
If the routine runs correctly it simply resets these settings.
(This also saves you having to duplicate the same code over and over just to reset your system variables.)
If your program does crash or is cancelled it restores your settings back to where they were before the routine
started.
The following is an example routine with the error trap incorporated.
(Hint : You could also make the error trap routine a stand alone program, load it from your Acad Lisp file and call it
from multiple programs.
This way it would act as a Global Error Routine.)
More Tips and Tricks - Page III
http://www.afralisp.com/tips3.htm (2 of 4) [23/03/2005 05:48:03 p.m.]
(defun c:lsc ( / a1 a2)
(initerr)
(setq a1 (getvar "ltscale"))
(setq a1 (rtos a1))
(setq a2
(strcat "THE LTSCALE OF THIS DRAWING IS " a1))
(alert a2)
(reset)
(princ)
)
;;;*==========================================================
(defun initerr ()
(setq oldlayer (getvar "clayer"))
(setq oldsnap (getvar "osmode"))
(setq oldpick (getvar "pickbox"))
(setq temperr *error*)
(setq *error* trap)
(princ)
)
;;;*===========================================================
(defun trap (errmsg)
(command nil nil nil)
(if (not
(member errmsg
'("console break" "Function Cancelled"))
)
(princ (strcat "\nError: " errmsg))
)
(setvar "clayer" oldlayer)
(setvar "blipmode" 1)
(setvar "menuecho" 0)
(setvar "highlight" 1)
(setvar "osmode" oldsnap)
(setvar "pickbox" oldpick)
(princ "\nError Resetting Enviroment ")
(terpri)
(setq *error* temperr)
(princ)
)
;;;*===========================================================
(defun reset ()
(setq *error* temperr)
(setvar "clayer" oldlayer)
(setvar "blipmode" 1)
(setvar "menuecho" 0)
(setvar "highlight" 1)
(setvar "osmode" oldsnap)
(setvar "pickbox" oldpick)
(princ)
)
;;;*======================================================
(princ)

More Tips and Tricks - Page III


http://www.afralisp.com/tips3.htm (3 of 4) [23/03/2005 05:48:03 p.m.]
You are visitor number

Web afralisp.com
Be it hereby known that all the Coding and Tutorials contained on this here site, together with but not excluding all those other parts and utterances thereunto, shall not be warranted
against all defects, failures and malfunctions as shall occur between now and Thursday afternoon shortly before 2:00 am, during which time AfraLisp will maybe, at no charge to you or
the other person who was here before you, send the Coding or Tutorial to our Programmers, who will emerge from their caves and engage in rituals designed to cleanse the Coding or
Tutorial of evil spirits. This warranty does not cover attractive blonde females (not male) who may happen to visit this site or establishment or whatever you would like to call it.
Please respect the intellectual rights of others, or we will hunt you down and perform nasty things upon your body and appendages!!!
Copyright 1999-Perpetuity by AfraLisp
All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage
Powered by CORBIMITE.com
More Tips and Tricks - Page III
http://www.afralisp.com/tips3.htm (4 of 4) [23/03/2005 05:48:03 p.m.]
Search
The AutoLisp/Visual Lisp/VBA
Resource Website
Copyright 1999-Perpetuity by AfraLisp
Home Lisp Tutors Newsletter EuroTech Rubbish Lisp Tips Links Privacy
VBA Tutors Daily Cartoon Books Downloads VBA Tips CAD Vault IntelliCAD
"Utter Rubbish"
Page III
TO: All employees
FROM: The boss
DATE: October 4th, 2002
RE: Foul Language
It has been brought to management's attention that some individuals
throughout the company have been using foul language during the
course of normal conversation with their coworkers. Due to complaints
received from some employees who are easily offended, this type of
language will be no longer tolerated. We do, however, realize the
critical importance of being able to accurately express your feelings
when communicating with coworkers. Therefore, a list of new phrases
has been provided so
that proper exchange of ideas and information can continue in an
effective manner without risk of offending our more sensitive
employees.
TRY SAYING: Perhaps I can work late.
INSTEAD OF: When the f*ck do you expect me to do this?
TRY SAYING: I'm certain that is not feasible.
INSTEAD OF: No f*cking way!
TRY SAYING: Really?
INSTEAD OF: You've got to be sh*tting me.
TRY SAYING: Perhaps you should check with . . .
INSTEAD OF: Tell someone who gives a sh*t.
TRY SAYING: Of course I'm concerned.
INSTEAD OF: Ask me if I give a sh*t.
TRY SAYING: I wasn't involved in the project.
INSTEAD OF: It's not my f*cking problem.
TRY SAYING: That's interesting.
INSTEAD OF: What the f*ck?
TRY SAYING: I'm not sure I can implement this.
INSTEAD OF: F*ck it, it won't work.
TRY SAYING: I'll try to schedule that.
INSTEAD OF: Why the hell didn't you tell me sooner?
TRY SAYING: Are you sure this is a problem?
INSTEAD OF: Who the f*ck cares?
TRY SAYING: He's not familiar with the problem.
INSTEAD OF: He's got his head up his ass.
TRY SAYING: So you weren't happy with it?
INSTEAD OF: Kiss my ass.
TRY SAYING: I'm a bit overloaded at this moment.
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (1 of 15) [23/03/2005 05:48:07 p.m.]
INSTEAD OF: F*ck it, I'm on salary.
TRY SAYING: I don't think you understand.
INSTEAD OF: Shove it up your ass.
TRY SAYING: I love a challenge.
INSTEAD OF: This job sucks.
TRY SAYING: You want me to take care of that?
INSTEAD OF: Who the hell died and made you boss?
TRY SAYING: I see.
INSTEAD OF: Bite me.
TRY SAYING: Yes, we really should discuss it.
INSTEAD OF: Another f*cking meeting?
TRY SAYING: I don't think this will be a problem.
INSTEAD OF: I really don't give a sh*t.
TRY SAYING: He's somewhat insensitive.
INSTEAD OF: He's a f*cking prick.
TRY SAYING: She's an aggressive go-getter.
INSTEAD OF: She's a ball-busting bitch.
TRY SAYING: I think you could use more training.
INSTEAD OF: What the f*ck are you doing?
=====================
Two Irish men walk into a pet shop. Right away they go over to the bird section.
Gerry says to Paddy, "Dat's dem!"
The clerk comes over and asks if he can help them.
"Yeah, we'll take four of dem dere birds in dat cage dere," says Gerry, "Put dem in a peeper bag."
The clerk does and the two guys pay for the birds and leave the shop.
They get into Gerry's van and drive until they are high up in the hills and stop at the top of a cliff with a
500-foot drop.
"Dis looks like a grand place, eh?" says Gerry.
"Oh, yeh, dis looks good," replies Paddy.
They flip a coin and Gerry wins the toss.
"I guess I git to go first, eh Paddy?" says Gerry.
He then takes two birds out of the bag, places them on his shoulders and jumps off the cliff.
Paddy watches as his mate drops off the edge and goes straight down for a few seconds followed by a
'SPLAT'.
As Paddy looks over the edge of the cliff he shakes his head and says,
"Fock dat, dis budgie jumpin' is too fockin' dangerous for me"
======= PART TWO ======
A minute later, Seamus arrives. He too has been to the pet shop and he, walks up carrying the familiar
peeper bag.
He pulls a parrot out of the bag, and then Paddy notices that, in his other hand, Seamus is carrying a
gun.
"Hi, Paddy. Watch this," Seamus says and launches himself over the edge of the cliff.
Paddy watches as half way down, Seamus takes the gun and blows the parrot's head off.
Seamus continues to plummet until there is a SPLAT!, as he joins Gerry's remains at the bottom.
Paddy shakes his head and says, "An' oim never troyin' dat parrotshooting nider"
======= PART THREE ======
A few minutes after Seamus splats himself Sean strolls up. He too has been to the pet shop and he
walks up carrying the familiar
'peeper bag'. Instead of a parrot he pulls a chicken out of the bag, and launches himself off the cliff with
the usual result.
Once more Paddy shakes his head -
"Fock me Sean, first der was Gerry with his budgie jumping, den Seamus parrotshooting and now you
fockin' hengliding!"
===============
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (2 of 15) [23/03/2005 05:48:07 p.m.]
Mike goes into an elevator, looks up and sees this great big huge guy standing next to him.
The big guy sees little Mike staring at him, looks down and says, "7 feet tall, 350lbs, 20inch penis,
testicles 3lbs each, Turner Brown."
Mike just faints dead away and falls to the floor.
The big dude kneels down and brings him to by slapping his face and shaking him. He asks, "Are you
OK??"
In a very weak voice Mike says, "Excuse me, but what did you just say to me?"
The big dude says, "When I saw the curious look on your face, I just figured I'd give you the answers to
the questions everyone always asks me. "I'm 7 feet tall, weigh 350lbs, have a 20 inch penis, my testicles
weigh 3lbs each, and my name is Turner Brown."
Mike said, "Oh Thank God!!! .... I thought you said "Turn Around!!"
=============
Bob joins a very exclusive nudist colony. On his first day he takes off his clothes
and starts wandering around. A gorgeous petite blonde walks by him and the man
immediately gets an erection.
The woman notices his erection, comes over to him grinning sweetly and says:
"Sir, did you call for me?"
Bob replies: "No, what do you mean?"
She says: "You must be new here; let me explain. It's a rule here that if I give you an erection,
it implies you called for me." Smiling, she then leads him to the side of a pool, lays down on a
towel, eagerly pulls him to her and happily lets him have his way with her.
Bob continues exploring the facilities. He enters a sauna, sits down, and farts.
Within a few seconds a huge, horribly corpulent, hairy man with a firm erection lumbers out
of the steam towards him. The Huge Man says: "Sir, did you call for me?"
Bob replies: "No, what do you mean?"
The Huge Man: "You must be new here; it is a rule that when you fart, it implies you called for me."
The huge man then easily spins Bob around, bends him over the bench and has his way with him.
Bob rushes back to the colony office. He is greeted by the smiling naked receptionist:
"May I help you?"
Bob says: "Here is your card and key back. You can keep the $500 joining fee."
Receptionist: "But Sir, you've only been here a couple of hours;
you only saw a small fraction of our facilities.....
"Bob replies: "Listen lady, I am 58 years old...
I get a hard-on twice a month, but I fart 15 times a day!
======================
The Kenny Hangover Scale
1-Star Hangover *
No pain. No real feeling of illness. You slept in your own bed and when you woke up there were no
traffic cones in there with you. You are still able to function relatively well on the energy stored up from
all those vodka red bulls. However, you can drink 10 bottles of water and still feel as parched as the
Sahara. Even vegetarians are craving a Cheeseburger and a side of fries.
2-Star Hangover * *
No pain, but something is definitely amiss. You may look okay but you have the attention span and
mental capacity of a stapler. The coffee you hug to try and remain focused is only exacerbating your
rumbling gut, which is craving a full English breakfast. Although you have a nice demeanour about the
office, you are costing your employer valuable money because all you really can handle is some light
filing, followed by aimlessly surfing the net and writing junk e-mails.
3-Star Hangover * * *
Slight headache. Stomach feels crap. You are definitely a space cadet and not so productive. Anytime a
girl or lad walks by you gag because her perfume/aftershave reminds you of the random gin shots you
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (3 of 15) [23/03/2005 05:48:07 p.m.]
did with your alcoholic friends after the bouncer kicked you out at 1:45 a.m. Life would be better right
now if you were in your bed with a dozen doughnuts and a litre of coke watching daytime TV. You've
had 4 cups of coffee, a gallon of water, 2 Sausage Rolls and a litre of diet coke yet you haven't peed
once.
4-Star Hangover * * * *
You have lost the will to live. Your head is throbbing and you can't speak too quickly or else you might
spew. Your boss has already lambasted you for being late and has given you a lecture for reeking of
booze. You wore nice clothes, but you smell of socks, and you can't hide the fact that you either
missed an oh-so crucial spot shaving or it looks like you put your make-up on while riding the dodgems
depending on your gender. Your teeth have their own individual sweaters. Your eyes look like one big
vein and your hairstyle makes you look like a reject from the second-grade class picture circa 1976.
You would give a week's pay for one of the following: _Home time, doughnut and somewhere to be
alone, or a Time machine so you could go back and NOT have gone out the night before. You scare
small children in the street just by walking past them.
5-Star Hangover * * * * *
You have a second heartbeat in your head, which is actually annoying the employee who sits next to
you. Vodka vapour is seeping out of every pore and making you dizzy. You still have toothpaste crust in
the corners of your mouth from brushing your teeth. Your body has lost the ability to generate
saliva, so your tongue is suffocating you. You'd cry but that would take the last of the moisture left in
your body. Death seems pretty good right now.
Your boss doesn't even get mad at you and your co-workers think that your dog just died because you
look so pathetic. You should have called in sick because, let's face it, all you can manage to do is
breathe...very gently.
6-Star Hangover * * * * * *
You arrive home and climb into bed. Sleep comes instantly; as you were fighting it all the way home in
the taxi. You get about 2 hours sleep until the noises inside your head wake you up. You notice that
your bed has been cleared for take off and is flying relentlessly around the room. No matter
what you do you now, you're going to chuck. You stumble out of bed and now find that your room is in a
yacht under full sail. After walking along the skirting boards on alternating walls knocking off all the
pictures, you find the toilet. If you are lucky you will remember to lift the lid before you
spontaneously explode and wake the whole house up with your impersonation of walrus mating calls.
You sit there on the floor in your undies, Cuddling the only friend in the world you have left (the toilet),
randomly continuing to make the walrus noises, spitting, and farting. Help usually comes at this
stage, even if it is short lived. Tears stream down your face and your abdomen hurts. Help now turns
into abuse and he/she usually goes back to bed leaving you there in the dark. With your stomach totally
empty, your spontaneous eruptions have died back to 15-minute intervals, but your body won't relent.
You are convinced that you are starting to turn yourself inside out and swear that you saw your tonsils
projectile out your mouth on the last occasion. It is now dawn and you pass your disgusted partner
getting up for the day as you try to climb into bed. She/He abuses you again
for trying to get into bed with lumpy bits of dried vomit in your hair. _You reluctantly accept their advice
and have a shower in exchange for them driving you to the hospital. Work is not an option.
===============
Unauthorized Activity
This one is a cracker. It was an actual letter sent to a man named
Ryan DeVries by the Michigan Department of Environmental Quality, State
of Michigan.
Wait till you read this guy's response.......
***************************
Mr. Ryan DeVries
2088 Dagget Pierson, MI 49339
SUBJECT: DEQ File No. 97-59-0023; T11N; R10W, Sec. 20;
Montcalm County
Dear Mr. DeVries:
It has come to the attention of the Department of Environmental
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (4 of 15) [23/03/2005 05:48:07 p.m.]
Quality that there has been recent unauthorized activity on the
above referenced parcel of property. You have been certified as
the legal landowner and/or contractor who did the following
unauthorized activity:
Construction and maintenance of two wood debris dams across the
outlet stream of Spring Pond. A permit must be issued prior to
the start of this type of activity. A review of the Department's
files shows that no permits have been issued. Therefore, the
Department has determined that this activity is in violation of
Part 301, Inland Lakes and Streams, of the Natural Resource and
Environmental Protection Act, Act 451 of the Public Acts of 1994,
being sections 324.30101 to 324.30113 of the Michigan Compiled
Laws, annotated.
The Department has been informed that one or both of the dams
partially failed during a recent rain event, causing debris and
flooding at downstream locations. We find that dams of this
nature are inherently hazardous and cannot be permitted. The
Department therefore orders you to cease and desist all activities
at this location, and to restore the stream to a free-flow
condition by removing all wood and brush forming the dams from the stream channel. All restoration
work shall be completed no later than
January 31, 2002.
Please notify this office when the restoration has been completed
so that a follow-up site inspection may be scheduled by our staff.
Failure to comply with this request or any further unauthorized
activity on the site may result in this case being referred for
elevated enforcement action.
We anticipate and would appreciate your full cooperation in this
matter. Please feel free to contact me at this office if you have
any questions.
Sincerely, David L. Price
District Representative Land and Water Management Division
*******************
This is the actual response sent back........
Dear Mr. Price,
Re: DEQ File No. 97-59-0023; T11N; R10W, Sec. 20;
Montcalm County.
Your certified letter dated 12/17/01 has been handed to
me to respond to.
First of all, Mr. Ryan DeVries is not the legal Landowner and/or
Contractor at 2088 Dagget, Pierson, Michigan. I am the legal
owner and a couple of beavers are in the (State unauthorized)
process of constructing and maintaining two wood "debris" dams
across the outlet stream of my Spring Pond.
While I did not pay for, authorize, nor supervise their dam
project, I think they would be highly offended that you call their
skillful use of natures building materials "debris."
I would like to challenge your department to attempt to emulate
their dam project any time and/or any place you choose. I believe
I can safely state there is no way you could ever match their dam
skills, their dam resourcefulness, their dam ingenuity, their dam
persistence, their dam determination and/or their dam work ethic.
As to your request, I do not think the beavers are aware that they
must first fill out a dam permit prior to the start of this type of
dam activity.
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (5 of 15) [23/03/2005 05:48:07 p.m.]
My first dam question to you is: (1) Are you trying to discriminate
against my Spring Pond Beavers or (2) do you require all beavers
throughout this State to conform to said dam request?
If you are not discriminating against these particular beavers,
through the Freedom of Information Act, I request completed
copies of all those other applicable beaver dam permits that have
been issued. Perhaps we will see if there really is a dam violation
of Part 301, Inland Lakes and Streams, of the Natural Resource
and Environmental Protection Act, Act 451 of the Public Acts of
1994, being sections 324.30101 to 324.30113 of the Michigan
Compiled Laws, annotated.
I have several concerns. My first concern is - aren't the beavers
entitled to legal representation? The Spring Pond Beavers are
financially destitute and are unable to pay for said
representation - so the State will have to provide them with a dam lawyer.
The Department's dam concern that either one or both of the dams
failed during a recent rain event causing flooding is proof that
this is a natural occurrence, which the Department is required
to protect.
In other words, we should leave the Spring Pond Beavers alone
rather than harassing them and calling their dam names. If you
want the stream "restored" to a dam free-flow condition please
contact the beavers - but if you are going to arrest them, they
obviously did not pay any attention to your dam letter, they being
unable to read English.
In my humble opinion, the Spring Pond Beavers have a right to
build their unauthorized dams as long as the sky is blue, the grass
is green and water flows downstream. They have more dam rights
than I do to live and enjoy Spring Pond. If the Department of
Natural Resources and Environmental Protection lives up to its name, it
should protect the natural resources (Beavers) and the environment
(Beavers' Dams.).
So, as far as the beavers and I are concerned, this dam case can
be referred for more elevated enforcement action right now. Why
wait until 1/31/2002? The Spring Pond Beavers may be under the
dam ice then and there will be no way for you or your dam staff to
contact/harass them then.
In conclusion, I would like to bring to your attention to a real
environmental quality (health) problem in the area. It is the
bears!
Bears are actually defecating in our woods. I definitely believe
you should be persecuting the defecating bears and leave the beavers
alone. If you are going to investigate the beaver dam, watch your
step! (The bears are not careful where they dump!)
Being unable to comply with your dam request, and being unable
to contact you on your dam answering machine, I am sending this
response to your dam office.
Sincerely,
Stephen L.Tvedten
===================
One night, a police officer was staking out a particularly rowdy bar for possible violations of the driving
under the influence laws.
At closing time, he saw a fellow stumble out of the bar, trip on the curb, and try his keys on five different
cars before he found his. Then, sat in the front seat fumbling around with his keys for several minutes.
Everyone else then left the bar and drove off.
Finally, the guy sitting in his car started his engine and began to pull away.
The police officer was waiting for him. He stopped the driver, read him his rights and administered the
Breathalyzer test. The results showed a reading of 0.0 % !
The puzzled officer demanded to know how that could be.
The driver replied, "Tonight, I'm the Designated Decoy."
=================
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (6 of 15) [23/03/2005 05:48:07 p.m.]
Extract from the Australian Etiquette Handbook
GENERAL:
1. Never take a beer to a job interview.
2. Always identify people in your yard before shooting them.
3. If you have to vacuum the bed, it's time to change the sheets.
4. Even if you're certain you're included in the will, it's rude to take the trailer to the funeral home.
DINING OUT:
1. When decanting wine from the box, tilt the paper cup and pour slowly so as not to "bruise" the wine.
2. If drinking directly from the bottle, hold it with only one hand.
ENTERTAINING IN YOUR HOME:
1. A centrepiece for the table should never be anything prepared by a taxidermist.
2. Don't allow the dog to eat at the table, no matter how good his manners.
PERSONAL HYGIENE:
1. While ears need to be cleaned regularly, this should be done in private, using one's OWN keys.
2. Even if you live alone, deodorant isn't a waste of money.
3. Use of toiletries can only delay bathing a few days.
4. Dirt and grease under the fingernails is a no-no, as it detracts from a woman's jewelry and alters the
taste of finger foods.
DATING (Outside the Family):
1. Always offer to bait your date's hook, especially on the first date.
2. Be assertive. Let her know you're interested: "I've been wanting to go out with you since I read that
stuff on the crap house door two years ago."
3. Establish with her parents what time she's expected back. Some will say 10:00 PM, others might say
"Monday." If the latter is the answer, it's the man's responsibility to get her to school on time.
THEATRE ETIQUETTE:
1. Crying babies should be taken to the lobby and picked up after the movie ends.
2. Refrain from talking to characters on the screen. Tests have proven they can't hear you.
WEDDINGS:
1. Livestock is a poor choice for a wedding gift.
2. Kissing the bride for more than five seconds may get you shot.
3. For the groom, at least, rent a tux. A track suit with a cummerbund and a clean football jumper can
create a tacky appearance.
4. Though uncomfortable, say "yes" to socks and shoes for the occasion.
DRIVING ETIQUETTE:
1. Dim your headlights for approaching vehicles, even if the gun's loaded and the drivers heads in sight.
2. When approaching a round-about, the vehicle with the largest tyres doesn't always have the right of
way.
3. Never tow another car using panty hose and duct tape.
4. When sending your wife down the road with a petrol can, it's impolite to ask her to bring back beer,
too.
=================
Politics..
Returning from school one day, little Johnny goes to his father and asks:
- Dad, our teacher mentioned during the history class today one word I didn't know...
- Yes son...?
-It's "politics", dad. Could you explain me what it means?
- Well now, Johnny - says his father while frowning - that's a rather complex term.. especially for
someone as young as you; to make it easier, let's put it into your perspective: I am your father. I work
and bring money to this house. I make all of the most important decisions. Therefore let's call me
Capitalism. Your mum, she run's the household - so she's something like a Government around here.
Our maid does most of the toil around the house - so she can be the Working Class. You son, let's call
you The People. And your little baby brother is our youngest family member - hence he's the future.
That's pretty much how politics works, son. Was that good enough for you?
-Well, thank's dad. It was a bit confusing though. I'll have to sleep on it a bit and see whether I can
understand it tomorrow..
Later that night, Johnny suddenly wakes up. He's hungry. On the way to the kitchen, he hears his little
brother screaming from his cot. So he sneaks to his room, takes a good look around, and finds his
sibling in soiled pampers ;-) The stench is unbearable. And since Johnny is only a 9-year old kid, with
no baby-training, he shouts for his parents.
Nothing. He shouts again, only louder. Still nothing. Quite frustrated with the situation at hand, he heads
for his parents' bedroom, where he finds his mother fast asleep, but no trace of the "patter familias".
Utter Rubbish-Page II
http://www.afralisp.com/utterrubbish2.htm (7 of 15) [23/03/2005 05:48:07 p.m.]
Puzzled, he goes to the maid's chambers - and lo! and behold there's his dad, (with the maid, of course),
cheating on his wife! Exasparated, Johnny finally gives up, and goes back to bed.
The next day, Johnny's father (unaware of his son's revelations the previous night)goes to his boy and
asks:
- So..is politics any clearer to you now?
- 'Course it is dad. While Capitalism is screwing the Working Class, Government is fast asleep, People is
being ignored, and our Future is in deep sh*t!
=================
Ever wonder why Middle Eastern Muslim terrorists are so quick to
volunteer for suicide missions?
Let's just take a closer look at their lifestyle...
No premarital sex.
No Booze. None. Never.
No TV. No cable TV. No satellite TV
No Spice channel. No Playboy channel. No ESPN. No Hooters!
No Sports Illustrated Swimsuit Edition.
Sand. F*ckin' sand everywhere!
No organized sports of any kind. That's right No Sports!
Women are to be completely covered and wear veils.
No thongs. No Victoria's Secret.
Very, very few cars.
Camels. Lots of camels. Stinking, filthy camels.
Sand. F*ckin' sand everywhere!
Ever try to fish at an Oasis? No bass boats. No bass. No fish.
Sandstorms. More f*ckin' sand everywhere!
Rags for clothes and dishcloths with fanbelts for hats.
Camel and goat burgers cooked over burning camel dung chips.
Eating with your right hand only because you wipe your butt
with your left.
Toilet tissue is unknown.
Sand. F*ckin' sand everywhere!
No Golf. Just sand traps.
Constant wailing next door...no wait, that's their music.
Praying 5 times a day. For what? More of this life?
Oh, and did I mention the f*ckin' sand?
And when you die it's supposed to get better.
No wonder they volunteer for suicide missions!!
================
An elderly Italian man asked the local priest to hear his confession:
"Father, during World War 2 a beautiful woman knocked on my door and asked me to hide h