See the top rated post in this thread. Click here

Page 1 of 4 1234 LastLast
Results 1 to 10 of 32

Thread: Replace the .ctb file at the folder level

  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Replace the .ctb file at the folder level

    Hello everyone,

    I looking to see if anyone has a code or can write one that will remove the existing .ctb file from the drawing then replace it with a new one.

    EX. The drawings have xyz.ctb in them I need abc.ctb insert without opening each one and changing the file one at a time.

    So, I would like to go to the folder that has these drawings and the code will go through the folder and any sub folders and remove and replace the .ctb.

    Thanks

    Kyle C.

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Replace the .ctb file at the folder level

    Are you up for doing this yourself?

    You just need to build a set of drawings, iterate this set, opening each drawing, then iterating the layouts within each drawing, modify the StyleSheet property.

    Here is most of what you need, you just need to define how you want to build the list of drawing names and plug them into "lst" as an array of strings.

    Code:
    Public Sub changestylesheets()
       Dim oAxDbDoc As New AxDbDocument
       Dim lst As Variant, dwg As Variant
       lst = Array("C:\Program Files\Autodesk Civil 3D 2006\Sample\lineweights.dwg",
                        "C:\Program Files\Autodesk Civil 3D 2006\Sample\truetype.dwg")
       For Each dwg In lst
          oAxDbDoc.Open dwg
          Dim item As AcadLayout
          For Each item In oAxDbDoc.Layouts
             item.StyleSheet = "Fill Patterns.ctb"
          Next item
          oAxDbDoc.SaveAs dwg
       Next dwg
    End Sub
    I used the code example posted here [ http://jtbworld.blogspot.com/2006/01...ngs-using.html ] for the ObjectDBX stuff.

    Obviously, no error checking - but it's a start for you. One more thing, put your actual CTB file name in there.
    R.K. McSwain | CAD Panacea |

  3. #3
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Replace the .ctb file at the folder level

    rkmcswain,

    you have lost me, I need a little hand holding on this.

    I am only looking to change out the CTB file and what is the lineweights.dwg & truetype.dwg for?

    Quote Originally Posted by rkmcswain
    ....You just need to build a set of drawings, iterate this set, opening each drawing, then iterating the layouts within each drawing, modify the StyleSheet property. <-What do you mean?

    Here is most of what you need, you just need to define how you want to build the list of drawing names and plug them into "lst" as an array of strings.

    Code:
    Public Sub changestylesheets()
    Dim oAxDbDoc As New AxDbDocument
    Dim lst As Variant, dwg As Variant
    lst = Array("C:\Program Files\Autodesk Civil 3D 2006\Sample\lineweights.dwg",
    "C:\Program Files\Autodesk Civil 3D 2006\Sample\truetype.dwg")
    For Each dwg In lst
    oAxDbDoc.Open dwg
    Dim item As AcadLayout
    For Each item In oAxDbDoc.Layouts
    item.StyleSheet = "Fill Patterns.ctb"
    Next item
    oAxDbDoc.SaveAs dwg
    Next dwg
    End Sub
    Kyle C.

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Replace the .ctb file at the folder level

    Quote Originally Posted by kylec_edg
    rkmcswain,

    you have lost me, I need a little hand holding on this.

    I am only looking to change out the CTB file and what is the lineweights.dwg & truetype.dwg for?
    Kyle C.
    In that example, that is the drawings that it will change. You need to put your list of drawings in there as mentioned:

    Quote Originally Posted by rkmcswain
    build the list of drawing names and plug them into "lst" as an array of strings
    "lst" being the variable.

    Sorry, I don't have time to build a complete solution.

    Now that I think of it, the functionality you want may be part of ToolPac 9.0. You might contact the author at [ http://www.dotsoft.com/contact.htm ]. We are still on TP8 which doesn't include it AFAIK.
    R.K. McSwain | CAD Panacea |

  5. #5
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Replace the .ctb file at the folder level

    rkmcswain,

    I looking to do this to over 50 drawings are saying I need to list all 50 drawings in the lisp and then run it?

    Quote Originally Posted by rkmcswain
    In that example, that is the drawings that it will change. You need to put your list of drawings in there as mentioned:



    "lst" being the variable.
    Can't I just use a .scr & .bat file that will open AutoCAD then run the lisp that looks at the .ctb file and changes to the one in the code.

    All I looking to do is change the .ctb file in a large number of drawings.

    Kyle C.

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

    Default Re: Replace the .ctb file at the folder level

    You can do it in a script file. You will still need to have a list of all the drawings to do, as far as I know. Then you can tell it to run the lisp file.

    I don't know anything about bat files. I have never used one. To get your list, here is a simple way.
    Code:
    (setq FilePath (getfiled "" "" "dwg" 4))
    (setq Path (strcat (vl-filename-directory) "\\"))
    (setq DwgList (vl-directory-files "*.dwg" Path 1))

  7. #7
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Replace the .ctb file at the folder level

    Of all the reply so far,

    Where is the part of the code that removes the existing .ctb file and replaces it with a new?

    Kyle C.

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

    Default Re: Replace the .ctb file at the folder level

    Look at RK's response. It is written in vba, but could be translated into Lisp (ActiveX). Go through the help files and see how to write it.

    You step through the layout object, and replace the property StyleSheet.

  9. #9
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Replace the .ctb file at the folder level

    Quote Originally Posted by kylec_edg
    Of all the reply so far,

    Where is the part of the code that removes the existing .ctb file and replaces it with a new?

    Kyle C.
    HINT: The StyleSheet property = the associated CTB file name.....

  10. #10
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    1

    Default Re: Replace the .ctb file at the folder level

    Quote Originally Posted by kylec_edg
    rkmcswain,

    I looking to do this to over 50 drawings are saying I need to list all 50 drawings in the lisp and then run it?
    There is no lisp. That is a VBA subroutine.

    Quote Originally Posted by kylec_edg
    Can't I just use a .scr & .bat file that will open AutoCAD then run the lisp that looks at the .ctb file and changes to the one in the code.
    All I looking to do is change the .ctb file in a large number of drawings.
    If you really want to rewrite everything.
    But 90% of the code you need is in my post.

    As mentioned, that VBA subroutine uses ObjectDBX to open and modify the drawings without using the AutoCAD editor. I have not run any time tests, but I bet it's 20X faster than a script file where AutoCAD actually opens the drawing in the editor.
    R.K. McSwain | CAD Panacea |

Page 1 of 4 1234 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 2015-07-15, 06:38 PM
  2. Replies: 0
    Last Post: 2012-09-20, 04:53 PM
  3. Replies: 0
    Last Post: 2011-05-30, 07:07 AM
  4. copy file folder
    By parkerfeldman in forum AutoLISP
    Replies: 3
    Last Post: 2009-09-02, 04:21 PM
  5. File and Replace text via C#
    By nvphatbk in forum Dot Net API
    Replies: 3
    Last Post: 2008-12-16, 06:23 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
  •