<?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: Working in PaperSpace in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718204#M52207</link>
    <description>&lt;PRE&gt;    Public Shared Sub New_Text(ByVal acObjIdColl As ObjectIdCollection, ByVal sSpace As String, ByVal Text_Location As Point3d, _
                               ByVal Text_Height As Double, ByVal Text_String As String, ByVal Layer As String, ByVal Text_Style As String, _
                               ByVal Color As String, ByVal Justification As String, ByVal Vertical_Alignment As String)
      Dim acDoc As Document
      Dim acCurDb As Database
      Dim acBlkTbl As BlockTable
      Dim acBlkTblRec As BlockTableRecord
      Dim acText As DBText

      acDoc = Application.DocumentManager.MdiActiveDocument
      acCurDb = acDoc.Database
      Using acLckDoc As DocumentLock = acDoc.LockDocument
        Application.SetSystemVariable("CLAYER", Layer)
        Application.SetSystemVariable("TEXTSTYLE", Text_Style)
        Application.SetSystemVariable("CECOLOR", Color)
        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
          '' Open the Block table for read
          acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
          '' Open the Block table record Model space for write
          If sSpace = "Model" Then
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
          Else
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
          End If
          acText = New DBText()
          acText.SetDatabaseDefaults()
          acText.Position = Text_Location
          acText.Height = Text_Height
          acText.TextString = Text_String
          acBlkTblRec.AppendEntity(acText)
          Select Case LCase(Justification)
            Case "right"
              If LCase(Vertical_Alignment) = "middle" Then
                acText.HorizontalMode = TextHorizontalMode.TextRight
                acText.VerticalMode = TextVerticalMode.TextVerticalMid
              Else
                acText.HorizontalMode = TextHorizontalMode.TextRight
              End If
            Case "center"
              If LCase(Vertical_Alignment) = "middle" Then
                acText.HorizontalMode = TextHorizontalMode.TextCenter
                acText.VerticalMode = TextVerticalMode.TextVerticalMid
              Else
                acText.HorizontalMode = TextHorizontalMode.TextRight
              End If
            Case "left"
              If LCase(Vertical_Alignment) = "middle" Then
                acText.HorizontalMode = TextHorizontalMode.TextLeft
                acText.VerticalMode = TextVerticalMode.TextVerticalMid
              Else
                acText.HorizontalMode = TextHorizontalMode.TextRight
              End If
          End Select
          acTrans.AddNewlyCreatedDBObject(acText, True)
          '' Save the changes and dispose of the transaction
          acTrans.Commit()
        End Using
        acDoc.Editor.UpdateScreen()
      End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response Khoa.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the complete Sub.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm able to insert the frame work of the Stock list in the correct location. I don't understand the problem with the Text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brian&lt;/P&gt;</description>
    <pubDate>Fri, 30 Nov 2012 19:55:52 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-11-30T19:55:52Z</dc:date>
    <item>
      <title>Working in PaperSpace</title>
      <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3717990#M52205</link>
      <description>&lt;PRE&gt;      Dim acDoc As Document
      Dim acCurDb As Database
      Dim acBlkTbl As BlockTable
      Dim acBlkTblRec As BlockTableRecord
      Dim acText As DBText = New DBText()

      acDoc = Application.DocumentManager.MdiActiveDocument
      acCurDb = acDoc.Database

      Using acLckDoc As DocumentLock = acDoc.LockDocument

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

          acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

          acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), OpenMode.ForWrite)

          acText = New DBText()

          acText.Position = New Point3d(31.5359, 2.5536, 0)

          acBlkTblRec.AppendEntity(acText)

          acTrans.AddNewlyCreatedDBObject(acText, True)

          acTrans.Commit()

        End Using

        acDoc.Editor.UpdateScreen()

      End Using

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to fill out a sheet stocklist in paperspace. What is the trick to get the new text object located in the proper place? When I run the attached code, the text always is located at 0,0,0. Is there an offset I need to apply?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 17:22:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3717990#M52205</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-30T17:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Working in PaperSpace</title>
      <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718178#M52206</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code looks right to insert the text at a specified position in the &lt;U&gt;first layout&amp;nbsp;of paper space&lt;/U&gt;. I don't know why your text is located at (0, 0, 0). You may post your detailed code to help to&amp;nbsp;see the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 19:44:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718178#M52206</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-30T19:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Working in PaperSpace</title>
      <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718204#M52207</link>
      <description>&lt;PRE&gt;    Public Shared Sub New_Text(ByVal acObjIdColl As ObjectIdCollection, ByVal sSpace As String, ByVal Text_Location As Point3d, _
                               ByVal Text_Height As Double, ByVal Text_String As String, ByVal Layer As String, ByVal Text_Style As String, _
                               ByVal Color As String, ByVal Justification As String, ByVal Vertical_Alignment As String)
      Dim acDoc As Document
      Dim acCurDb As Database
      Dim acBlkTbl As BlockTable
      Dim acBlkTblRec As BlockTableRecord
      Dim acText As DBText

      acDoc = Application.DocumentManager.MdiActiveDocument
      acCurDb = acDoc.Database
      Using acLckDoc As DocumentLock = acDoc.LockDocument
        Application.SetSystemVariable("CLAYER", Layer)
        Application.SetSystemVariable("TEXTSTYLE", Text_Style)
        Application.SetSystemVariable("CECOLOR", Color)
        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
          '' Open the Block table for read
          acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
          '' Open the Block table record Model space for write
          If sSpace = "Model" Then
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
          Else
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
          End If
          acText = New DBText()
          acText.SetDatabaseDefaults()
          acText.Position = Text_Location
          acText.Height = Text_Height
          acText.TextString = Text_String
          acBlkTblRec.AppendEntity(acText)
          Select Case LCase(Justification)
            Case "right"
              If LCase(Vertical_Alignment) = "middle" Then
                acText.HorizontalMode = TextHorizontalMode.TextRight
                acText.VerticalMode = TextVerticalMode.TextVerticalMid
              Else
                acText.HorizontalMode = TextHorizontalMode.TextRight
              End If
            Case "center"
              If LCase(Vertical_Alignment) = "middle" Then
                acText.HorizontalMode = TextHorizontalMode.TextCenter
                acText.VerticalMode = TextVerticalMode.TextVerticalMid
              Else
                acText.HorizontalMode = TextHorizontalMode.TextRight
              End If
            Case "left"
              If LCase(Vertical_Alignment) = "middle" Then
                acText.HorizontalMode = TextHorizontalMode.TextLeft
                acText.VerticalMode = TextVerticalMode.TextVerticalMid
              Else
                acText.HorizontalMode = TextHorizontalMode.TextRight
              End If
          End Select
          acTrans.AddNewlyCreatedDBObject(acText, True)
          '' Save the changes and dispose of the transaction
          acTrans.Commit()
        End Using
        acDoc.Editor.UpdateScreen()
      End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response Khoa.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the complete Sub.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm able to insert the frame work of the Stock list in the correct location. I don't understand the problem with the Text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brian&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 19:55:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718204#M52207</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-30T19:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Working in PaperSpace</title>
      <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718456#M52208</link>
      <description>&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for a bit lag. I don't have a chance to test your code yet. I will check it again after work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 22:03:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718456#M52208</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-11-30T22:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Working in PaperSpace</title>
      <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718696#M52209</link>
      <description>&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AutoCAD uses &lt;STRONG&gt;DBText.AlignmentPoint&lt;/STRONG&gt; property to adjust alignment of a text if it is not&amp;nbsp;horizontal left (TextHorizontalMode.TextLeft)&amp;nbsp;and vertical base (TextVerticalMode.TextBase) by default.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DBText.Position defines a text&amp;nbsp;insertion point&amp;nbsp;while DBText.AlignmentPoint defines&amp;nbsp;its alignment point. They are different. AlignmentPoint does not need to set (it will get default value 0,0,0), if the text is &lt;U&gt;default&amp;nbsp;horizontal left and vertical base&lt;/U&gt; (it will fail if we try to change AlignmentPoint at this time).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If&amp;nbsp;we change horizontal and vertical alignments to be different with their default values, the Position property&amp;nbsp;(&lt;EM&gt;&lt;STRONG&gt;lower left&lt;/STRONG&gt; point of the text&lt;/EM&gt;) becomes useless because it will be &lt;U&gt;different depending on text height and width&lt;/U&gt;. Instead,&amp;nbsp;we need to set AlignmentPoint property. The AlignmentPoint will be the text&amp;nbsp;location at this time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;problem is&amp;nbsp;that the text is always at (0, 0, 0) point regardless of any DBText.Position because this text has alignment properties different with its&amp;nbsp;default values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you just need to add &lt;U&gt;acText.&lt;STRONG&gt;AlignmentPoint&lt;/STRONG&gt; = Text_Location after&amp;nbsp;modifying horizontal and vertical modes&lt;/U&gt;.&amp;nbsp;I rewrite your code (in C#) with a test method to add texts in both Model and Paper spaces. The issue is the text alignment, not belongs to Paper space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("New_Text")]
public static void New_Text()
{
    New_Text(null, "Model", new Point3d(5, 10, 0), 2, "My model text", "0", "Standard", "2", "center", "middle");
    New_Text(null, "Layout", new Point3d(5, 10, 0), 2, "My paper text", "0", "Standard", "3", "left", "middle");
}

public static void New_Text(ObjectIdCollection acObjIdColl, string sSpace, Point3d Text_Location, double Text_Height,
                            string Text_String, string Layer, string Text_Style, string Color, string Justification,
                            string Vertical_Alignment)
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;
    using (DocumentLock acLckDoc = acDoc.LockDocument())
    {
        Application.SetSystemVariable("CLAYER", Layer);
        Application.SetSystemVariable("TEXTSTYLE", Text_Style);
        Application.SetSystemVariable("CECOLOR", Color);
        // Start a transaction
        using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
        {
            // Open the Block table for read
            BlockTable acBlkTbl = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
            // Open the Block table record Model space for write
            BlockTableRecord acBlkTblRec;
            if ((sSpace == "Model"))
            {
                acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
            }
            else
            {
                acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite);
            }
            DBText acText = new DBText();
            acText.SetDatabaseDefaults();
            acText.Position = Text_Location;
            acText.Height = Text_Height;
            acText.TextString = Text_String;
            acBlkTblRec.AppendEntity(acText);
            switch (Justification.ToLower())
            {
                case "right":
                    if ((Vertical_Alignment.ToLower() == "middle"))
                    {
                        acText.HorizontalMode = TextHorizontalMode.TextRight;
                        acText.VerticalMode = TextVerticalMode.TextVerticalMid;
                    }
                    else
                    {
                        acText.HorizontalMode = TextHorizontalMode.TextRight;
                    }
                    break;
                case "center":
                    if ((Vertical_Alignment.ToLower() == "middle"))
                    {
                        acText.HorizontalMode = TextHorizontalMode.TextCenter;
                        acText.VerticalMode = TextVerticalMode.TextVerticalMid;
                    }
                    else
                    {
                        acText.HorizontalMode = TextHorizontalMode.TextRight;
                    }
                    break;
                case "left":
                    if ((Vertical_Alignment.ToLower() == "middle"))
                    {
                        acText.HorizontalMode = TextHorizontalMode.TextLeft;
                        acText.VerticalMode = TextVerticalMode.TextVerticalMid;
                    }
                    else
                    {
                        acText.HorizontalMode = TextHorizontalMode.TextRight;
                    }
                    break;
            }
            acText.AlignmentPoint = Text_Location;

            acTrans.AddNewlyCreatedDBObject(acText, true);
            // Save the changes and dispose of the transaction
            acTrans.Commit();
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Khoa&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2012 02:04:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718696#M52209</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-01T02:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Working in PaperSpace</title>
      <link>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718906#M52210</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By my side, I use a SetPosition() extension method for the DBText type. This method takes care of setting AlignmentPoint according to the text Justification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C#&lt;/P&gt;&lt;PRE&gt;    public static class DBTextExtension
    {
        public static void SetPosition(this DBText text, Point3d pt, AttachmentPoint justif)
        {
            text.Position = pt;
            text.Justify = justif;
            if (text.HorizontalMode != TextHorizontalMode.TextLeft || 
                text.VerticalMode != TextVerticalMode.TextBase)
            {
                text.AlignmentPoint = pt;
                text.AdjustAlignment(HostApplicationServices.WorkingDatabase);
            }
        }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;F#&lt;/P&gt;&lt;PRE&gt;type DBText with
    member txt.SetPosition(pt,&amp;nbsp;justif) =
        txt.Position &amp;lt;- pt
        txt.Justify &amp;lt;- justif
        if txt.HorizontalMode &amp;lt;&amp;gt; TextHorizontalMode.TextLeft ||
            txt.VerticalMode &amp;lt;&amp;gt; TextVerticalMode.TextBase then
            txt.AlignmentPoint &amp;lt;- pt
            txt.AdjustAlignment(HostApplicationServices.WorkingDatabase)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VB&lt;/P&gt;&lt;PRE&gt;    Module DBTextExtensions

        &amp;lt;System.Runtime.CompilerServices.Extension()&amp;gt; _
        Public Sub SetPosition(ByVal text As DBText, ByVal pt As Point3d, ByVal justif As AttachmentPoint)
            text.Position = pt
            text.Justify = justif
            If text.HorizontalMode &amp;lt;&amp;gt; TextHorizontalMode.TextLeft OrElse _
                text.VerticalMode &amp;lt;&amp;gt; TextVerticalMode.TextBase Then
                text.AlignmentPoint = pt
                text.AdjustAlignment(HostApplicationServices.WorkingDatabase)
            End If
        End Sub

    End Module&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2012 14:31:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/working-in-paperspace/m-p/3718906#M52210</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-12-01T14:31:12Z</dc:date>
    </item>
  </channel>
</rss>

