Wednesday, May 1, 2013

Automatically create PDF or DWF files from AutoCAD

As electronic drawing formats (PDF and DWF) are becoming more popular both for internal checks during the design process and even final deliverables, it is important to have good workflows for this. A very handy feature for creating PDF and DWF files (that in my experience seems to be fairly unknown) is Auto Publish.
Auto Publish is found on the Plot and Publish tab in the options dialog.

There are quite a few options available in the Auto Publish Settings dialog. Some of the key ones are:
  • Publish on Close, Save, or to prompt before publishing
  • Choosing the file format, PDF or DWF
  • Single-Sheet or Multi-Sheet
  • The output location. Drawing Folder creates the file in the same folder the drawing is in. A full path could be provided here as well. Note: these settings are stored in the registry so this path can be added to a network based profile so multiple workstations output to the same location.

Once the preferred settings are made the Auto Publish needs to be toggled on before it will be in effect.

In my settings I chose to publish a PDF when I close my drawing file. I also specified the location to be the Drawing Folder. With these settings in place and the Automatic Publish toggled on when I close my drawing a PDF is automatically created.

Notice the layout tab name is added to the filename just like when publishing directly from AutoCAD. In the future the PDF will automatically be overwritten when I close the file again.

Auto Publish is a very flexible feature and the settings are stored in the AutoCAD profile which makes it great for managing a network based AutoCAD environment. The Automatic Publish toggle is off by default and there is not a registry key for this state. When the toggle is on and if you want to force it to be on through the AutoCAD profile here is the registry key for that (in the General section of the registry)
"AUTOMATICPUB"=dword:00000001

The Auto Publish settings are also stored in the AutoCAD profile in the AcAutoPublishOpts section of the registry.

Take some time to explore all of the options with Auto Publish, this can offer several streamlined workflows to the design environment.




Monday, April 29, 2013

Migrating .Net Apps to AutoCAD 2013

As I began migrating my .Net apps developed in Visual Studio 2010/AutoCAD 2011 to AutoCAD 2013, I quickly realized a new .dll reference is required. After updating the project references with the 2013 versions of acdbmgd.dll and acmgd.dll then re-building the solution I was presented with the following error message:
The type or namespace name could not be found
 
The additional .dll that is required is the accoremgd.dll (located in the root AutoCAD 2013 install location). Add this reference and I assume continue to set copy local to False (same as acdbmgd and acmgd). Also, make sure to set the Target Framework to .NET 4 (should be the default) and you should now be ready to be programming on the AutoCAD 2013 platform.
 
 
 
 


Friday, April 26, 2013

The AutoCAD custom.cui is a perfect place for custom content

Even in a managed network environment where custom CAD content is maintained and deployed, it is still nice for individual users to have the ability to add their own customizations. An administrator can maintain control of an environment but it can be good to encourage creativity for users. This gives them a chance to explore the AutoCAD CUI environment, make custom CUI elements (ribbon tabs, panels, menus, etc.) and develop useful (or just fun) macros and custom commands. The perfect place for all of this to happen is the custom.cui that is delivered with AutoCAD and resides on the local C:\ drive.

The delivered acad.cui file already has the custom.cui partially loaded. This means that every time the acad.cui file is loaded it will load the partial custom.cui file.


The custom.cui is located in the same appdata\roaming\autodesk\....\support folder that the acad.cui is. There is not a custom.mnl by default, but as we have discussed in earlier posts AutoCAD will look for a .mnl file that has the same name as all loaded CUI files. This means if we create a custom.mnl file and store it in the above location, our individual custom content in the .mnl will be automatically loaded every time AutoCAD loads! Note, one of the most helpful uses of an .mnl file is it can be an access point to load other lisp files, dll files, arx files, and more.

Using the custom.cui is a streamlined way for individual users to add creative and custom user interface elements, commands, and macros to their environment and still keep it separate from the acad.cui and network delivered content. Furthermore, this makes upgrading simple for individual users since they will just need to grab their custom.cui (and .mnl if one was created) and introduce it in the next version of AutoCAD (some tweaking may be necessary depending on differences in CUI handling from version to version).

To get started, launch AutoCAD and browse to the custom.cui as shown above. Refer to this earlier post as a refresher on how to create a custom ribbon element.

Saturday, January 19, 2013

Use Startup Switch /b to Add AutoCAD Support Path When Launching AutoCAD

We have talked about loading a specific network based AutoCAD profile when AutoCAD is launched. To do this we use the Profile startup switch /p at the AutoCAD startup command line. For example, "C:\Program Files\Autodesk\AutoCAD 2011\acad.exe" /p "C:\SLD\Support\Profile.arg" in the AutoCAD Shortcut Target will launch AutoCAD 2011 into the profile defined in the Profile.arg file. If a Profile parameter is not specified AutoCAD will load the last used AutoCAD user profile. Also, if a .dwg file is opened by double clicking on it in Windows Explorer the last used AutoCAD user profile will be loaded (this may not be a desirable workflow).

/p is called a startup switch. There are several other switches that can be passed to AutoCAD during the startup sequence. Visit this Autodesk page for a complete list of startup switches. Let's look at a very flexible switch, the Script switch /b. This switch executes an AutoCAD script during the startup sequence. Once we have an access point via a script we can do almost anything. This example will execute a script file that calls a lisp routine. The lisp routine will add a support path to the existing AutoCAD support paths defined by the current AutoCAD user profile. This can be handy if you are not controlling which profile a user is launching but want to ensure they have certain support paths available.

To start, we need to create our lisp file that the script will call. The lisp code is accessing the AutoCAD environment variable to determine the current defined AutoCAD support paths and then adds the new support path (or paths) at the end.

Next, we will create a script file that calls the command defined in our lisp routine. The script file just needs to load the lisp routine and execute our command.
Now we need an AutoCAD desktop icon that launches the version you are working with and calls our script file. I copied the out-of-the-box AutoCAD Shortcut and renamed it for this example.

Then right click and select properties and on the Shortcut tab add the /b startup switch in the target to point to your script file. Note, the .scr extension is left off and use quotes especially if there are spaces in the path location.
The /b startup switch is added just after the acad.exe action. You can have multiple startup switches so we could also point to a profile (using /p) or several other options. In this example the full Target text path is:

"C:\Program Files\Autodesk\AutoCAD 2011\acad.exe" /b "C:\SLD\Support\Script\addSupportPath"

Now when AutoCAD is launched from this icon since we are not specifying a profile with the /p startup switch, the last used AutoCAD based user profile will load. Regardless of which profile that is our /b startup switch will call our script file. Our script file loads our lisp routine and executes the command to update the AutoCAD support path.
The AutoCAD startup switches can provide quite a bit of flexibility. Especially once you gain access to the startup sequence with a script file that opens the door to load lisp code, .Net dll's, and more. Depending on how you choose to manage your environment or what you are trying to accomplish this can provide a streamlined solution.




Thursday, December 13, 2012

Restore or Reset an AutoCAD CUI File

It is no wonder the most popular AutoCAD command is UNDO. UNDO might be the most popular action in all other areas of our lives if we had the option. I would much rather click UNDO after my toddler tips over a glass of milk at dinner than to go through the effort of cleaning it up. UNDO would also come in handy when our new puppy pees on the carpet. Even though we do not have an UNDO button in real life we can appreciate that we do in AutoCAD. So, what about when working with the AutoCAD CUI file? Good news! There is also an UNDO (sort of)...

When AutoCAD is installed on a computer the out of the box Support folder which includes the ACAD.CUIx file is tucked away on the C:\ drive. When AutoCAD is launched for the first time it configures the software for the currently logged in user. Part of this configuration process is copying the contents of the Support folder to the user's appdata\roaming\autodesk\...\support folder. If a different user logs on to the computer the same process happens so each user has his/her own Support folder and therefore, his/her own ACAD.CUIx file.

As changes are made to the ACAD.CUIx file it is possible for the CUI to become corrupt. It is sometimes difficult to detect when a CUI file has become corrupt but several unexpected errors can be resolved by replacing the CUI file with either a previous version or the original ACAD.CUIx file.

There are two choices available: Restore the CUI file, or Reset the CUI file. Restoring the CUI file is basically an UNDO and any changes that were made since the CUI Editor was opened are lost. Resetting the CUI file replaces the current CUI file with the original ACAD.CUIx file from the AutoCAD Install Location. So any changes that have ever been made to the CUI file are lost.

To Restore the ACAD.CUIx:
Open the CUI dialog (Manage tab | CUI). You will see the ACAD.CUI file and can confirm the location is in your users folder.


Right click on the ACAD.CUI and select Restore ACAD.CUIX


This option is nice if you have customizations that you want to keep and just want to UNDO the current modifications to the ACAD.CUIx file. Notice the CUI file will be restored to the state it was in prior to the CUI Editor being opened.


If the ACAD.CUIx file seems corrupt and you want to start all over with the original ACAD.CUIx file then you would choose the Reset option:

Open the CUI dialog (Manage tab | CUI), right click on the ACAD.CUI and select Reset ACAD.CUIX
This option will lose any changes made to the ACAD.CUIx file and will restore from the original out of the box version.
 
 
Resetting the CUI is also a way to clean out all partially loaded CUI files that might be in place from working with AutoCAD vertical applications. Additionally, it is important to note that Workspaces are saved within CUI files so depending on which CUI file custom Workspaces have been created in those will be lost as well.
 
Any time strange errors seem to be occurring consider the CUI as an option. I have seen several Fatal Errors when AutoCAD is starting up be resolved by Restoring or Resetting the CUI.





Sunday, August 26, 2012

Custom acad.lsp and acaddoc.lsp

We have talked about several methods to load custom content in previous posts. One of my favorites is loading an enterprise cui which in turn will load an mnl file with the same file name. This is a clean method and keeps all of your custom content organized and easily deployed from a central network location. However, there may be times when you really do not have a user interface (cui) and you just want your custom routine(s) to be loaded. There is a handy built in AutoCAD method for this, the acad.lsp and the acaddoc.lsp.

The acad.lsp is a special routine recognized by AutoCAD and is loaded every time an AutoCAD session is launched. The acaddoc.lsp is a special routine recognized by AutoCAD and is loaded every time an AutoCAD drawing is opened.

We can take advantage of these auto-loading routines to load custom content by placing files named either acad.lsp or acaddoc.lsp in any of our support paths defined by our network based profile. Creating separate (custom) acad.lsp and/or acaddoc.lsp files does not interfere with the delivered AutoCAD files (they just need to be in different folders).

For example, in our AutoCAD profile we have a support path defined (C:\sld):

This could of course be any network path. Let's place a custom acaddoc.lsp file that loads some custom content in this folder.

Now when AutoCAD is launched in a profile where our above path is a support path our custom lisp content is loaded.

Note, since we used acaddoc.lsp our routine will load every time a drawing is opened. If we only want our routine to load when AutoCAD is launched we would change the filename to acad.lsp.

I am not sure if there are other default filenames that behave similarly but the above two work great and should provide as much flexibility as you would need. This does not work for .dll files directly however, if you have a custom .dll you can just place a NETLOAD statement inside your custom acad.lsp or acaddoc.lsp. Remember, once you have an access point to load one routine, you can load as many other lisp routines, .dll files, .arx files, and more that you need.

This approach provides another streamlined method to load and manage custom content for multiple users.



Thursday, June 28, 2012

Simple Custom AutoCAD User Profile

In previous posts I have talked about creating AutoCAD user profiles and the different components that can be included in a profile. One of the main reasons to create an AutoCAD user profile is to have specific content available during an AutoCAD drawing session. This content can be anything from network and printer paths, to CAD standards, to custom commands.

This post will go through creating a very simple custom AutoCAD profile and hopefully it will make sense on how to add more information to the profile as needed in your environment.

An AutoCAD user profile has a lot of information in it and without being intimately familiar with it, it is difficult to know what each line in the profile (.arg) file is doing. The good news is it is really not that important if you just want to cut to the chase and create your own custom profile. We will let AutoCAD handle all the complicated stuff and we will focus on only the items we are concerned with (the simple stuff).

