<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DeepClone Dynamic BlockTableRecord in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292628#M74188</link>
    <description>Hello everybody,&lt;BR /&gt;
&lt;BR /&gt;
Sorry to let off as I can solve all my own problems, but I can't...  &lt;BR /&gt;
&lt;BR /&gt;
I attempted to speed up my program by creating a system that did not insert the block from file everytime, rather to insert a master block, and clone that one as I needed to.  This worked great for the blocks that all have the same definition block table record, but when I wanted to copy the block table record into a new block I get in trouble.&lt;BR /&gt;
&lt;BR /&gt;
In this mess are 2 functions I created that are supposed to be my one shoe fits all for inserting a block/block reference.  My problem is when I insert a dynamic block, I get the Multiply owned object error upon save; where my source dynamic block, and the cloned dynamic block both have the same entities inside them (by handle).  'Audit' only makes things worse, by putting new handles on all the entities in the source block in addition to the original entities (now I have a block table ref with 2 times the number of entities as the source dwg file.)&lt;BR /&gt;
&lt;BR /&gt;
Can anybody point out the error in my code / logic path please...&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
&lt;BR /&gt;
jvj</description>
    <pubDate>Thu, 03 Jul 2008 17:55:20 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-07-03T17:55:20Z</dc:date>
    <item>
      <title>DeepClone Dynamic BlockTableRecord</title>
      <link>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292627#M74187</link>
      <description>Public Overridable Function InsertBlockRef(ByVal dblInsert As Point3d, ByVal btrSpace As BlockTableRecord, ByVal strSourceBlockName As String, ByVal strSourceBlockPath As String, Optional ByVal strBlockNewName As String = "") As BlockReference&lt;BR /&gt;
        Dim dlock As DocumentLock = Nothing&lt;BR /&gt;
        Dim bt As BlockTable&lt;BR /&gt;
        Dim btr As BlockTableRecord = Nothing&lt;BR /&gt;
        Dim br As BlockReference = Nothing&lt;BR /&gt;
        'Dim id As ObjectId&lt;BR /&gt;
        Dim db As Autodesk.AutoCAD.DatabaseServices.Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
        Using trans As Transaction = db.TransactionManager.StartTransaction&lt;BR /&gt;
            Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;
            'insert block and rename it&lt;BR /&gt;
            Try&lt;BR /&gt;
                Try&lt;BR /&gt;
                    dlock = ThisDrawing.LockDocument&lt;BR /&gt;
                Catch ex As Exception&lt;BR /&gt;
                    Dim aex As New System.Exception("Error locking document for InsertBlock: " &amp;amp; strSourceBlockName &amp;amp; ": ", ex)&lt;BR /&gt;
                    Throw aex&lt;BR /&gt;
                End Try&lt;BR /&gt;
                bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)&lt;BR /&gt;
                Dim btrSource As BlockTableRecord = GetBlock(strSourceBlockName, strSourceBlockPath, strBlockNewName)&lt;BR /&gt;
                'if getblock returns nothing then the rest of this code is worthless, skip it and dispose the transaction&lt;BR /&gt;
                If btrSource IsNot Nothing Then&lt;BR /&gt;
                    btr = trans.GetObject(btrSource.ObjectId, OpenMode.ForRead)&lt;BR /&gt;
                    btrSpace = trans.GetObject(btrSpace.ObjectId, OpenMode.ForWrite)&lt;BR /&gt;
                    'Get the Attributes&lt;BR /&gt;
                    Dim attColl As AttributeCollection&lt;BR /&gt;
                    Dim ent As Entity&lt;BR /&gt;
                    Dim btrenum As BlockTableRecordEnumerator&lt;BR /&gt;
                    br = New BlockReference(dblInsert, btr.ObjectId)&lt;BR /&gt;
                    btrSpace.AppendEntity(br)&lt;BR /&gt;
                    trans.AddNewlyCreatedDBObject(br, True)&lt;BR /&gt;
                    attColl = br.AttributeCollection&lt;BR /&gt;
                    btrenum = btr.GetEnumerator&lt;BR /&gt;
                    While btrenum.MoveNext&lt;BR /&gt;
                        ent = btrenum.Current.GetObject(OpenMode.ForWrite)&lt;BR /&gt;
                        If TypeOf ent Is AttributeDefinition Then&lt;BR /&gt;
                            Dim attdef As AttributeDefinition = ent&lt;BR /&gt;
                            Dim attref As New AttributeReference&lt;BR /&gt;
                            attref.SetAttributeFromBlock(attdef, br.BlockTransform)&lt;BR /&gt;
                            attref.TextString = attdef.TextString&lt;BR /&gt;
                            attColl.AppendAttribute(attref)&lt;BR /&gt;
                            trans.AddNewlyCreatedDBObject(attref, True)&lt;BR /&gt;
                        End If&lt;BR /&gt;
                    End While&lt;BR /&gt;
                    trans.Commit()&lt;BR /&gt;
                End If&lt;BR /&gt;
            Catch ex As System.Exception&lt;BR /&gt;
                Dim aex2 As New System.Exception("Error in inserting new block: " &amp;amp; strSourceBlockName &amp;amp; ": ", ex)&lt;BR /&gt;
                Throw aex2&lt;BR /&gt;
            Finally&lt;BR /&gt;
                If Not trans Is Nothing Then trans.Dispose()&lt;BR /&gt;
                If Not dlock Is Nothing Then dlock.Dispose()&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End Using&lt;BR /&gt;
        Return br&lt;BR /&gt;
    End Function&lt;BR /&gt;
