2.25.2010

Transparent CAD Administration

No CAD admin likes dealing with users (though they are inherently part of the job). They mess with things they shouldn't and use unapproved software. But I digress.

Fortunately, in most offices, there is at least one common .lsp file that everyone has in their AutoCAD Startup Suite. If they don't, you can use yesterday's post as a guideline on how to add a .lsp file to everyone's Startup Suite using a batch file or a Windows-aware programming language (i.e. VBScript or PowerShell).

Once everyone has a common, network-based .lsp file in their Startup Suite, you can use this to your advantage and change its contents to do your bidding. For starters, you can use the code from yesterday's post to add additional items to users' Startup Suites.

Here are a few Lisp code snippets that will help you get started:
; Items in brackets [] are meant to be replaced with your specific values.


; If using any vlax functions:
(vl-load-com)


; A common task is to make sure a user has a certain directory in their support paths.
; The following snippet adds a given support directory to AutoCAD's support paths.
(setq suppdir "[YourSupportDir]")
(if (not (vl-string-search suppdir (getenv "ACAD")))
(setenv "ACAD" (strcat (vl-string-right-trim ";" (getenv "ACAD")) ";" suppdir))
)
(setq suppdir nil)
; If you want to explicitly set the support paths, just use (setenv "ACAD" "[SupportPathsHere]").
; The paths must be separated by semicolons.


; If your company uses a standard profile, you can use this snippet to make sure everyone uses it.
; Use yesterday's post to determine the current revision and version of AutoCAD and replace
; the x's with the correct values.
(vl-registry-write
"HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\Rxx.x\\ACAD-xxxx:xxx\\Profiles"
nil
"[YourDefaultProfile]"
)