First, just a few high level points to make:
An .arg (AutoCAD Registry) file is used to create an AutoCAD user profile and set registry keys on your computer. If you have ever looked (you don't really need to) in your computer's registry you will see all of the AutoCAD user profiles that are defined on your computer. (Note: AutoCAD user profiles are specific to the logged in user).


After installing AutoCAD you should see the Unnamed Profile which is the out-of-the-box delivered AutoCAD user profile.

Let's create a new .arg file with the goal being to create a new AutoCAD user profile on our computer. To keep this simple we only need to think about the custom paths or content we want to add to our profile. In this case we are just going to add an AutoCAD Support Path and point to a custom cui file that we would like to have loaded as our Enterprise Menu File.

Rather than needing to account for all of the other settings in the profile we will let AutoCAD automatically assign everything else. So basically, only the registry keys that we want to override need to be identified in our new .arg file.

To accomplish the above we can create a new .arg file (either by exporting from AutoCAD, or from scratch). Once the .arg file exists we can clean out everything we do not need (so everything except for our support path and Enterprise Menu File). Whatever we do not define in our .arg file AutoCAD will create default registry keys for.

Here is the contents of our custom .arg file that adds a support path and an Enterprise Menu File: (You can edit an .arg file with Notepad)

REGEDIT4

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.1\ACAD-9001:409\Profiles\SLD_Example\General]
"ACAD"="C:\\SLD\\Support;%InstallFolder%\\support;%InstallFolder%\\fonts;%InstallFolder%\\help;%InstallFolder%\\express;%InstallFolder%\\support\\color;%RoamableRootFolder%\\support;"

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.1\ACAD-9001:409\Profiles\SLD_Example\General Configuration]
"EnterpriseMenuFile"="C:\SLD\Support\SLD_2011"

The path in between the brackets [ ] defines the location of the registry keys that we are modifying. Notice it is the same path as the registry location of the Unnamed Profile on our machine (above image) except for once we get to the Profiles location we are creating a new profile name, SLD_Example.
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.1\ACAD-9001:409\Profiles\SLD_Example\General]

We are overriding the "ACAD" registry key which is the AutoCAD Support Paths. The below support paths are copied from the Unnamed Profile and we added the 1 support path that we need for our custom profile.
"ACAD"="C:\\SLD\\Support;%InstallFolder%\\support;%InstallFolder%\\fonts;%InstallFolder%\\help;%InstallFolder%\\express;%InstallFolder%\\support\\color;%RoamableRootFolder%\\support;"

We then define the "EnterpriseMenuFile" registry key which is our custom cui file that we want our profile to have. (The cui file could be located in a network location so multiple users all receive the same custom content.)

"EnterpriseMenuFile"="C:\SLD\Support\SLD_2011"

Now when we point to this .arg file from our AutoCAD Desktop Shortcut and launch AutoCAD a new profile will be created on your computer:
Even though we only defined 2 registry keys you will notice that all of the other profile information is automatically defined by AutoCAD.

You now have a completely separate and custom AutoCAD user profile that contains all of the out-of-the-box AutoCAD settings with our additional custom content. This can be shared over a network and remember, once we load that Enterprise cui file we can gain access to custom content with an .mnl file that has the same name as the cui file.

I created a new Ribbon tab in this cui file so you can see that is available to us in our new profile:


This approach can offer a very streamlined method to manage multiple AutoCAD user profiles that maybe you have for each client. Only define the registry keys that you want to override (i.e. suport paths, cui file, maybe plot styles, etc.) and you can keep your profiles very simple and portable by letting AutoCAD do the rest of the work. This .arg file that we created can easily be upgraded to the next version of AutoCAD since we know AutoCAD will automatically define all of the other registry keys that we are not overriding. (Note, the registry path to the profile would be different for each version of AutoCAD - this it the path in the brackets [ ] mentioned above).

Note, you can build your profile in AutoCAD and export it out to get the .arg file. You can then remove any of the registry keys that you are not overriding and you will be left with your simple custom AutoCAD user profile.