.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

clone DynamicBlock from a different file

2 REPLIES 2
Reply
Message 1 of 3
humbertogo
422 Views, 2 Replies

clone DynamicBlock from a different file

Hi Guys

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

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

2 REPLIES 2
Message 2 of 3
JamieVJohnson2
in reply to: humbertogo

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

jvj
Message 3 of 3
humbertogo
in reply to: JamieVJohnson2

Will Try and post the result back

Thank You for your time

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost