Nate Holt's Blog

February 16, 2011

Atoms-Family: tracking globals in AutoCAD Electrical

Filed under: Electrical — nateholt @ 11:03 am

No, not the 1960’s TV series… this is about a generic AutoLISP function. Use it to code-up a tool to monitor creation and modification of global variables as AutoCAD Electrical runs.

Disclaimer: this may or may not be useful information.

AutoCAD Electrical holds a lot of stuff in global variables as it does its thing. If you take a look at the source code for the Spreadsheet –> PLC I/O utility that Autodesk kindly ships with every copy of the product, you’ll notice quite a few variables with a prefix “GBL_wd_”. These are Lisp variables that hold data that is global to the overall AutoCAD Electrical application.

For example, there is the “WD_M” block that you’re probably familiar with. It has 70-80 attributes on it with key values that influence what and how things happen on the active drawing. AutoCAD Electrical reads this block and retrieves these attribute values one time and then saves the values as global variable called “GBL_wd_m”. Whenever you then ask AutoCAD Electrical to do some task on this drawing that requires it to retrieve a setting held on the WD_M block, it just grabs the value from the global variable GBL_wd_m instead of having to search the drawing for the WD_M block instance and then reading the appropriate attribute value off of it. Saves a lot of time.

There are lots of them and the names of these and lots of other stuff can be listed at any time with the simple Lisp expression (atoms-family 1) [Enter].

Here’s a tool that makes use of this atom-family call to track/monitor globals as AutoCAD Electrical runs …

Example Run

Starting up AutoCAD Electrical, we open up a drawing from the Project Manager. Then appload the above utility “GBL_TRACKER.LSP”. Type GBL_TRACKER [Enter] at the “Command:” prompt.

Now we pick an AutoCAD Electrical command, let’s say we try to SCOOT a wire. Then type GBL_TRACKER [Enter] again…

The circled global shows that the drawing’s valid wire type layer names are held in a global.

How might this be useful?

Let’s say that when we run  our SCOOT command and pick on a line that is on a layer that is not currently defined as a valid wire layer, then the SCOOT command aborts. For example, let’s say that we have drawn a cable “fan-in” and marked it with a cable marker. The “fan-in” part of the wire is on layer called “_MULTI_WIRE” which is not a valid wire layer. But we’d like to use SCOOT to adjust it.

From what our tool’s output tells us, it looks like valid wire layer names are held in a global variable. What if we try to temporarily add layer name “_MULTI_WIRE” to the global variable that holds the drawing’s valid wire layer names? Will SCOOT then “work” when we pick on a LINE that is on non-wire layer “_MULTI_WIRE” ? Let’s try it…

To add this to the global variable, we’d type or program this expression:

(setq GBL_wd_active_dwg_wiretype_cache_lst (cons "_MULTI_WIRE" GBL_wd_active_dwg_wiretype_cache_lst))

And now, when we try to SCOOT the non-wire and attached cable marker, SCOOT does not error out… but operates as if the non-wire line entity was actually a wire! Cool.

To restore normal SCOOT operation, just set the global to nil (and it will re-read the next time it is needed).

(setq GBL_wd_active_dwg_wiretype_cache_lst nil)  


UPDATE: forgot to mention this… you can view the contents of any global variable at any time. Just type the global variable name at the “Command:” prompt BUT precede the name with a ! character. For example, to display the value of the GBL_wd_m global, type this:

Command: !GBL_wd_m [enter]

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: