My Photo

Search


  • Search 280+ postings

Site Awards



Syndications for this Site


Blog Roundup

What happens when you take "1 Part CAD Site" and mix it (not shake it) with "1 Part AutoCAD RSS Feed Aggregator" or for those that know AutoLISP (+ "CAD Site" "AutoCAD RSS Feed Aggregator")?  I'm not sure, but if it was possible to derive a solution from the formula I am sure you would get something close to CADtutor.net.  While I have often visited CADtutor.net it wasn't until recently that I discovered that the site was aggregating many of the commonly visited AutoCAD and CAD related blogs in the industry.  It is a great way to keep up to date on what is happening in the industry as well as learn new tips and tricks about AutoCAD and other programs that you might use.  The link to the AutoCAD RSS Feed page on CADTutor.net is below:

http://www.cadtutor.net/forum/forumdisplay.php?f=38

Michael's Corner is also a great section of CADtutor.net to visit as well.  He has been writing a monthly column on various aspects of AutoCAD since 2003, with the exception of January of 2008 when he spent a few weeks away on vacation when I filled in for him.  Michael is a great guy and is always willing to help AutoCAD users when he can.

Sincerely,
  Lee

Mail Bag - Why do some commands support the use of additional characters in front of their names, and others do not?

Mailbag_header_2
The Mail Bag has become one of my favorite new little segments on my blog, and by the number of comments that I have been getting it looks like many others agree as well.  In today's Mail Bag, a reader has a question about why there are some commands that have an additional character in front of their names and there is the same command with out that additional character.  For example, to plot a drawing you would use the PLOT command, but there is also a -PLOT command.  Both the PLOT and -PLOT command allow you to plot a drawing, but to get to the final output from the command the process is a little bit different.  The PLOT command displays a dialog box under normal situations, while the -PLOT command displays a series of command prompts to help plot a drawing.  Below is a listing of a few characters that you might encounter when creating your own macros, or when you are trying to create a basic script to automate AutoCAD or AutoCAD LT.

- (Hyphen) - Command displays command prompts instead of a dialog box, in most cases the commands that support a version of the command are ones that display a dialog box.  A few examples are the -PLOT vs. PLOT, -LAYER vs. LAYER, and -ARRAY vs. ARRAY commands.

+ (Plus) - There are a couple different types of commands that use the plus symbol in front of commands.  The most common commands that have a plus symbol in front of their name are the ones with tabs, such as the Options dialog box or UCS dialog box.  A few examples are the +OPTIONS vs. OPTIONS, +DSETTINGS vs. DSETTINGS, and +UCSMAN vs. UCSMAN commands.  When the +OPTIONS is typed at the command line the prompt Tab index <0>: is displayed.  If you want to display the User Preferences tab you would enter a value of 5, the leftmost tab is 0.  Another version of a command that can use the plus symbol is the variation of the PUBLISH command.  If a plus is placed in front of the command you are able to browse and select an existing DSD file from a standard file navigation dialog box.

' (Apostrophe) - The apostrophe symbol is used by some commands that can be used while another command is already in progress, in this state a command is known as a transparent command.  Most commands can not be used transparently when other commands are running.  The most commonly used commands that are used transparently are ZOOM, PAN, and -VIEW.  There are many other commands that can be used transparently, as well and those are often used to control entity property settings such as COLOR, LTYPE, and SETVAR.  To use a command transparently, simply start another command that displays a command prompt such as the LINE command, and then enter 'ZOOM at the command prompt while the LINE command is still in progress.  AutoCAD indicates that you are in a transparent command with the display of >> in front of the command prompt.  Once the transparent command has ended or been cancelled you are returned to the previous command prompt of the original command, in the example it is the LINE command.

Command: l
LINE Specify first point: 'zoom

>>Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>:

>>Press ESC or ENTER to exit, or right-click to display shortcut menu.

Resuming LINE command.
Specify first point:
Specify next point or [Undo]:

For additional information on what commands can be used transparently, which ones support a hyphen or simply a list of all commands in AutoCAD use the links below.

Transparent AutoCAD Commands
Hyphened AutoCAD Commands
AutoCAD Command Reference (R12 through 2007)

