I need to load styles for doors and members etc etc from an AutoCAD Architecture template file to a drawing file. This can be done easily in style dialog by copy and paste through the UI. But I need to do this programmatically using .NET. I tried to use WBlockCloneObjects. But it does not seem to work all the time. Is there a way to more reliably to do this?
There is a helper function called CloningHelper under Autodesk.Aec.ApplicationServices.Utility Namespace. This allows you to import/export style based information in the same manner as UI's styles copy/paste operations between drawings. Below are the sample commands that demonstrate the usage of this class. It is written for AutoCAD Architecture (ACA). But the same concept should apply to the object that you see in the style dialog in AutoCAD MEP.
In the code below, please look at the lines:
Autodesk.Aec.ApplicationServices.Utility.CloningHelper helpme =
helpme.Clone(dbSource, dbDestination, objCollectionSrc, rxcls, true);
There are four options for merge type:
Normal = 0, // no overwrite
Overwrite = 1, // this is default.
Unique = 2, // rename it if the same name exists.
Merge = 3 // no overwrite + add overlapping ones as anonymous name
// (Intended for behind the scenes further processing.)
Note #1: WBlockCloneObject may work with simple cases. But when it has more complex relations, it may not work. For example, we are aware that it won't work with Schedule Table Styles and Structural Members Styles. CloningHelper is the one ACA uses internally.
Note #2: CloningHelper is exposed in ACA 2009 and later versions in .NET. Only C++/OMF version is available for ACA 2008 and earlier versions.
public class Class1
static Editor ed =
// Import a door style from an external drawing.
public void importDoorStyleTest()
// our destination file is the current db.
Database dbDestination =
// our source file from which we import styles.
// The name of source drawing is harded for
string SourcePath =
@"C:\temp\Door Styles (Metric).dwg";
Database dbSource = new Database(false, true);
// get the source dictionary
DictionaryDoorStyle dictStyle =
// get the list of style ids that you want to import.
// (1) if you want to import everything, use this.
// the list of ids in the style dictionary.
//ObjectIdCollection objCollectionSrc =
// (2) if you want to import a specific style,
// use this.
// we assume you know the name of style you want to
ObjectIdCollection objCollectionSrc =
dictStyle.GetAt("Bifold - Double")
// now use CloningHelper class to import styles.
// there are four options for merge type:
// Normal = 0, // no overwrite
// Overwrite = 1, // this is default.
// Unique = 2, // rename it if the same name
// // exists.
// Merge = 3 // no overwrite + add
// // overlapping as anonymous
CloningHelper helpme =
// uncomment below if you want a behavior other than
// finally call clone.
catch (System.Exception e)