&lt;BR /&gt;
    Public Function GetBlock(ByVal strsourceblockname As String, ByVal strsourceblockpath As String, Optional ByVal strblocknewname As String = "") As BlockTableRecord&lt;BR /&gt;
        Dim dlock As DocumentLock = Nothing&lt;BR /&gt;
        Dim bt As BlockTable&lt;BR /&gt;
        Dim btr As BlockTableRecord = Nothing&lt;BR /&gt;
        Dim id As ObjectId&lt;BR /&gt;
        Dim db As Autodesk.AutoCAD.DatabaseServices.Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
        Using trans As Transaction = db.TransactionManager.StartTransaction&lt;BR /&gt;
            Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;
            'insert block and rename it&lt;BR /&gt;
            Try&lt;BR /&gt;
                Try&lt;BR /&gt;
                    dlock = ThisDrawing.LockDocument&lt;BR /&gt;
                Catch ex As Exception&lt;BR /&gt;
                    Dim aex As New System.Exception("Error locking document for InsertBlock: " &amp;amp; strsourceblockname &amp;amp; ": ", ex)&lt;BR /&gt;
                    Throw aex&lt;BR /&gt;
                End Try&lt;BR /&gt;
                bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)&lt;BR /&gt;
                If bt.Has(strsourceblockname) Then&lt;BR /&gt;
                    'block found, get instance for copying&lt;BR /&gt;
                    If strblocknewname &amp;lt;&amp;gt; "" Then&lt;BR /&gt;
                        'renaming source block, so create a new definition&lt;BR /&gt;
                        Dim idMap As New IdMapping&lt;BR /&gt;
                        Dim btrS As BlockTableRecord = trans.GetObject(bt.Item(strsourceblockname), OpenMode.ForWrite)&lt;BR /&gt;
                        btr = btrS.DeepClone(bt, idMap, True)&lt;BR /&gt;
                        btr.Name = strblocknewname&lt;BR /&gt;
                        bt.Add(btr)&lt;BR /&gt;
                        trans.AddNewlyCreatedDBObject(btr, True)&lt;BR /&gt;
                    Else&lt;BR /&gt;
                        btr = trans.GetObject(bt.Item(strsourceblockname), OpenMode.ForRead)&lt;BR /&gt;
                    End If&lt;BR /&gt;
                Else&lt;BR /&gt;
                    'block not found, insert into drawing&lt;BR /&gt;
                    Using sourcedb As Database = New Database(False, False)&lt;BR /&gt;
                        Try&lt;BR /&gt;
                            sourcedb.ReadDwgFile(strsourceblockpath, IO.FileShare.Read, True, "")&lt;BR /&gt;
                            id = db.Insert(strsourceblockpath, sourcedb, True)&lt;BR /&gt;
                            btr = trans.GetObject(id, OpenMode.ForWrite)&lt;BR /&gt;
                            If strblocknewname &amp;lt;&amp;gt; "" Then&lt;BR /&gt;
                                btr.Name = strblocknewname&lt;BR /&gt;
                            Else&lt;BR /&gt;
                                btr.Name = strsourceblockname&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Catch ex As System.Exception&lt;BR /&gt;
                            Dim aex As New System.Exception("Block file not found " &amp;amp; strsourceblockpath &amp;amp; ": ", ex)&lt;BR /&gt;
                            Throw aex&lt;BR /&gt;
                            Exit Function&lt;BR /&gt;
                        End Try&lt;BR /&gt;
                        sourcedb.Dispose()&lt;BR /&gt;
                    End Using&lt;BR /&gt;
                End If&lt;BR /&gt;
                trans.Commit()&lt;BR /&gt;
            Catch ex As System.Exception&lt;BR /&gt;
                Dim aex2 As New System.Exception("Error in inserting new block: " &amp;amp; strsourceblockname &amp;amp; ": ", ex)&lt;BR /&gt;
                Throw aex2&lt;BR /&gt;
            Finally&lt;BR /&gt;
                If Not trans Is Nothing Then trans.Dispose()&lt;BR /&gt;
                If Not dlock Is Nothing Then dlock.Dispose()&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End Using&lt;BR /&gt;
        Return btr&lt;BR /&gt;
    End Function</description>
      <pubDate>Thu, 03 Jul 2008 17:47:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292627#M74187</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-03T17:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: DeepClone Dynamic BlockTableRecord</title>
      <link>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292628#M74188</link>
      <description>Hello everybody,&lt;BR /&gt;
