Previously I've posted two sample using CloningHelper utility class. I showed the usage in the context of importing/exporting styles from/to anthoer drawing and cloning a style within the drawing in C#. Here is another one in VB.NET this time. In this example, we are using it to import a proper set definition. Same idea as before. Please refer to the previous posts for description.
' Import a property set definition from an external drawing
<CommandMethod("ACANetScheduleLabs", "AcaImportPropSetDef", _
CommandFlags.Modal)> _
Public Sub ImportPropertySetDefinition()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Try
' Our destination file is the current db
Dim dbDestination As Database =
Application.DocumentManager.MdiActiveDocument.Database
' Our source file from which we import a prop set def.
' ex. the following is from:
' C:\ProgramData\Autodesk\ACA 2013\enu\Styles\Metric\
' Schedule(Tables(Metric).dwg)
Dim sourcePath As String =
"C:\ACA\ACA .NET 2013\Drawings\Schedule Tables (Metric).dwg"
Dim dbSource As Database = New Database(False, True)
dbSource.ReadDwgFile(
sourcePath, System.IO.FileShare.Read, True, "")
' Get the source dictionary
Dim dictPropSetDef As _
New DictionaryPropertySetDefinitions(dbSource)
' Get the list of def ids that you want to import
' 1) if you want to import everything from the given
' dictionary, use this.
'Dim objCollectionSrc As ObjectIdCollection =
' dictPropSetDef.Records
' 2) if you want to import a specific style, use this.
Dim objCollectionSrc As New ObjectIdCollection
' The name of def you want to import
objCollectionSrc.Add(dictPropSetDef.GetAt("DoorObjects"))
' 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 ones as
' // anonymous name (intended for behind the
' // scenes further processing.)
Dim helper As New CloningHelper
' Uncomment one of these if you want to have a behavior other
' than default (i.e., overwrite).
'helper.MergeType = DictionaryRecordMergeBehavior.Unique
'helper.MergeType = DictionaryRecordMergeBehavior.Merge
'helper.MergeType = DictionaryRecordMergeBehavior.Normal
' Finally call clone.
helper.Clone(dbSource, dbDestination, objCollectionSrc,
dictPropSetDef.RecordType, True)
Catch ex As Exception
ed.WriteMessage(
"error in AcaImportPropSetDef" + ex.Message + vbCrLf)
Return
End Try
ed.WriteMessage(
"Prop set def DoorObjects has been successfully imported" +
vbCrLf)
End Sub