08/12/2012

Import/Export styles from/to another drawing in .NET

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?

Solution

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.

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.

Comments

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?

Solution

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.

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.