Thursday, December 16, 2010

Architecture of a Streamlined Design Environment

As I have mentioned in previous posts I am a fan of using the mnl as an access point to all custom AutoCAD menu content. Another popular method (which I avoid) is to place menu loading calls in the acaddoc.lsp file. My philosophy is to minimize modifying out of the box AutoCAD files and keeping as much custom content separated from delivered AutoCAD files as possible. This helps for a few reasons: one, upgrades are easier and smoother if all of your custom content is separate from the delivered AutoCAD files and can simply be reintroduced to the next version of AutoCAD. Another benefit is setting up a machine for a user is quick and easy and can be done by IT support in many cases (since out of the box AutoCAD is all that is needed and custom content can be introduced simply by adding a desktop shortcut that points to an arg file). Thirdly, this method keeps your menu sets organized so if you have multiple menu sets and AutoCAD user profiles they won't be conflicting with each other.

As with several areas in the AutoCAD realm, there is not necessarily a "right" or "wrong" way of doing something but rather an "optimized" way for each particular environment. The environment I work in includes multiple sets of standards for different clients and different third party applications so it is essential to keep my custom AutoCAD menu content organized.

Here is a flow diagram that represents an architecture that allows me to manage multiple environments for different clients and/or disciplines and keeps the custom content separate from AutoCAD:





This is a high level architecture but provides the framework for adding as much custom content as your heart desires...or rather, your clients/customers/users desire. We will look at the specific CUI architecture in a future post and talk about managing 3rd party applications and multiple AutoCAD based user profiles.

Monday, November 29, 2010

Streamlined Network Deployment

We have now created an AutoCAD user profile and saved it as an arg file. We looked at some of the key paths that are defined in the arg file: Main CUI and Enterprise CUI and we discussed how AutoCAD loads the CUI files that are loaded via these paths as well as an MNL file with the same name (and in the same location) giving us an excellent access point to load other custom content.

We created our own custom layer app using C# .net and we have a compiled .dll file for this app.

I think it will be worthwhile to re-cap how all of the above is tied together in a network environment and reaches the users. All that needs to happen in order for this to reach our end user is for the user to load an AutoCAD user profile that loads a CUI file that loads the MNL file that loads the .dll!

That sounds like a nursery rhyme but read it a few times, and it will sink in.

In a previous post we talked about passing a command line parameter when AutoCAD loads that will load a specified profile. If we get this AutoCAD shortcut to a user's desktop then when AutoCAD is launched from that icon our chain reaction happens and the custom layer app reaches our end user.

To automate this process you could consider executing a batch file that will copy the AutoCAD shortcut from a secure network location to the executing machine's desktop and no further client side configurations are required.

Here is the code that will go in the batch file:

COPY "X:\SLD\DesktopIcons\SLDMain.lnk" ^ "%userprofile%\Desktop"

This batch file can be executed through Windows Explorer but an elegant way of presenting it to your users is to use a web based intranet site (such as Microsoft SharePoint) and create a hyperlink that executes the batch file when clicked. Here is the HTML markup that will launch a .bat file.

<a href="X:\SLD\Configurations\SLD_Profile01.bat">SLD Profile</a>

The result of all this is the client machine can have nothing but an out of the box AutoCAD install and then a single click (to execute the batch file) will place a new AutoCAD shortcut on the client machine's desktop. This shortcut points to an arg file that then allows all of your custom content to be loaded automatically!


Tuesday, October 5, 2010

Layer App

There are several ways to develop custom applications but now that we have talked about setting up the C#.net IDE let's develop an app! This simple little app will create AutoCAD layers. We will develop and build the app in this post and in a future post we will look at different UI options for providing it to the designers on the network.


Here is the code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;