&lt;BR /&gt;
Sorry to let off as I can solve all my own problems, but I can't...  &lt;BR /&gt;
&lt;BR /&gt;
I attempted to speed up my program by creating a system that did not insert the block from file everytime, rather to insert a master block, and clone that one as I needed to.  This worked great for the blocks that all have the same definition block table record, but when I wanted to copy the block table record into a new block I get in trouble.&lt;BR /&gt;
&lt;BR /&gt;
In this mess are 2 functions I created that are supposed to be my one shoe fits all for inserting a block/block reference.  My problem is when I insert a dynamic block, I get the Multiply owned object error upon save; where my source dynamic block, and the cloned dynamic block both have the same entities inside them (by handle).  'Audit' only makes things worse, by putting new handles on all the entities in the source block in addition to the original entities (now I have a block table ref with 2 times the number of entities as the source dwg file.)&lt;BR /&gt;
&lt;BR /&gt;
Can anybody point out the error in my code / logic path please...&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
&lt;BR /&gt;
jvj</description>
      <pubDate>Thu, 03 Jul 2008 17:55:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292628#M74188</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-03T17:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: DeepClone Dynamic BlockTableRecord</title>
      <link>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292629#M74189</link>
      <description>Maybe this helps.&lt;BR /&gt;
[code]&lt;BR /&gt;
public static void TransformClonedSelectionSet(SelectionSet ss, Matrix3d &lt;BR /&gt;
transMatrix)&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
if (ss.Count == 0)&lt;BR /&gt;
&lt;BR /&gt;
return;&lt;BR /&gt;
&lt;BR /&gt;
Database targetDatabase = ss[0].ObjectId.Database;&lt;BR /&gt;
&lt;BR /&gt;
using (Transaction trans = &lt;BR /&gt;
targetDatabase.TransactionManager.StartTransaction())&lt;BR /&gt;
&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
ObjectIdCollection entityCollection = new &lt;BR /&gt;
ObjectIdCollection(ss.GetObjectIds());&lt;BR /&gt;
&lt;BR /&gt;
IdMapping idMap = new IdMapping();&lt;BR /&gt;
&lt;BR /&gt;
targetDatabase.DeepCloneObjects(entityCollection, &lt;BR /&gt;
targetDatabase.CurrentSpaceId, idMap, false);&lt;BR /&gt;
&lt;BR /&gt;
foreach (IdPair pair in idMap)&lt;BR /&gt;
&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
Entity clonedEntity = trans.GetObject(pair.Value, OpenMode.ForRead) as &lt;BR /&gt;
Entity;&lt;BR /&gt;
&lt;BR /&gt;
if (clonedEntity != null)&lt;BR /&gt;
&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
Type et = clonedEntity.GetType();&lt;BR /&gt;
&lt;BR /&gt;
if (typeof(SequenceEnd) != et &amp;amp;&amp;amp; typeof(AttributeReference) != et)&lt;BR /&gt;
&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
clonedEntity.UpgradeOpen();&lt;BR /&gt;
&lt;BR /&gt;
clonedEntity.TransformBy(transMatrix);&lt;BR /&gt;
&lt;BR /&gt;
clonedEntity.DowngradeOpen();&lt;BR /&gt;
&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
trans.Commit();&lt;BR /&gt;
&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
[/code]&lt;BR /&gt;
&lt;BR /&gt;
&lt;JAMIEVJOHNSON&gt; schrieb im Newsbeitrag &lt;BR /&gt;
news:5973147@discussion.autodesk.com...&lt;BR /&gt;
Hello everybody,&lt;BR /&gt;
&lt;BR /&gt;
Sorry to let off as I can solve all my own problems, but I can't...&lt;BR /&gt;
&lt;BR /&gt;
I attempted to speed up my program by creating a system that did not insert &lt;BR /&gt;
the block from file everytime, rather to insert a master block, and clone &lt;BR /&gt;
that one as I needed to.  This worked great for the blocks that all have the &lt;BR /&gt;
same definition block table record, but when I wanted to copy the block &lt;BR /&gt;
table record into a new block I get in trouble.&lt;BR /&gt;
&lt;BR /&gt;
In this mess are 2 functions I created that are supposed to be my one shoe &lt;BR /&gt;
fits all for inserting a block/block reference.  My problem is when I insert &lt;BR /&gt;
a dynamic block, I get the Multiply owned object error upon save; where my &lt;BR /&gt;
source dynamic block, and the cloned dynamic block both have the same &lt;BR /&gt;
entities inside them (by handle).  'Audit' only makes things worse, by &lt;BR /&gt;
putting new handles on all the entities in the source block in addition to &lt;BR /&gt;
the original entities (now I have a block table ref with 2 times the number &lt;BR /&gt;
of entities as the source dwg file.)&lt;BR /&gt;
&lt;BR /&gt;
Can anybody point out the error in my code / logic path please...&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
&lt;BR /&gt;
jvj&lt;/JAMIEVJOHNSON&gt;</description>
      <pubDate>Tue, 15 Jul 2008 09:55:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292629#M74189</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-15T09:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: DeepClone Dynamic BlockTableRecord</title>
      <link>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292630#M74190</link>
      <description>Thankyou for your reply Roland,&lt;BR /&gt;