Another create feature when wanting to learn about what commands and system variables in AutoCAD is the AutoComplete feature at the command prompt.  It allows you to find a command that you only remember the first few letters of.  To use AutoComplete, type in the first few letters at the command prompt and press the TAB key until you find the command you are looking for.  So if you wanted to know all of the commands that can use the + (plus) symbol, you can type the + symbol and then press Tab until you cycle through all the commands or until you found the one that you are interested in.

For some additional information on the AutoComplete feature see the links below:
Forgot a Command's Name, Now What?
What Was That AutoCAD System Variable or Command?

Got a question that you are looking for an answer to, send me an e-mail and I will be more than happy to help you out.  Use the Email Me link below the About section on this page or click here.

Sincerely,
  Lee

Using Icon Switches with AutoCAD 2007

Icon switches (or command line switches) are often a forget method of customizing AutoCAD to gain some additional productivity benefits.  Did you know you could use an icon switch to specify the default profile or drawing template that AutoCAD starts up with when you double-click on the desktop icon.  Maybe you have been trying to figure out a way to specify a specific workspace to be displayed when you start up AutoCAD, wonder no more.  Icon switches allow you to do those things and much more with AutoCAD 2007.  AutoCAD has supported icon switches for along time now, since about R14.  To learn more about the icon switches in AutoCAD 2007 and previous release, click the link to access the AutoCAD Icon Switches PDF file from HyperPics.com.  The PDF file includes information about all the different icon switches available, and even a short tutorial on how to modify a desktop icon to use the icon switches.

Mail Bag - How can I align text when creating a new text object in AutoCAD?

Mailbag_header_2
I recently got an e-mail about how you could align a new text object vertically based on existing text object that already exists in the drawing.  Most people and I am among them, often create a text object and then align it with an existing text object, but you can cut down on having to start the Move command and picking a base point and then a second point by using point filters or object snap tracking based on your preference to align text objects.

Note: How the text objects align is based on the current text alignment of the new text object and the existing text object.

Using Object Snap Tracking to Align Text Vertically

  1. Before you start creating a new text object, turn on the Insertion object snap and enable object snap tracking by clicking the OTRACK button on the status bar.
  2. Start the DTEXT or MTEXT command.
  3. At the Specify start point of text or Specify first corner prompt, hover over the text object's Insertion point.  You should see a vector is displayed vertically from the Insertion point which allows you to specify a point along that vector path.
    Aligntextvertically
  4. Enter a distant to specify a new point, or simply click along the vector.
  5. Once the start point or first corner has been specified you can finish the command like you normally would.

Using Point Filters to Align Text Vertically

  1. Start the DTEXT or MTEXT command.
  2. At the Specify start point of text or Specify first corner prompts, enter .X and press Enter.  You could also hold down the SHIFT key, right-click and select Point Filters >> .X.
  3. At the prompt .X of, enter INS and press Enter.  You could also hold down the SHIFT key, right-click and select Insert.
  4. Select the Insertion point of the text object you want to vertically align with, and then pick a second point to determine the Y coordinate value.
  5. Once the start point or first corner has been specified you can finish the command like you normally would.

Alternatively, you could also use AutoLISP to simplify the process even further.  Belolw is a very basic example that simply starts the DTEXT command based on the insertion point of a selected text object.  The example lacks some error checking and is designed just to show a conceptual way of how to align text vertically or horizontally with other text object that already exists in a drawing.

(defun c:AlignVertically ( / ent ent_data pt-align)
  (if (setq ent (entsel "\nSelect a text object to align vertically with: "))
    (progn
      (setq ent_data (entget (car ent)))
      (if (setq pt-align (getpoint (cdr (assoc 10 ent_data)) "\nSpecify start point: "))
        (command ".dtext" pt-align)
        (prompt "\nNo Point selected.")
      )
    )
    (prompt "\nNo object selected.")
  )
(princ)
)

Sincerely,
  Lee

AutoCAD 2007 and AutoCAD 2007 based products coming

Well its no secret that AutoCAD is on an anual release cycle and with that in mind, AutoCAD 2007 is just around the corner. Today markes the first day that beta sites can only talk about the up and coming AutoCAD 2007 product. No don't ask what takes place during the beta program as we are not allowed to talk about that.  If you want to know what happens during a beta program, feel free to sign up at the My Feedback portal that Autodesk hosts.

