clone DynamicBlock from a different file

clone DynamicBlock from a different file

humbertogo
Advocate Advocate
949 Views
2 Replies
Message 1 of 3

clone DynamicBlock from a different file

humbertogo
Advocate
Advocate

Hi Guys

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

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

0 Likes
950 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

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)
        Else
            Using trans As Transaction = mTrans.TransactionManager.StartTransaction
                Using sourcedb As Database = New Database(False, False)
                    Try
                        sourcedb.ReadDwgFile(strSourceBlockPath, IO.FileShare.Read, True, "")
                        oid = db.Insert(strSourceBlockPath, sourcedb, True)
                        btr = trans.GetObject(oid, OpenMode.ForWrite, True, True)
                        btr.Name = strSourceBlockName
                        trans.Commit()
                    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.

 

jvj

0 Likes
Message 3 of 3

humbertogo
Advocate
Advocate

Will Try and post the result back

Thank You for your time

0 Likes