Results 1 to 4 of 4

Thread: Find string in drawing and replace with VBA

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2006-02
    Posts
    10
    Login to Give a bone
    0

    Default Find string in drawing and replace with VBA

    I'm trying to create something that will find a particular text object based on its string, and replace it with a variable value.

    For example...

    I've got a table (on PaperSpace) of calculations for area square footages. It would look something like this:
    Total coverage........SQcov
    Livable...................SQliv
    Exterior..................SQext

    The "SQxxx" are all basic text objects. I already have a working function that uses the geometry in the drawing (ModelSpace) to automatically calculate the appropriate values, and now I want to simply replace the text string "SQxxx" with the value of the variable containing the appropriate calculated area.

    I also have several different PaperSpace layouts, but I know exactly which one each string is on, so I can easily specify that if necessary. I'm not even sure if that matters..

    Anybody know how I can do this? I'm fairly new to VBA still.

    --Montana

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Find string in drawing and replace with VBA

    You failed to mention what version of AutoCAD... fields in 2005 or later will does this already.

  3. #3
    Member
    Join Date
    2006-02
    Posts
    10
    Login to Give a bone
    0

    Default Re: Find string in drawing and replace with VBA

    Sorry, I'm using ADT 2004.

  4. #4
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Find string in drawing and replace with VBA

    The brute-force approach would be to get the layout, then loop thru the objects until you find the needed string.

    You can get the Layout object:
    Set myLayout = ThisDrawing.Layouts.Item("Layout1")

    Once you have that, iterate thru the Layout.Block until you get to the text object.

Similar Threads

  1. how to replace only a single string by pre decided string.
    By mohammad.raees637333 in forum AutoLISP
    Replies: 3
    Last Post: 2014-04-22, 01:07 PM
  2. How do I replace part of a string?
    By aaronic_abacus in forum AutoLISP
    Replies: 2
    Last Post: 2009-12-12, 06:24 PM
  3. Find and/or Replace Text in the Drawing Manager
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2009-10-25, 03:34 PM
  4. Replies: 0
    Last Post: 2008-05-22, 08:49 PM
  5. find and replace removing first letter string
    By tyeelaw13 in forum AutoCAD General
    Replies: 9
    Last Post: 2005-05-03, 04:20 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
  •