; Say you want to make sure your users all have a certain tool palette.
(setq tooldir "[YourToolPaletteDirectory]"
toolpaths (vlax-get-property (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'Preferences) 'Files) 'ToolPalettePath)
)
(if (not (vl-string-search tooldir toolpaths))
(vlax-put-property
(vlax-get-property (vlax-get-property (vlax-get-acad-object) 'Preferences) 'Files)
'ToolPalettePath
(strcat (vl-string-right-trim ";" toolpaths) ";" tooldir)
)
)
(setq tooldir nil toolpaths nil)

; If you want to disallow your users from having their own tool palettes, use this:
(vlax-put-property
(vlax-get-property (vlax-get-property (vlax-get-acad-object) 'Preferences) 'Files)
'ToolPalettePath
[ToolPalettePaths]
)
; These paths should also be separated by semicolons.


; Last but not least, if you want to do something for a specific user:
(if (= "johndoe" (getvar "LOGINNAME"))
; do stuff for John Doe
)

; You can modify the above snippet with an OR statement to do something for a group of users as well:
(if (or
(= "johndoe" (getvar "LOGINNAME"))
(= "janedoe" (getvar "LOGINNAME"))
)
; do stuff for the Does
)

Enjoy, and as always comments are welcome.

2.24.2010

startup.lsp: Adding to AutoCAD's Startup Suite programmatically using Lisp

At one time or another, it becomes desirable to add a .lsp file or otherwise to AutoCAD's Startup Suite programmatically. The following Lisp function adds a given file to the current profile's Startup Suite. This is accomplished by manipulating registry values and can be done with VBScript, PowerShell, or just about any other Windows-aware programming language.

In HKEY_CURRENT_USER\Software\Autodesk\AutoCAD, there is a value called "CurVer" which contains the main revision of AutoCAD in use. In that revision's key, there is another "CurVer" value which is the main version of AutoCAD in use. In that version's key, there is a "Profiles" key whose default value is the current profile. Inside that, inside \Dialogs\Appload\Startup\, there are several values. There are "nStartup" values for every startup entry, (i.e. "1Startup","2Startup","3Startup") and a "NumStartup" key containing the number of startup entries.

In summary, the startup entries are contained in:
HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\[Revision]\[Version]\Profiles\[CurrentProfile]\Dialogs\Appload\Startup\

Edit: If working with a fresh installation, there may not be a Startup key. The code now accounts for this.

Download startup.lsp
(defun addToStartupSuite (filename / regpath revision version default ct numstartup n)
(setq regpath "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD"
revision (vl-registry-read regpath "CurVer")
version (vl-registry-read (setq regpath (strcat regpath "\\" revision)) "CurVer")
default (vl-registry-read (setq regpath (strcat regpath "\\" version "\\Profiles")))
regpath (strcat regpath "\\" default "\\Dialogs\\Appload\\Startup")
ct 1
)
(if (setq numstartup (vl-registry-read regpath "NumStartup"))
(progn
(setq n (1+ (atoi numstartup)))
(while (and
(< ct n)
(/= filename (vl-registry-read regpath (strcat (itoa ct) "Startup")))
)
(setq ct (1+ ct))
)
)
(setq n 1)
)
(if (= n ct)
(progn
(vl-registry-write regpath (strcat (itoa n) "Startup") filename)
(vl-registry-write regpath "NumStartup" (itoa n))
)
)
)

Comments are welcome.

2.20.2010

How to solve the Colebrook equation in Excel/VBA

I see that a lot of people have been searching for a quick and easy way to solve the Colebrook equation for the Darcy friction factor in Excel/VBA. Well, here you go. Thanks to Efficient Resolution of the Colebrook Equation by Didier Clamond, the Colebrook equation can be solved and the Darcy friction factor found with a very short and simple function.

This two iteration solving method is EXTREMELY accurate, "around machine precision" (Clamond).

The following VBA code is derived from Clamond's MATLAB implementation supplied in his paper. It can be added to a new VBA Module in your Excel spreadsheet so that you can access it from cells (i.e. "=Colebrook(somecell, anothercell)").

R is the Reynolds number (Re, dimensionless), and K is relative roughness (K = e/Dh, dimensionless), which is equal to the absolute roughness divided by the hydraulic diameter. Watch your units!

The returned result is of course the Darcy friction factor, which is meant to be used with the Darcy-Weisbach equation to calculate pressure drop.

Function Colebrook(R As Double, K As Double) As Double
Dim X1 As Double, X2 As Double, F As Double, E As Double
X1 = K * R * 0.123968186335418
X2 = Log(R) - 0.779397488455682
F = X2 - 0.2
E = (Log(X1 + F) + F - X2) / (1 + X1 + F)
F = F - (1 + X1 + F + 0.5 * E) * E * (X1 + F) / (1 + X1 + F + E * (1 + E / 3))
E = (Log(X1 + F) + F - X2) / (1 + X1 + F)
F = F - (1 + X1 + F + 0.5 * E) * E * (X1 + F) / (1 + X1 + F + E * (1 + E / 3))
F = 1.15129254649702 / F
Colebrook = F * F
End Function

Enjoy, and thank you to Didier Clamond for coming up with this solving method!

2.05.2010

A script to download and compile Audacious

The following script will download, compile and install the latest version of Audacious media player from the most up-to-date source code available via Mercurial. It will make a new directory called 'audacious' in the directory it is run in, so keep that in mind. It will also download the most recent 'adplug.db' for the Adplug plugin.

Download audinstall.sh

Run the script by typing ./audinstall.sh in a terminal. The newly created executable will be /usr/local/bin/audacious. Shortcuts will be created in the Applications>Other folder in Ubuntu.

-----------------------------------------------------------------------

#!/usr/bin/env bash

sudo apt-get build-dep audacious audacious-plugins
sudo apt-get install mercurial automake

sudo rm -rf audacious
mkdir audacious
cd audacious

hg clone http://hg.atheme.org/audacious/ audacious-devel
hg clone http://hg.atheme.org/audacious-plugins/ audacious-plugins-devel

for d in *
do
cd "$d"
./autogen.sh
./configure
make
sudo make install
cd ..
done

wget http://downloads.sourceforge.net/project/adplug/Database/2006-07-06/adplugdb-2006-07-07.tar.gz
tar -xzf adplugdb*
sudo rm -rf ~/.adplug
mkdir ~/.adplug
cp 20*/adplug.db ~/.adplug/