.NET

Reply
Active Contributor
humberto
Posts: 44
Registered: ‎06-03-2003
Message 1 of 3 (117 Views)

clone DynamicBlock from a different file

117 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: 165
Registered: ‎08-26-2010
Message 2 of 3 (102 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
Active Contributor
humberto
Posts: 44
Registered: ‎06-03-2003
Message 3 of 3 (69 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community