Results 1 to 4 of 4

Thread: File and Replace text via C#

  1. #1
    Member
    Join Date
    2007-07
    Posts
    17
    Login to Give a bone
    0

    Default File and Replace text via C#

    hi anyone!
    I wanna create file and replace text in many drawings at the same time via C#. Does anyone help me to do that! thanks in advance. I did that but the result doesn't good.
    phat

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: File and Replace text via C#

    Maybe if you post the code you have, then others can help you optimize it.

  3. #3
    Member
    Join Date
    2007-07
    Posts
    17
    Login to Give a bone
    0

    Default Re: File and Replace text via C#

    Hi T.Willey,
    here is my code
    private void button1_Click(object sender, EventArgs e)
    {
    CAD.AcadDocument dx01 = null;
    acad = new CAD.AcadApplication();
    acad.Visible = true;

    for (int i = 0; i < listBox1.Items.Count; i++)
    {
    dx01 = acad.Documents.Open(listBox1.Items[i].ToString(), true, null);
    dx01 = acad.ActiveDocument;

    CAD.AcadSelectionSets objSelCol = dx01.SelectionSets;

    foreach (CAD.AcadSelectionSet objSelSet in objSelCol)
    {
    if (objSelSet.Name == "ISSUED FOR APPROVAL")
    {
    objSelSet.Name = "ISSUED FOR CONSTRUCTION";
    }
    }

    dx01.Save();
    dx01.Close(false, null);
    }
    ---> I have so many drawings contain "ISSUED FOR APPROVAL", and I want to change into "ISSUED FOR CONSTRUCTION"
    ---> My problem is the objSelCol.count = 0. So., there is nothing change in my drawings.
    thanks alots.

  4. #4
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: File and Replace text via C#

    So are you running this from outside Acad? If so, I have no experience, and I hear it is slow that way. If you can run it from within Acad then it will be faster.

    You can open a drawings database without opening the drawing in the editor, which will make it run a lot faster, but you can't use ' ssget ', because that is based off the document and not the database, I think. But even so, you can mimic what the ' ssget ' is doing. All you have to do is search each layout for the object type(s) you want, and then see if the string value has the string you want within. If so change it, and note that you changed it, so that you know to save the drawing.

    If the text will be nested within a block, then just step through the block table, and search each one to see if it contains an object with the string desired to change. The layouts are defined as blocks, so by searching all records in the block table, you will search all the layouts also. This may be the direction you want to go, but you only need to go this way if you think the string can be nested within a block.

    Does this sound like something you can do? Or do you need more guidance?

Similar Threads

  1. Text Replace using CSV
    By mrsusan in forum AutoLISP
    Replies: 6
    Last Post: 2012-02-16, 09:39 AM
  2. Replace a specific line of text within a file
    By ccowgill in forum AutoLISP
    Replies: 15
    Last Post: 2009-06-15, 05:21 PM
  3. Find and Replace Text
    By Catiator in forum Revit MEP - General
    Replies: 1
    Last Post: 2008-06-12, 03:35 PM
  4. RS3: Find and Replace Text
    By nemmersbj in forum Revit Structure - Wish List
    Replies: 0
    Last Post: 2006-08-26, 03:21 PM
  5. Find / Replace Text
    By Eric Stewart in forum Revit Architecture - Wish List
    Replies: 2
    Last Post: 2006-04-12, 03:43 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
  •