Showing posts with label AutoCAD. Show all posts
Showing posts with label AutoCAD. Show all posts

Saturday, July 21, 2012

How to send AutoCAD commands via C#?

I’m working on an AutoCAD plugin in .Net (C#) and  was trying to insert Blocks from multiple DWG files into drawing area via C#.  Initially I was trying to write routines for Drag & Drop, Rotating, Scaling etc. However, AutoCAD’s built-in command “INSERT” is doing all such tasks. So I started looking for the method to Execute AutoCAD’s built-in commands.

I tried INSERT command and here is a code segment from  my C# Project initiated with AutoCAD.Net Wizards (Download from Autodesk Developer Network).

AutoCAD Command Method (C#)
  1.       [CommandMethod("InsertDWG")]
  2.         static public void SendINSERTCmd()
  3.         {
  4.             string DWG = @"D:\MYDWGs\1047.DWG";
  5.             string InsertCmd = @"_.-INSERT " + DWG + '\r' + '\n';
  6.             Document doc = Application.DocumentManager.MdiActiveDocument;
  7.             doc.SendStringToExecute(InsertCmd, true, false, false);
  8.         }

After compiling your code, use “NetLoad” to load your .net DLL and issue “InsertDWG”. You  will see the command line in AutoCAD’s command window. Drawing Block would be attached to your mouse pointer and you would be able to Drag, Drop, Scale, Rotate and all perform all functions that are provided in AutoCAD normally.

Friday, April 23, 2010

Tool Palettes in AutoCAD:

 

In AutoCAD, Tool Palettes provides the flexibility to have quick access to Drawings, Tools, and Commands etc.

These can be docked, undocked, resize and move at different locations in AutoCAD UI.

Users can easily customize these according to their needs. This involves:

  • Addition/deletion of Palettes.
  • Rename existing Palettes
  • Addition/removal of Commands,  Icons etc

Etc…

There can be large number of palettes which can easily be accessible using context menu while showing the list of available palettes.

 

Users can even place their drawings, templates etc on these tools palettes and can access them while working

  ToolPalettes_List

   

Arranging in Groups

AutoCAD brings a great number of Tool Palettes. In addition, users can add/remove their own. In addition, as more tool palettes can be created, this could lead to a very large number of tools and palettes and list can be very long and would be difficult to use.

Tool Palettes can be arranged in Palette groups and Sub Groups, which will show only selected Palettes.

Tool Palettes Groups are very useful when you have a large number of Tool Palettes and you have to use limited number of tools and wish to have only your required tools in palettes.

You can switch between Tool Palette Groups and can display all tool palettes at once.

  ToolPalettes_Groups

How to create Palette Groups:

As there is a good number of Tool Palettes available already and you might want to add your own. At this point you might want to arrange yours into groups. So here is the way, to create Palette Groups and arrange your tool palettes in these:

Click Right Mouse Button on Tool Palette Panel and choose Customize Palettes. This should open Customize Dialog box:

From the right panel (Palette Groups:), you can define your Groups and Sub Groups.

From the left panel (Palettes), you can choose which Tool palettes to be added into your groups.

Simply Draw your Tool Palettes from Left Panel (Palettes) to the Right Panel (Palette Groups:) and drop on your group. When you are done, press Close Button.

And your groups would be available immediate and could be accessed using Context Menu of Tool Palette Panel (right mouse button on Palette Panel Window).

 

PaletteGroups 

Thursday, April 22, 2010

AutoCAD Tool Palettes Files:

In AutoCAD, the location of Tool Palettes Files can be obtained by executing following Macro in Command Line:

*_TOOLPALETTEPATH

This should return the path of Tool Palette Files. By default, AutoCAD saves its Tool Palettes in following location:
%UserProfile%\Application Data\Autodesk\AutoCAD 2008\R17.1\enu\Support\ToolPalette

Same macro can be used to change this path. When you issue *_TOOLPALETTEPATH, it will show you the path(s) value and you can specify new path(s) in the prompt.

There can be multiple paths, and AutoCAD will load Tool Palettes from these paths immediately.

In addition to the use of macro *_TOOLPALETTEPATH, a somewhat better way to change/update/remove or add more Tool Palette Paths, this is more user friendly option:

Go to Tools –> Options –> Files –>  Tool Palettes File Locations: And here you can add more paths containing tool palette files.

AutoCAD will immediately load Tool Palette Files present in those folders.

 

How AutoCAD load its Tool Palette Files:

AutoCAD looks for tool palette Catalog Files which holds the information about tool palette files locations.

Both Catalog Files and  Tool Palette Files are XML based and have extension .atc.

To load Tool Palettes from specified folders, AutoCAD looks following files.

Catalog File:

This file contains the list of Tool Palettes (can be located at different locations). AutoCAD get the information of Tool Palettes from this file and load them.

AutoCAD’s default Catalog file is:
%UserProfile%\Application Data\Autodesk\AutoCAD 2008\R17.1\enu\Support\ToolPalette\AcTpCatalog.atc

In Catalog files, each tool palette file is referenced with its GUID.

Note: Catalog file can be of any name, and there could be multiple Catalog Files as well.

   

Tool Palette File:

The Tool Palette which contains the references to the icons, commands drawings etc and would appear in AutoCAD’s Tool Palette Panel. Its reference should be present in Catalog file.

AutoCAD’s default Tool Palette files location is:
%UserProfile%\Application Data\Autodesk\AutoCAD 2008\R17.1\enu\Support\ToolPalette\Palettes

The Palette File Names are composed as FileName_GUID.atc. For example:
MyToolPalette_A0CCA60A-AB56-4EFD-83A5-8764BC08CDA8.atc.

If Palette is using images (*.ico, *.bmp etc) then their references would be present in Palette file itself.

Each Tool Palette has a unique GUID which is used to reference in Catalog file along with its file name, and that makes it possible to have multiple Tool Palettes with same name (having different GUIDs) in AutoCAD’s UI

Notes:

  • AutoCAD load these tool palettes each time it starts by looking into folders added to Tool Palettes File Locations.
  • There may be other configurations files, but above two mentioned would be the ones dealing with locating and loading of Tool Palettes.