&lt;BR /&gt;
So what your saying is that I need to use the database.deepcloneobjects instead of the entity.deepclone in order to get the results i'm after?&lt;BR /&gt;
&lt;BR /&gt;
Then you are applying some sort of optional transformation (move, rotate) at the end on all entities that are not SequenceEnd and AttributeReferences.&lt;BR /&gt;
&lt;BR /&gt;
This is for copying block references, or block definitions?  Because I want to copy dynamic block definitions and rename them as well.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
jvj</description>
      <pubDate>Tue, 15 Jul 2008 13:28:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292630#M74190</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-15T13:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: DeepClone Dynamic BlockTableRecord</title>
      <link>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292631#M74191</link>
      <description>I can copy dynamic block references with it and get all the dynamic &lt;BR /&gt;
properties.&lt;BR /&gt;
&lt;JAMIEVJOHNSON&gt; schrieb im Newsbeitrag &lt;BR /&gt;
news:5981579@discussion.autodesk.com...&lt;BR /&gt;
Thankyou for your reply Roland,&lt;BR /&gt;
&lt;BR /&gt;
So what your saying is that I need to use the database.deepcloneobjects &lt;BR /&gt;
instead of the entity.deepclone in order to get the results i'm after?&lt;BR /&gt;
&lt;BR /&gt;
Then you are applying some sort of optional transformation (move, rotate) at &lt;BR /&gt;
the end on all entities that are not SequenceEnd and AttributeReferences.&lt;BR /&gt;
&lt;BR /&gt;
This is for copying block references, or block definitions?  Because I want &lt;BR /&gt;
to copy dynamic block definitions and rename them as well.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
jvj&lt;/JAMIEVJOHNSON&gt;</description>
      <pubDate>Thu, 17 Jul 2008 14:05:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/deepclone-dynamic-blocktablerecord/m-p/2292631#M74191</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-17T14:05:25Z</dc:date>
    </item>
  </channel>
</rss>

