.NET

.NET

Reply
Valued Contributor
humberto
Posts: 60
Registered: ‎06-03-2003
Message 1 of 3 (124 Views)

clone DynamicBlock from a different file

124 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 ?

Mentor
JamieVJohnson2
Posts: 170
Registered: ‎08-26-2010
Message 2 of 3 (109 Views)

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)
        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
Valued Contributor
humberto
Posts: 60
Registered: ‎06-03-2003
Message 3 of 3 (76 Views)

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
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.