I have been busy working on projects related to AutoCAD 2007 for many months now and have not had a lot of time to gather some nice documents to display on the website or my blog, but a good friend and great author Ellen Finkelstein took a break from writing an update to the AutoCAD and AutoCAD LT Bible to put some stuff together though.  You can read about some of the many new and exciting features on Ellen's website at http://www.ellenfinkelstein.com/autoCAD.html.

Yes, I have time for one quick question.

Question in the back row: Will you be updating the guides that you maintain for AutoCAD 2007?

Yes, I will start posting some stuff over the next few days on What's New in the new release, and will work on getting some of my guides updated that I publish with each new release. That's all the time I have for questions as I need to get some of my projects out the door.

Sincerely,
  Lee

Working with Environment Variables through AutoLISP

Ok I know environment variables are not as popular as they once use to be, but they can be very powerful in setting up unique values on the machine for company settings.  As you might have noticed in a few of the past postings I have been releasing sample code that uses the FSO (File System Object) of the Shell object.

This sample follows that same trend and uses the Shell object to manipulate environment variables that are maintained by the OS.  Below are three, yes I said three different examples of using the Shell object.  The first shows how to expand environment variables in a string.  This can be great for building file paths or getting information about the OS or PC.

;; Shows how to use expanding environment strings
;; Usage: (ExpEnvStr "%TEMP%\\MYDATA")
;; Results of sample: "C:\\DOCUME~1\\Lee\\LOCALS~1\\Temp\\MYDATA"
(defun ExpEnvStr ( strVal / wshShell)
  (vl-load-com)

  (setq wshShell (vlax-create-object "WScript.Shell"))
  (vlax-invoke-method wshShell 'ExpandEnvironmentStrings strVal)
)

;; Retreive the value of the environment variable
;; Usage: (GetEnvStr "SYSTEM" "USERID")
(defun GetEnvStr ( strVarType strVarName / wshShell envVars)
  (vl-load-com)

  (setq wshShell (vlax-create-object "WScript.Shell"))
  (setq envVars (vlax-get-property wshShell 'Environment strVarType))
  (vlax-get-property envVars 'Item strVarName)
)

;; Set the value to an environment variable
;; Usage: (SetEnvStr "SYSTEM" "USERID" "L123")
(defun SetEnvStr ( strVarType strVarName strVarVal / wshShell envVars)
  (vl-load-com)

  (setq wshShell (vlax-create-object "WScript.Shell"))
  (setq envVars (vlax-get-property wshShell 'Environment strVarType))
  (vlax-put-property envVars 'Item strVarName strVarVal)
)

Got an idea for some sample code?  If you do, I would like to hear from you.  Your idea might be selected and the results posted on the blog or website.

Sincerely,
  Lee

Creating a New Document in AutoCAD with AutoLISP

It must be getting close to the end of the year and time to clean out the good old sample vault.  Many of the samples that have been put up on my blog have been created throughout this year based on questions that I have gotten through e-mail, in passing at events such as AU and even from my online forum.

Have you ever wanted to create a new document using a macro and tried to use the NEW command to do this?  Using the NEW command might not be the best approach.  Below is a very basic custom function that demonstrates how to create a new drawing based on a template through AutoLISP.

;; Begin Code
;; Written by: Lee Ambrosius
;; Command macro option ^P(createnewdwg "acadiso.dwt")

;; Load the Visual LISP environment
(vl-load-com)

;; Custom routine that allows you to create a new drawing
(defun createNewDWG (templateName)
  (vla-activate (vla-add (vla-get-documents (vlax-get-acad-object)) templateName))
(princ)
)
;; End Code

Sincerely,
  Lee

Printing a MS Word Doc using AutoLISP

Its that time of the year for giving out gifts and such... so today I have decided to drop a smaple of code that deomstrates how to print a MS Word document using AutoLISP.  What a great way to print your holiday newsletter while the boss things you are working in AutoCAD.  OK maybe not thebest of uses for the code sample.  It is possible to automate the printing process of not only your AutoCAD drawings, but also the spces that might need to go out with them at the same time.  The code can be modified to specifiy a printer if need be, but it is designed to go to the default printer though.

:: Begin Code
;; Written by: Lee Ambrosius, HyperPics LLC

;; Usage: (PrintMSWordDoc "C:\\test.doc")
;; Open a document in MS Word and Print it out
(defun PrintMSWordDoc ( strWordDoc / wordObj wordDocsObj wordDocObj)
  (vl-load-com)

  ;; Variable to define constant used in the Close and Quit methods
  (setq wdDoNotSaveChanges 0)

  ;; Create a new MS Word object
  (setq wordObj (vlax-invoke-method (vlax-get-acad-object) 'GetInterfaceObject "Word.Application"))

  ;; Get a reference to the Docuemnts collection in Word
  (setq wordDocsObj (vlax-get-property wordObj 'Documents))

  ;; Open the drawing
  (setq wordDocObj (vlax-invoke-method wordDocsObj 'Open strWordDoc))

  ;; Print it out
  (vlax-invoke-method wordDocObj 'PrintOut)

  ;; Close the document and don't save any changes
  (vlax-invoke-method wordDocObj 'Close wdDoNotSaveChanges)

  ;; Close the instance of the MS Word application
  (vlax-invoke-method wordObj 'Quit wdDoNotSaveChanges)
(princ)
)
;; End Code

Sincerely,
  Lee

Which Drives are Available?

From time to time you might want your AutoLISP application to be able to write to a specific drive or drives in a specific order if you are working with a group of users that might do some travelling.  If you want to test to see which drives are available through AutoLISP, you could use the function vl-directory-files.  This would force you to test each letter combination which can take time and it doesn't tell you if the drive is ready or not.  Below is an example using the FSO object to get all the available drives on the machine, and test to see what type of drive it is and if it is ready or not.

;; Begin Code
(defun GetDrives ( / wshFSO driveObjs)
  (vl-load-com)

  (if (= wshLibImport nil)
    (progn
      (vlax-import-type-library :tlb-filename "c:\\windows\\system32\\wshom.ocx"
                          :methods-prefix "wshm-"
                          :properties-prefix "wshp-"
                          :constants-prefix "wshk-"
      )
      (setq wshLibImport T)
    )
  )

  (setq wshFSO (vlax-create-object "Scripting.FileSystemObject"))
  (setq driveObjs (wshp-get-Drives wshFSO))

  (vlax-for driveObj driveObjs
    (progn
      (prompt (strcat "\nDrive Letter: " (vlax-get-property driveObj 'DriveLetter)))
      (prompt "\nDrive Type: ")
      (cond
        ((= (vlax-get-property driveObj 'DriveLetter) wshk-CDRom)(prompt "CDROM"))
        ((= (vlax-get-property driveObj 'DriveLetter) wshk-RamDisk)(prompt "Ram Disk"))
        ((= (vlax-get-property driveObj 'DriveLetter) wshk-Fixed)(prompt "Fixed"))
        ((= (vlax-get-property driveObj 'DriveLetter) wshk-Removable)(prompt "Removeable"))
        ((= (vlax-get-property driveObj 'DriveLetter) wshk-UnknownType)(prompt "Unknown"))
      )
      (prompt (strcat "\nIs Ready: "))
      (if (= (vlax-get-property driveObj 'IsReady) :vlax-true)
        (prompt "True")
        (prompt "False")
      )
    )
  )
(princ)
)
;; End Code

Sincerely,
  Lee

Obtaining a Short File Name through LISP

Many that know me, know that I like to dabble from time to time with programming AutoCAD.  Ok, maybe it is not just dabbling, but rather pushing things right to the edge.  If you have an old program or have a need for file name structure of 8.3 then you might enjoy the routine below.  It is an example of how AutoLISP or Visual LISP can use COM objects to extend the functionality of the language.  The sample shows how to use the File System Object.

;; Begin Code
(defun GetShortName ( strFileName / wshFSO fileObj)
  (vl-load-com)

  (setq wshFSO (vlax-create-object "Scripting.FileSystemObject"))
  (setq fileObj (vlax-invoke-method wshFSO 'GetFile strFileName))
  (vlax-get-property fileObj 'ShortPath)
)
;; End Code

Happy coding...

Sincerely,
  Lee

Feeds


  • Between the Lines Blog

  • Will render for food... Digital Media Blog

  • HyperPics.com