namespace SLDTools
{
    public class LayerCreate
    {
        // Creates layer if one does not already exist
        public void layerCreate(string layerName,
                                short layerColor,
                                string layerLineType,
                                string layerDescription)
        {
            Document doc =
              Application.DocumentManager.MdiActiveDocument;
            Database db =
              doc.Database;
            Editor ed =
              doc.Editor;
            // Start a transaction
            using (Transaction acTrans =
                   db.TransactionManager.StartTransaction())
            {
                // Open the layer table for read
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(
                             db.LayerTableId,
                             OpenMode.ForRead)
                           as LayerTable;
                // Open the linetype table for read
                LinetypeTable acLineTypeTbl;
                acLineTypeTbl = acTrans.GetObject(
                                  db.LinetypeTableId,
                                  OpenMode.ForRead)
                                as LinetypeTable;
                LayerTableRecord acLyrTblRec;
                // If layer does not exist then create it
                if (acLyrTbl.Has(layerName) == false)
                {
                    acLyrTblRec = new LayerTableRecord();
                    // Assign ACI color and layer name
                    acLyrTblRec.Color = Color.FromColorIndex(
                                          ColorMethod.ByAci,
                                          layerColor);
                    acLyrTblRec.Name = layerName;
                    // Upgrade the layer table for write
                    acLyrTbl.UpgradeOpen();
                    // Append the new layer to the layer table
                    // and the transaction
                    acLyrTbl.Add(acLyrTblRec);
                    // Load linetype
                    if (acLineTypeTbl.Has(layerLineType) == false)
                    {
                        db.LoadLineTypeFile(
                          layerLineType, "acad.lin");
                    }
                    // Assign linetype
                    if (acLineTypeTbl.Has(layerLineType) == true)
                    {
                        acLyrTblRec.LinetypeObjectId =
                          acLineTypeTbl[layerLineType];
                    }
                    // Add layer description
                    acLyrTblRec.Description = layerDescription;
                    // Add new layer
                    acTrans.AddNewlyCreatedDBObject(
                      acLyrTblRec, true);
                }
                else
                {
                    acLyrTblRec = acTrans.GetObject(
                                    acLyrTbl[layerName],
                                    OpenMode.ForRead)
                                    as LayerTableRecord;
                }
                acTrans.Commit();
                acTrans.Dispose();
            }
        }
        // Define command that will be executed
        // from AutoCAD command line
        [CommandMethod("SLDLAYER")]
        public void sldLayer()
        {
            layerCreate("SLD_Example",
                        154,
                        "Continuous",
                        "Layer created for SLD blog post");
        }
    }
}


The above code can be expanded to either create several layers at the same time (i.e. to create a standard layer set within a drawing) or to create several individual layers (one at a time). The defined command "SLDLAYER" will be the command executed from the AutoCAD command line. Let's test it:


1. Enter the code in the new project we created in our last post and compile the dll.

The compiled dll file will now be in your Visual Studio project path...\bin\release folder.


2. Open AutoCAD and execute NETLOAD at the command prompt.


3. Browse to the dll and select Open.


4. The command defined in our custom layer app is now loaded into AutoCAD so we can execute SLDLAYER...and after doing so, we have our new layer!

Note: our streamlined environment that we have created so far provides the flexibility to incorporate scripts, custom lisp routines, dll files, and more without having to modify client machines. This app can be added by adding the NETLOAD function in the startup mnl file. We will look closer at this in the next post.



Monday, September 20, 2010

IDE For Custom Apps!

As we continue to lay down the stepping stones for building a streamlined design environment, I would like to interject one of my favorite activities - developing custom AutoCAD applications (apps). The apps that we develop will fit seamlessly into our environment without having to re-configure or install anything on the client machines.

Before we develop our first app however, we should briefly discuss the development environment. A few years ago I transitioned from developing AutoCAD apps in the LISP environment to using C#.net. The AutoCAD API offers some very powerful control for developing custom apps.

To get started with C#.net you can download the Microsoft Visual Studio Express environment for free!

Install Visual C# Express Edition.

Launch Visual C# Express Edition.

Create a new project by selecting File -> New Project 

Select Class Library as the template for the new project and select OK.

You should now have a new solution that looks like this:

In the Solution Explorer (right side of screen) expand References.

Right click on References and select Add Reference.


