<?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: Centering Text while using Python Code in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/centering-text-while-using-python-code/m-p/12386282#M21601</link>
    <description>&lt;P&gt;You can try running ATTSYNC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTY, using send command is probably not the best approach. You can modify blocks and their attributes with the ActiveX API&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30" target="_blank"&gt;https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Nov 2023 22:33:38 GMT</pubDate>
    <dc:creator>daniel_cadext</dc:creator>
    <dc:date>2023-11-18T22:33:38Z</dc:date>
    <item>
      <title>Centering Text while using Python Code</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/centering-text-while-using-python-code/m-p/12386260#M21600</link>
      <description>&lt;P&gt;So I have been developing a code below that will search a specific folder for dwg's then it will open them and edit some revision text. Here is the code below (I will explain the prob after the code):&lt;/P&gt;&lt;LI-CODE lang="general"&gt;import os
import win32com.client
import time

# ----------------------Set global Type Variables For this Program---------------------------------#
# File Extension of the file type we want to sort out of the active directory
file_extension = "dwg"
# Location of the source folder
path = 'C:/Userbackups/autocad-sample-drawings/'
save_path = 'C:/Userbackups/autocad-sampleRev-Up-drawings/'



# ----------------------Get a list of all the .dwg files in directory path---------------------------#
dir_list = os.listdir(path)
dwg_files = [file for file in dir_list if file.split('.')[1] == file_extension]

# Debugging check display the files on the terminal
# Specify the directory where the files are located
print("Files and directories in '", path, " :")
# List the files on the screen
for filename in dwg_files:
    print(filename)
# Add a blank row on the screen
print("\n")
# Open the AutoCAD
acad = win32com.client.dynamic.Dispatch("AutoCAD.Application")

# Go through each file in the directory that had a .dwg extension
for filename in dwg_files:
    # Define the file path and file name to open
    file_path = path + filename
    # For debugging confirm file path
    print(file_path)
    # Open the file as an AutoCad object
    time.sleep(5)
    doc = acad.Documents.Open(file_path)
    # Make the autocad application visible on the screen
    time.sleep(3)
    acad.Visible = True
    # ---------------------- AutoCad prompt commands ------------------------------------------------#
    # 5 Second delay added for now to ensure Autocadd open the drawing
    print('5 second delay start')
   time.sleep(5)
    print('5 second delay end')
    # Send Zoom Extents Command to AutoCad
    doc.SendCommand("_ZOOM _E \n")
    # Change the Rev Number on the drawing
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #5 B \n Y \n')
    doc.SendCommand('\n')
    # Add new rev #
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #30 B \n Y \n')
    doc.SendCommand('\n')
    # Add new rev Month
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #31 OCT \n Y \n')
    doc.SendCommand('\n')
    # Add new rev YEAR
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #32 23 \n Y \n')
    doc.SendCommand('\n')
    # Add new rev DESCRIPTION TOP
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #33 IFC \n Y \n')
    doc.SendCommand('\n')
    # Add new rev DESCRIPTION BOTTOM
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #34 PROJ#-I&amp;amp;E=#1 \n Y \n')
    doc.SendCommand('\n')
    # Add new rev DRAWN BY
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #35 TC \n Y \n')
    doc.SendCommand('\n')
    # Add new rev CHECKED BY
    doc.SendCommand('\n')
    doc.SendCommand('_GATTE _B Ttl_b #36 TC \n Y \n')
    doc.SendCommand('\n')
    # Add delay to ensure changes made
    time.sleep(3)
    save_file_path = save_path + filename
    doc.SaveAs(save_file_path)
    doc.Close()
    print(filename, " Rev'd up\n")

# Close AutoCad
time.sleep(3)
acad.Quit()

print("Rev up completed")&lt;/LI-CODE&gt;&lt;P&gt;So the code will input the text fine but it will input the text at an off center alignment. See photo below&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image001.png" style="width: 215px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1294647iC21931128BF2E784/image-size/large?v=v2&amp;amp;px=999" role="button" title="image001.png" alt="image001.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The Line with the "A" revision is manually entered text - When manually entered the text appears in the center of the text box. The properties of the text says the alignment is "Center Middle"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Line with the "B" revision is text entered using the code - When entered with the code the text appears in the left side of the text box. The properties of the text still says the alignment is "Center Middle".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have any ideas how to automate the process of having this text auto centered within the code?&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2023 22:08:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/centering-text-while-using-python-code/m-p/12386260#M21600</guid>
      <dc:creator>troy_ferris97</dc:creator>
      <dc:date>2023-11-18T22:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Centering Text while using Python Code</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/centering-text-while-using-python-code/m-p/12386282#M21601</link>
      <description>&lt;P&gt;You can try running ATTSYNC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTY, using send command is probably not the best approach. You can modify blocks and their attributes with the ActiveX API&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30" target="_blank"&gt;https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2023 22:33:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/centering-text-while-using-python-code/m-p/12386282#M21601</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2023-11-18T22:33:38Z</dc:date>
    </item>
  </channel>
</rss>

