Valued Contributor
61 Posts
2 Kudos
Registered: ‎06-03-2003
Post 1 of 3

clone DynamicBlock from a different file

125 Views, 2 Replies
07-12-2012 12:17 AM

Hi Guys

I trying to clone DynamicBlockProperty from a file to the current drawing

Using VB or C#.Net.
How to resolve it ?

171 Posts
62 Kudos
Registered: ‎08-26-2010
Post 2 of 3

Re: clone DynamicBlock from a different file

07-12-2012 03:49 PM in reply to: humberto

Are you trying to clone the property or perhaps the entire block definition.  Either way, I'd start by loading the source drawing into a temp cad database.  Then finding the block definition.

    ''' <summary>
    ''' Finds / inserts a block definition from file.
    ''' </summary>
    ''' <param name="strSourceBlockName">Name of inserted block</param>
    ''' <param name="strSourceBlockPath">Name of block's dwg file</param>
    ''' <returns>BlockTableRecord of the found/inserted block</returns>
    ''' <remarks>If block is not found, then an error is thrown, and nothing is returned.</remarks>
    Public Function GetBlock(ByVal strSourceBlockName As String, ByVal strSourceBlockPath As String, ByRef db As Database, ByRef mTrans As Transaction) As BlockTableRecord
        Dim oid As ObjectId = Nothing
        Dim btr As BlockTableRecord = Nothing
        Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
        If bt.Has(strSourceBlockName) Then
            btr = bt(strSourceBlockName).GetObject(OpenMode.ForRead)
            Using trans As Transaction = mTrans.TransactionManager.StartTransaction
                Using sourcedb As Database = New Database(False, False)
                        sourcedb.ReadDwgFile(strSourceBlockPath, IO.FileShare.Read, True, "")
                        oid = db.Insert(strSourceBlockPath, sourcedb, True)
                        btr = trans.GetObject(oid, OpenMode.ForWrite, True, True)
                        btr.Name = strSourceBlockName
                    Catch ex As System.Exception
                        Throw New System.Exception("Block file not found " & strSourceBlockPath & ": ", ex)
                    End Try
                End Using
            End Using
        End If
        Return btr
    End Function

 Once you have the source database loaded get the block or block reference and start working on it.



Valued Contributor
61 Posts
2 Kudos
Registered: ‎06-03-2003
Post 3 of 3

Re: clone DynamicBlock from a different file

07-18-2012 01:21 AM in reply to: JamieVJohnson2

Will Try and post the result back

Thank You for your time

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post