<?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: Copy block from one layout to all other layouts same coordinates in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9670171#M18835</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One last question....&lt;/P&gt;&lt;P&gt;One of the attributes may or may not contain a width factor that is set on insert.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I assign the same width factor to each "copied" block's attribute. I have tried many things over the weekend and cant seem to figure it out. I have the tag name for the attribute and the width but cant seem to figure out how to apply it to that attribute during the copy process.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Aug 2020 15:57:57 GMT</pubDate>
    <dc:creator>David_Prontnicki</dc:creator>
    <dc:date>2020-08-03T15:57:57Z</dc:date>
    <item>
      <title>Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667063#M18829</link>
      <description>&lt;P&gt;I am trying to copy a block reference to each paperspace layout tab to the same coordinates. The program currently inserts the block at the user's selected coordinates. I get the block objectId and the user selected coordinates and pass them to the sub below. I have tried may things but cant seem to get it to work. Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    Private Sub CopyToAllLayouts(acBlockReferenceObjectId As ObjectId, insertionPoint As Point3d)

        Dim acCurrentDatabase As Database = Active.Database
        Dim acDocumentEditor As Editor = Active.Editor

        Using acDocumentLock As DocumentLock = Active.Document.LockDocument()

            Using acTranaction As Transaction = Active.Database.TransactionManager.StartTransaction()

                Dim acLayoutDatabaseDictionary As DBDictionary = TryCast(acTranaction.GetObject(acCurrentDatabase.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)

                For Each acLayoutDatabaseDictionaryEntry As DBDictionaryEntry In acLayoutDatabaseDictionary

                    Dim acLayout As Layout = CType(acLayoutDatabaseDictionaryEntry.Value.GetObject(OpenMode.ForRead), Layout)
                    Dim acLayoutName As String = acLayout.LayoutName
                    Dim acLayoutObjectId As ObjectId = acLayoutDatabaseDictionary.GetAt(acLayoutName)

                    Dim acBlockTableRecord = CType(acTranaction.GetObject(acLayout.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord)

                    Dim acBlockReference As BlockReference = New BlockReference(insertionPoint, acBlockReferenceObjectId)

                    'Dim acBlockTable = DirectCast(acTranaction.GetObject(acCurrentDatabase.BlockTableId, OpenMode.ForRead), BlockTable)
                    'Dim acBlockReference = New BlockReference(insertionPoint, acBlockReferenceObjectId)
                    'Dim acBlockTableRecord = DirectCast(acTranaction.GetObject(acCurrentDatabase.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

                    'acBlockReference.TransformBy(acDocumentEditor.CurrentUserCoordinateSystem)

                    acBlockTableRecord.UpgradeOpen()
                    acBlockReference.TransformBy(acDocumentEditor.CurrentUserCoordinateSystem)
                    acBlockTableRecord.AppendEntity(acBlockReference)
                    acTranaction.AddNewlyCreatedDBObject(acBlockReference, True)

                Next

                acTranaction.Commit()

            End Using

        End Using

    End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 31 Jul 2020 20:23:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667063#M18829</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2020-07-31T20:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667101#M18830</link>
      <description>&lt;P&gt;This should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private static void CopyToAllLayouts(ObjectId blockTableRecordId, Point3d position)
        {
            var db = HostApplicationServices.WorkingDatabase;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                foreach (DBDictionaryEntry entry in layouts)
                {
                    if (entry.Key != "Model")
                    {
                        var layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                        var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
                        var br = new BlockReference(position, blockTableRecordId);
                        btr.AppendEntity(br);
                        tr.AddNewlyCreatedDBObject(br, true);
                    }
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 31 Jul 2020 21:01:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667101#M18830</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-07-31T21:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667136#M18831</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the speedy reply. One small problem. It is copying the block to the right location but the attributes are now empty. The block contains 5 attribute values that get applied on initial insertion. That works perfect. during the copy process the attributes are now blank. Any ideas why that may be?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 21:32:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667136#M18831</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2020-07-31T21:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667363#M18832</link>
      <description>&lt;P&gt;With .NET, you have to explicitly create the attribute references using the attribute definitions as templates. See &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-2107599E-9405-4D8B-A6DD-83D603B41568" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;this topic&lt;/STRONG&gt;&lt;/A&gt;.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private static void CopyToAllLayouts(ObjectId blockTableRecordId, Point3d position)
{
    var db = HostApplicationServices.WorkingDatabase;
    using (var tr = db.TransactionManager.StartTransaction())
    {
        var layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
        foreach (DBDictionaryEntry entry in layouts)
        {
            if (entry.Key != "Model")
            {
                // insert the block reference
                var layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                var owner = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
                var br = new BlockReference(position, blockTableRecordId);
                owner.AppendEntity(br);
                tr.AddNewlyCreatedDBObject(br, true);

                // add attribute references
                var btr = (BlockTableRecord)tr.GetObject(blockTableRecordId, OpenMode.ForRead);
                foreach (ObjectId id in btr)
                {
                    if (id.ObjectClass == RXObject.GetClass(typeof(AttributeDefinition)))
                    {
                        var attDef = (AttributeDefinition)tr.GetObject(id, OpenMode.ForRead);
                        if (!attDef.Constant)
                        {
                            var attRef = new AttributeReference();
                            attRef.SetAttributeFromBlock(attDef, br.BlockTransform);
                            br.AttributeCollection.AppendAttribute(attRef);
                            tr.AddNewlyCreatedDBObject(attRef, true);
                        }
                    }
                }
            }
        }
        tr.Commit();
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 01 Aug 2020 05:41:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9667363#M18832</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-08-01T05:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9669599#M18833</link>
      <description>&lt;P&gt;Hello &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/99495"&gt;@David_Prontnicki&lt;/a&gt; !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Great to see you here on .NET forum.&lt;/P&gt;
&lt;P&gt;Don't forget to accept a solution when you receive the answer which works for you.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 11:27:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9669599#M18833</guid>
      <dc:creator>lena.talkhina</dc:creator>
      <dc:date>2020-08-03T11:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9669932#M18834</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much. Works perfect. I appreciate all the help, and apologize for not mentioning the attributes in the OP.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 14:04:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9669932#M18834</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2020-08-03T14:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9670171#M18835</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One last question....&lt;/P&gt;&lt;P&gt;One of the attributes may or may not contain a width factor that is set on insert.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I assign the same width factor to each "copied" block's attribute. I have tried many things over the weekend and cant seem to figure it out. I have the tag name for the attribute and the width but cant seem to figure out how to apply it to that attribute during the copy process.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 15:57:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9670171#M18835</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2020-08-03T15:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Copy block from one layout to all other layouts same coordinates</title>
      <link>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9670204#M18836</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Never mind. Of course I figure it out after I post. LOL sometimes typing out the question gets you the answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Sub CopyBlockToAllLayouts(acInsertedBlockTableRecordObjectId As ObjectId, insertionPoint As Point3d)

        Dim acCurrentDatabase As Database = Active.Database

        Dim professionalAttributeObjectId As ObjectId

        Using acDocumentLock As DocumentLock = Active.Document.LockDocument()

            Using acTranaction As Transaction = acCurrentDatabase.TransactionManager.StartTransaction()

                Dim acLayoutDatabaseDictionary = CType(acTranaction.GetObject(acCurrentDatabase.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)

                For Each acLayoutDatabaseDictionaryEntry As DBDictionaryEntry In acLayoutDatabaseDictionary

                    If acLayoutDatabaseDictionaryEntry.Key &amp;lt;&amp;gt; "Model" Then

                        Dim acLayout = CType(acTranaction.GetObject(acLayoutDatabaseDictionaryEntry.Value, OpenMode.ForRead), Layout)
                        Dim acBlockTableRecordOwner = CType(acTranaction.GetObject(acLayout.BlockTableRecordId, OpenMode.ForWrite), BlockTableRecord)
                        Dim acBlockReference = New BlockReference(insertionPoint, acInsertedBlockTableRecordObjectId)

                        acBlockTableRecordOwner.AppendEntity(acBlockReference)
                        acTranaction.AddNewlyCreatedDBObject(acBlockReference, True)

                        Dim acBlockTableRecord = CType(acTranaction.GetObject(acInsertedBlockTableRecordObjectId, OpenMode.ForRead), BlockTableRecord)

                        For Each acAtributeDefinitionObjectId As ObjectId In acBlockTableRecord

                            If acAtributeDefinitionObjectId.ObjectClass = RXObject.GetClass(GetType(AttributeDefinition)) Then

                                Dim acAttributeDefinition = CType(acTranaction.GetObject(acAtributeDefinitionObjectId, OpenMode.ForRead), AttributeDefinition)

                                If Not acAttributeDefinition.Constant Then

                                    Dim acAttributeReference As New AttributeReference()
                                    acAttributeReference.SetAttributeFromBlock(acAttributeDefinition, acBlockReference.BlockTransform)
'Added this line
                                    acAttributeReference.TextString = acAttributeDefinition.TextString
                                    acBlockReference.AttributeCollection.AppendAttribute(acAttributeReference)
                                    acTranaction.AddNewlyCreatedDBObject(acAttributeReference, True)
'added select case and ran my SetNameAttributeWidth sub
                                    Select Case acAttributeDefinition.Tag

                                        Case "PROFESSIONAL"

                                            professionalAttributeObjectId = acAttributeReference.ObjectId

                                            SetNameAttributeWidth(professionalAttributeObjectId, 2.7)

                                    End Select

                                End If

                            End If

                        Next

                    End If

                Next

                acTranaction.Commit()

            End Using

        End Using

    End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 03 Aug 2020 16:12:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/copy-block-from-one-layout-to-all-other-layouts-same-coordinates/m-p/9670204#M18836</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2020-08-03T16:12:34Z</dc:date>
    </item>
  </channel>
</rss>