Select the Browse tab on the Add Reference dialog box. Then browse to the install folder of AutoCAD (i.e. C:\Program Files\AutoCAD 2010\

From this location we will add two .dll files that will provide the AutoCAD API to develop custom apps in the .net environment. The two files are:

acdbmgd.dll
acmgd.dll

You can select and load both files at the same time. You should now see these added in your References list.

One more step before we can create a custom AutoCAD app! Highlight both of the newly added references and below the Solution Explorer in the Properties pane set Copy Local to False.


This is the basic setup for a new custom AutoCAD app. Here are two excellent resources to find more detailed information and sample code:

2. Through The Interface

In my next post we will develop a layer creation app.





Wednesday, September 15, 2010

Streamlined Method for Modifying an Enterprise CUI File

In a previoust post we talked briefly about CUI files. There are 2 primary CUI files used by an AutoCAD user profile: Main and Enterprise. By default the enterprise CUI file is read only. This makes it an excellent option for placing your custom network content in. The main CUI file can be on each user's local C:\ drive. This allows the users to modify their base AutoCAD environment to their preference without inadvertently modifying the shared network CUI file. The .arg file that we created in this earlier post is where the paths to each CUI file are defined.

With a production environment any changes made to the network CUI will be visible to all users the next time they load AutoCAD. So when we want to make a change to the network CUI we probably want to test it in our test environment and then here is a streamlined method to modify the live network CUI file:

1. Make a copy of the production .arg file that all of your designers are using to your local machine (or your test environment).

2. Rename the .arg file with some sort of "admin" tag.

3. Switch the path definitions for the Main CUI and the Enterprise CUI.

production .arg file:


admin .arg file:



This will create a user profile where the acad.cui file on your C:\ drive will be loaded as the enterprise (read only) CUI and the shared network CUI file will load as your main CUI which you can now edit. Just be careful since this is a live shared file. Also be careful for savvy users who get clever (or read this post!) and switch these path definitions to modify the shared network CUI file.

Safety note: Always keep a backup of the current production CUI file. This way if it is modified by a user you can replace it or if you make a mistake while editing the live file you can quickly restore the working file.

You can further streamline this environment by creating 3 desktop shortcuts (on your machine only) and changing the target (profile parameter):

1. (Production) Target = "C:\Program Files\AutoCAD 2010\acad.exe" /p "X:\SLD\Profiles\SLD.arg"

2. (Development) Target = "C:\Program Files\AutoCAD 2010\acad.exe" /p "X:\SLD_dev\Profiles\SLD_dev.arg"

3. (Admin) Target ="C:\Program Files\AutoCAD 2010\acad.exe" /p "X:\SLD_dev\Profiles\SLD_Admin.arg"

This makes each profile accessible quickly depending on the situation. You can now add a UI to a custom (or standard) command and have it available instantly to your designers without having to load anything on their machines.

Monday, August 30, 2010

Testing...1, 2....testing

As you build a shared network "production" environment it is important to realize that multiple people are relying on that environment at any given time. Making the smallest change to production code can seem elementary and you will be tempted to just edit the production environment. There is no need to live on the edge and to get your heart pumping in anticipation as you open a production network file, edit one line of code, and click save.

Why put yourself through this stress? Setup a development network environment to test all of your changes before pushing it to the production environment. Editing one line of code invites room for error- an omitted semi-colon or a missing closing parenthesis are common simple oversights that can be caught immediately in the development environment to ensure a streamlined deployment into production.

To create a development area create a mirrored folder structure of your production environment. I create a dev folder at the same level as the production network folder. Inside of the dev folder is a copy of all of the production sub-folders and files.



Let's go ahead and create a new .arg (user profile) from AutoCAD for our development environment. Before doing this delete the .arg file that was copied into the _dev\Profiles folder. Open the production user profile in AutoCAD and we will create a new profile from the production profile. When the new profile is created we want to change the Enterprise Menu file location to point to our dev folder:



Now we can Export this development profile to our _dev\Profiles folder.

Depending on how you choose to manage your paths we may need to update a few lines of code in the .mnl file. Remember the .mnl file located in the same folder as the CUI will load automatically. The highlighted segment is what I changed.


;Title: SLD_dev.mnl
;Description: Automatically loads when SLD.cui is loaded.

;Constants
(setq SLD_DRIVE "X:\\")
(setq SLD_PATH (strcat SLD_DRIVE "SLD_dev\\Support\\"))
(setq SLD_TOOLS (strcat SLD_PATH "SLDTools.dll"))

;Load custom routines
(command "NETLOAD" SLD_TOOLS) ;netload sld functions
(load (strcat SLD_PATH "sld.lsp")) ;load lisp files

(princ "\nStreamlined content loaded!\n")

We can now update our desktop icon (in the _dev folder) to point to the development .arg file by changing the folder path and file name:




You can rename the development desktop shortcut so when you copy it to your desktop it will not be confused with the production environment.




Now we have two side by side environments, one that is production which is shared with your designers, the other which is identical to production but can be used for testing. When AutoCAD is launched from the development icon it will create a new profile so you can have both profiles loaded on your machine.





Any new custom files (lisp or dll) can be modified, created, and tested in the development area first. Also, CUI edits can be done in the development area before being visible to everyone. The CUI content will not be using hard paths so as long as it is relying on AutoCAD support paths then it will function fine when transferred into the production environment.

This post is really meant to cover the concept and importance of using a test environment. To what degree and exactly how to set up an efficient test environment may vary.






Friday, August 20, 2010

A Streamlined Access Point For Custom Content

One of the key concepts to understand when customizing AutoCAD (especially in a network environment) is that any CUI that is loaded into AutoCAD (either the Main CUI or the Enterprise CUI) will automatically load a menu lisp file (.mnl) that is in the same folder and shares the same name as the CUI file.

This is an excellent access point to provide custom content for your AutoCAD user profile. For example, if you create an AutoCAD user profile (.arg file) and path the EnterpriseMenuFile to a custom CUI then you can also create a .mnl file with the same name and in the same network directory.

In the .arg file the CUI paths are defined as follows:

"EnterpriseMenuFile"="x:\\sld\\support\\sld"
"MenuFile"="%RoamableRootFolder%\\support\\acad"

This profile will automatically look for a .mnl file with the same name and in the same directory as the CUI: 


Inside the .mnl file you can add in pretty much any custom content that you want. The below code will netload a dll file created in C#.net and will also load a lisp file.


;Title: SLD.mnl
;Description: Automatically loads when SLD.cui is loaded.

;Constants
(setq SLD_DRIVE "X:\\")
(setq SLD_PATH (strcat SLD_DRIVE "SLD\\Support\\"))
(setq SLD_TOOLS (strcat SLD_PATH "SLDTools.dll"))

;Load custom routines
(command "NETLOAD" SLD_TOOLS) ;netload sld functions
(load (strcat SLD_PATH "sld.lsp")) ;load lisp files

(princ "\nStreamlined content loaded!\n")



With this access point the amount of customization you can add is virtually endless. The nice thing is if you develop a new function and load it into this .mnl file it is instantly available to all of your users...that's streamlined.

Tuesday, August 10, 2010

Creating an AutoCAD User Profile

Creating an AutoCAD user profile allows AutoCAD to be "customized" in order to function efficiently within an environment. A few examples of data that is stored in an AutoCAD profile are support paths and plotter paths such as the location of .ctb files. Additionally, some of the most important elements in an AutoCAD user profile are the Customization (CUI) Files.

There are two primary CUI files, Main and Enterprise. The difference between these are that Main is editable by the user while the Enterprise CUI file is read-only by default. This makes the Enterprise CUI a great choice for providing customized content to your users through a shared network CUI file.

To create an AutoCAD user profile that points to your network CUI file we will start in AutoCAD. Select Tools | Options | Profile Tab | Add to List and enter a new profile name.


Click Apply & Close and then select the new profile and click Set Current. Your new profile should be highlighted and should show up as the current profile.


Select the Files Tab and point the Enterprise Customization File to the network cui file that you will be using. (Note: You can use UNC instead of a drive letter if you do not have a common network drive map for all users).


There are several other paths, settings, and configurations that can be controlled by the AutoCAD user profile but we will only change our Enterprise CUI for now.

Let's now export this profile so we can place it on a network file server making it available to all users. To do this go back to the Profiles tab and click Export. This creates a single file with an .arg extension. Once this .arg file is on the network we need a way to load it into AutoCAD. For this we can create an AutoCAD desktop icon that will load the new profile.

Copy an AutoCAD desktop shortcut into a network location (we can share this new shortcut with all users).


Right click on the AutoCAD shortcut and select Properties. We can now point to the .arg file using the /p (profile) parameter on the Target line.


Note: the /p goes after the acad.exe parameter that is already in the Target line. The full target line now looks like this:

"C:\Program Files\AutoCAD 2010\acad.exe" /p "X:\SLD\Profiles\SLD.arg"

This AutoCAD shortcut can be re-named and copied to each users' desktop and double clicking it will load the new profile you created!

The beauty of this approach is you do not need to modify anything on the users' machines, just simply copy the shortcut. You can automate the process of copying the shortcut to their desktops several different ways. The method I use is a batch (.bat) file that can be executed through a hyperlink on a web based collaboration tool such as SharePoint. This allows any user to get any profile (desktop shortcut) on to their machine with a single click.

You can make as many .arg files as you need depending on unique client needs, vertical application needs, or discipline needs.

With the core structure of our AutoCAD environment in place we have set the stage for endless customization possibilities. Next we will talk about loading an .mnl (menu lisp) file along with the CUI file and how this can be the key to providing all sorts of customized apps to your users.

Tuesday, August 3, 2010

The Foundation For a Streamlined Design Environment

While at a software conference last year that happened to be at a casino, I chose to partake in a little card playing. I am not an experienced gamer but a friend had recommended that I try Pai Gow poker. This game offers some flexibility in how you can play your hand depending on how aggressive you want to be. I found myself faced with a particularly tricky hand that could be played a few different ways. The dealer, noticing my indecision suggested a basic rule and informed me that this is what "the house" would do. The rule seemed simple and my initial reaction was that more thought should be put into it. But, I glanced around at the thousand dollar chandeliers hanging above each table and said, "well, the house seems to be doing pretty good".

The point being - simple can be effective and when it seems a situation should have more thought or effort put into it, ask yourself if there really is a benefit or is unnecessary complexity being added?

Laying down a simple "out-of-the-box" foundation is a great start to building an AutoCAD based network environment. Don't get bogged down trying to figure out how to deploy a specific menu, profile, or custom app - this (and more) can all be added later and if you have a stable, robust foundation in place it will be much smoother to work with.

Having a network deployment image for out-of-the-box AutoCAD local at each office is one of the most helpful and basic tools for maintaining a streamlined design environment. To create a network deployment image refer to the AutoCAD Network Administrator's Guide.

There are several options that can be built into the network deployment image. I always leave it as a silent install and out-of-the-box (except for licensing, see below). This will provide a flexible base platform that will allow for customizations to be added post-install. So instead of maintaining multiple network deployment images, start with a common base that can be used as a starting point for everyone.

Depending on how your AutoCAD license agreement is setup you may want to add the license server as a Windows Environment Variable in your network deployment image. You can use a batch file (and reg.exe) to modify the Environment Variables later on (i.e. for different offices or if your license servers change).

I will share some techniques that I use to deploy (and maintain) different user profiles in upcoming posts.

Monday, August 2, 2010

Welcome

Welcome to ‘Streamlined Design’, a blog dedicated to administrators and designers working with AutoCAD based products. I’ll be using this blog to share strategies for administering design technologies in a network environment, customizing AutoCAD, and interfacing different AutoCAD based applications.

There are several different methods to deploy and administer AutoCAD and I certainly do not claim to have all the answers nor that I have found the absolute best practices. I feel a design environment can always be improved…further streamlined. With that in mind, I will share some strategies and techniques that have worked for me and I hope during the process of doing so that I will continue to learn more about what I enjoy doing.

A little about me…I have worked with AutoCAD and several different AutoCAD vertical applications since the mid 90’s. I am responsible for administering a design environment that consists of multiple designers, multiple offices, component databases, and a handful of different AutoCAD based applications. I found that I really enjoy customizing AutoCAD and over the past few years I have been focusing on using C#.net to develop AutoCAD based applications.

Please feel free to contact me or suggest alternative methods as replies to any post. Thanks for reading!