Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Replace a specific line of text within a file

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Replace a specific line of text within a file

    As the title states, what is the simplest way to replace a specific line of text within a file.

    I need to have the ability to replace line 5 and line 7 of a particular file progammatically, based on the current annotation scale.

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    More details would be helpful. What type of object needs modification?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    Quote Originally Posted by Opie View Post
    More details would be helpful. What type of object needs modification?
    ye ask and ye shall receive.
    Eagle Point uses *.set files to contain their plot scales as well as many other settings. When reducing point files, our office would like to use annotative blocks, so they will show up at acceptable sizes no matter the viewport scale. Eagle Point uses the plot scale factor to scale points when they are reduced. Our intention is to set the plot scale to 1 reduce the points (so they come in at a scale of 1) and then change the plot scale back. Or possible just set up the routine so the plot scale matches the current annotation scale (i.e. 1:1 would result in a 1 scale plot scale, 1:40 would result in a 40 scale plot scale, and so on.)

    The 5th line of the *.set file contains the horizontal plot scale of the Eagle Point Project, the 7th line contains the vertical plot scale. I guess I really only need to be able to update the 5th line, as the 7th does not affect the scale of reduced points.

    Here is the first 10 lines of a typical *.set file
    EAGLE POINT / Systems
    VERSION ad 1.0
    EP Settings File
    VERSION 1.0
    AAPLAN000HORZSCALED 480
    AAPLAN000UNITSI 21
    AAPLAN000VERTSCALED 60
    ACADPROTOTYPESEEDFILES Z:\Prototypes\Road Base.dwg
    ALIGNMENTDATABASES Align001.MDB
    CURRGRAPHICKEYS AAPLAN000
    the scales are multiplied by 12 (inches in a foot). The actual scale is 40 horizontal, 5 vertical

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    Are you wanting the user to navigate to it? Or let the computer user the CurrentDataLocation folder as it is listed in Eagle Point's registry settings to locate this file?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    Quote Originally Posted by Opie View Post
    Are you wanting the user to navigate to it? Or let the computer user the CurrentDataLocation folder as it is listed in Eagle Point's registry settings to locate this file?
    I would say no to both. Our standard for reducing point files is that our base drawing and Eagle Point information is always in the same folder. So I would use the current drawing's folder, check to see if the file exists, and then run the program if it does.

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    • Make a backup copy of the file.
    • You need to read the file into a list.
    • Search the list for the right tag (my .set file does not have that tag as the fifth line).
    • Change the number at the end to the right value
    • Write the list back into the file.


    A secondary routine to restore the backup file after reducing the points.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    Quote Originally Posted by Opie View Post
    • Make a backup copy of the file.
    • You need to read the file into a list.
    • Search the list for the right tag (my .set file does not have that tag as the fifth line).
    • Change the number at the end to the right value
    • Write the list back into the file.

    A secondary routine to restore the backup file after reducing the points.
    so do the following?
    Code:
    ;rename existing file
    ;create new file with old name and open for write
    ;open existing file for read
    ;(while read each line
    ;if wcmatch line matches beginning of line that needs to be changed
    ;replace with this line
    ;increment line counter)
    ;close both files
    and
    Code:
    ;erase new file
    ;rename existing file

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    Sounds about right to me.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    Quote Originally Posted by Opie View Post
    Sounds about right to me.
    I'll give it a shot and let you know how it goes.

  10. #10
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Replace a specific line of text within a file

    You can do it. Be warned, I have had problems with Eagle Point when changing Eagle Point generated files. Hopefully, you won't have any of those problems.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Page 1 of 2 12 LastLast

Similar Threads

  1. Text Replace using CSV
    By mrsusan in forum AutoLISP
    Replies: 6
    Last Post: 2012-02-16, 09:39 AM
  2. Dim Text on Specific Layer instead of having Specific Color
    By Masroor Javid in forum ACA Wish List
    Replies: 0
    Last Post: 2009-02-23, 09:34 AM
  3. File and Replace text via C#
    By nvphatbk in forum Dot Net API
    Replies: 3
    Last Post: 2008-12-16, 06:23 PM
  4. Replies: 4
    Last Post: 2007-01-22, 11:04 AM
  5. read-line loop column text file
    By dukwing16 in forum AutoLISP
    Replies: 7
    Last Post: 2006-05-13, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •