CloningHelper sample in VB.NET

By Mikako Harada

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 
 
   _
  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:ProgramDataAutodeskACA 2013enuStylesMetric
      ' Schedule(Tables(Metric).dwg)
 
      Dim sourcePath As String =
        "C:ACAACA .NET 2013DrawingsSchedule 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

Comments

2 responses to “CloningHelper sample in VB.NET”

  1. Mallikarjuna Avatar
    Mallikarjuna

    Dear Mikako Harada,
    I want to add image or icon in Revit 3D view through programmatically in C#.net
    Please help me.
    Thankyou,
    Mallikarjuna

  2. Dear Mallikarjuna,
    I see that you asked the same question in five different places, to me, Saikat, Mikako, and Xiaodong.
    That is a bit much, really. Please avoid that in the future.
    Anyway, as Saikat said:
    It does not seem possible to add an image in a 3D view in Revit using the Revit User Interface itself. The image button appears disabled when the active view is a 3D view. Therefore, it is probably not possible to insert an image in a 3D view using the API either. If the UI does not support it, in most cases, the API does not either.
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading