Layer and Style Translator

Discussion in 'AutoCAD' started by Doug Broad, Apr 21, 2004.

  1. Doug Broad

    Doug Broad Guest

    Sorry, Hit the reply button instead of the new post button.

    Anyone got a layer and style translator.

    I'm looking at a drawing that obviously originated with
    a number of xrefs that were bound. Most of the layer names,
    dimension styles, and text styles are long:

    Example: ####.01-MP-PHASE1$0$1-A-96-COLU

    I'm looking to eliminate all characters prior to $#$#- and
    merge objects on those layers with any layer already existing
    in the drawing with the same name.

    Am starting to code now, but would be glad to avoid
    the necessity. Of course, if anyone can point me to a
    built-in translator that would be great also. Thanks.

    Preliminary pseudo code:

    (defun translate (property collection / name ... )
    ;;given a collection object, rename or move objects
    ;;from one name to another.

    ;;1. For each element in collection

    ;;a. Get the name

    ;;b. Get the name without the prefix.

    ;;c. If the name is different, then

    ;;c1. check if an item in the collection exists
    ;;with that name.

    ;;C1A. If an item exists add an association
    ;;to a translation schedule.

    ;;C1B Otherwise rename the item.

    ;;2. If a translation schedule exists,

    ;;2A.Parse the entire drawing and make
    ;;the property substitution to each object.

    ;;2B.Delete the old collection items in
    ;;the translation schedule.

    )


    (defun findxrprefix (name)
    ;;given a name that may contain an xref and wildcard
    ;;number string, return the xref prefix code.

    )

    (defun deleteprefix (name prefix)
    ;;given a string, eliminate the prefix if it
    ;;exists and return the rest.

    )

    (defun reassignobjects(propertyname schedule)
    ;;Foreach object in drawing translate the
    ;;property according to the schedule.

    )

    (defun c:translate ()
    ;;Foreach item in translation list,
    ;;translate

    )



    Regards,

    Doug
     
    Doug Broad, Apr 21, 2004
    #1
  2. Doug Broad

    Doug Broad Guest

    Got it. Thanks anyway.
     
    Doug Broad, Apr 21, 2004
    #2
  3. Doug Broad

    Joe Burke Guest

    Doug,

    Just curious, did you consider using CAD Standards? Given one or a few drawings in
    the state you mentioned, I'd try this before code.

    Save As .dws and delete all graphic objects.
    Purge all layers and styles you want to get rid of. Keeping those you want to retain.
    Apply the new .dws file to the original file(s).

    Joe Burke
     
    Joe Burke, Apr 21, 2004
    #3
  4. Doug Broad

    Doug Broad Guest

    Hi Joe,
    I thought of that and tried to experiment last night but
    it didn't seem to do what I wanted ( to rename layers
    by eliminating the xrefname and wildcard prefix.

    The style and layer names were so long that they didn't
    fit in any of the dialog windows. Thanks for the
    suggestion though.

    The bulk of my coding is done. Within an hour,
    I had a working version that fixed my immediate
    problems.

    I thought that there must have been some sort of
    layer and style translator either built in. Surprised
    to see there wasn't.

    Regards,

    Doug
     
    Doug Broad, Apr 21, 2004
    #4
  5. Doug Broad

    Mark Propst Guest

    so how ya comin with those fries?
    :)

     
    Mark Propst, Apr 21, 2004
    #5
  6. Doug Broad

    Doug Broad Guest

    Jes caint get no servus roun heah. Good
    thang my wife packed me lunch today. ;-)
     
    Doug Broad, Apr 21, 2004
    #6
  7. Doug Broad

    Steve Doman Guest

    Doug,

    I remember reading somewhere on the Internet about running the Express Tool
    LayTrans via a lisp function, since there is no longer a command line
    version.

    Assuming you have Express tools available...

    (arxload "laytrans")
    (acet-laytrans <transfilename> <bit>)

    Where the transfilename is the name of a layer mapping file previously
    created using the LayTrans dialogue. The bit controls translation behavior
    corresponding to the dialogues "settings".

    I think I saw this info from a Google search of this NG. Might have been a
    post from Jimmy B.

    Haven't tried the above however. Its probably to late to help you, but
    somebody else might benefit.

    Regards,
    Steve Doman
     
    Steve Doman, Apr 21, 2004
    #7
  8. Doug Broad

    Doug Broad Guest

    Steve,

    Thanks. Couldn't find that anywhere. That looks pretty good, certainly
    better than rename. After playing around with it, however, I think the
    program I just created may be better for the kind of changes I wanted to
    automate (eliminating the xref filename prefixes).

    Thanks again for bringing that to my attention.

    Regards,
    Doug
     
    Doug Broad, Apr 21, 2004
    #8
  9. Hi Doug, sorry to pitch in late ...

    If yours is a case of stripping xref bind prefixes perhaps
    the followng, which I quickly penned for another poster,
    may have the odd snip you can use ... I think it works :)

    Code:
    (defun c:BindFix15
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  BindFix15.lsp (AutoCAD 2000+)
    ;
    ;  Copyright 2003 · Michael Puckett · All Rights Reserved
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (  /
    ;  local defuns
    __GetTableEntries
    __RenameTableEntry
    __RenameTableEntryViaObjname
    __RenameTableEntryViaActiveX
    __StripBindingArtifacts
    __GetUniqueTableEntryName
    ;  local vars
    doc
    newname
    )
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  local defun __GetTableEntries
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (defun __GetTableEntries ( table / data result )
    (while (setq data (tblnext table (null data)))
    (setq result
    (cons (cdr (assoc 2 data)) result)
    )
    )
    result
    )
    
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  local defun __RenameTableEntry
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (defun __RenameTableEntry ( doc table oldname newname / data )
    ;  wrapper for __RenameTableEntryViaObjname
    ;  and __RenameTableEntryViaActiveX functions
    (setq table
    (cond
    ((eq (setq table (strcase table t)) "ltype") "linetype")
    (t table)
    )
    )
    (if (member table '("style" "dimstyle"))
    ;  autodesk made textstyles and dimstyles read-only to
    ;  the automation model w/regards to the symbol name, why?
    (__RenameTableEntryViaObjname table oldname newname)
    (__RenameTableEntryViaActiveX doc table oldname newname)
    )
    )
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  local defun __RenameTableEntryViaObjname
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (defun __RenameTableEntryViaObjname ( table oldname newname / data )
    ;  calling function responsible for
    ;  ensuring appropriate data passed
    (entmod
    (subst
    (cons 2 newname)
    (assoc 2 (setq data (entget (tblobjname table oldname))))
    data
    )
    )
    )
    
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  local defun __RenameTableEntryViaActiveX
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (defun __RenameTableEntryViaActiveX ( doc table oldname newname / data )
    ;  calling function responsible for
    ;  ensuring appropriate data passed
    (vla-put-name
    (vla-item
    (eval
    (list
    (read (strcat "vla-get-" table "s"))
    doc
    )
    )
    oldname
    )
    newname
    )
    ;  if you wanted this to be more robust
    ;  you could use the following ...
    ;
    ;  (vl-catch-all-apply
    ;     (function
    ;        (lambda ()
    ;           (vla-put-name ...)
    ;        )
    ;     )
    ;  )
    ;
    ;  I chose to pass valid data instead
    )
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  local defun __StripBindingArtifacts
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (defun __StripBindingArtifacts ( entry / i done )
    (cond
    (  (wcmatch entry "*`$#`$*")
    (setq i 0 ceiling (strlen entry))
    (while (and (not done) (< i ceiling))
    (if (wcmatch (substr entry (setq i (1+ i)) 3) "`$#`$*")
    (setq
    entry (substr entry (+ i 3))
    done  t
    )
    )
    )
    )
    )
    entry
    )
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  local defun __GetUniqueTableEntryName
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (defun __GetUniqueTableEntryName ( table entry )
    (cond
    (  (tblsearch table entry)
    (setq i 1)
    (while
    (tblsearch table
    (strcat entry "_" (itoa (setq i (1+ i))))
    )
    )
    (strcat entry "_" (itoa i))
    )
    (  t entry  )
    )
    )
    
    ;//////////////////////////////////////////////////////////////////////
    ;
    ;  "main"
    ;
    ;//////////////////////////////////////////////////////////////////////
    
    (cond
    
    (  (< 14 (atoi (getvar "acadver")))
    
    (vl-load-com)
    
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    
    (foreach table '("block" "dimstyle" "layer" "ltype" "style")
    (foreach entry (reverse (__GetTableEntries table))
    (cond
    (  (wcmatch entry "*`$#`$*")
    (__RenameTableEntry
    doc
    table
    entry
    (setq newname
    (__GetUniqueTableEntryName table
    (__StripBindingArtifacts entry)
    )
    )
    )
    (princ
    (strcat "\n"
    (if (tblsearch table newname)
    (strcat
    "Renamed "
    table " "
    entry " => "
    newname "."
    )
    (strcat
    "Could not rename "
    table " "
    entry "."
    )
    )
    )
    )
    )
    )
    )
    )
    )
    
    (  t (princ "\nSorry, penned for AutoCAD 2000+."))
    
    )
    
    (princ)
    
    )
    
    Cheers :)
     
    michael puckett, Apr 21, 2004
    #9
  10. Doug Broad

    Joe Burke Guest

    Hi Doug,

    Just an aside. I used CAD Standards often. "Fixing" drawings has become a major part
    of my business... unfortunately. Using Standards is tedious at best, but it usually
    does the job quite well. Of course I've done what you did too. I find a coded
    solution is better/faster when there's more than a few drawings.

    Joe Burke
     
    Joe Burke, Apr 22, 2004
    #10
  11. Doug Broad

    Doug Broad Guest

    Joe,

    Can you explain how you use CAD standards? Is it an entirely
    manual process or can it be automated (taught) to do the
    conversion?

    In what kind of situations do you use CAD standards?

    Thanks
     
    Doug Broad, Apr 22, 2004
    #11
  12. Doug Broad

    Doug Broad Guest

    Thanks a bunch Michael. Looks great.
    I'm going to try it out and compare. Sorry for the delay
    in replying. I stayed up most of the night last night
    to get a project out (10 D sheets of casework details
    in 1 week) Ooof. I was pooped. Might have
    some comments for you when the work hangover
    clears.

    Regards,
    Doug

     
    Doug Broad, Apr 22, 2004
    #12
  13. Doug Broad

    Steve Doman Guest

    Doug,

    Just for completeness, I found the info which I was referring to. It
    was a post from Tom Stoeckel of AutoDesk which I have pasted below.

    [Btw, I draw architectural millwork (casement details, paneling,
    casework, etc.) all the time. That's me, Mr. Detail.]

    Regards,
    Steve Doman

    -----

    Reply From: Stoeckel, Tom A.
    Date: Dec/19/01 - 23:08 (GMT)
    Re:

    There isn't a command line version, per se, but there is an exposed LISP
    function to do what you want. It was exposed as a LISP function rather
    than a regular command for simplicity and to consolidate the operation
    to a one line call. The use of the LISP function requires that you have
    already created and saved a layer translation mapping using the dialog
    version. The syntax is as follows:

    (acet-laytrans <file name> [<bits>])

    <file name> is a required argument. It is the name of a dwg or dws file
    that contains saved layer mappings. This file would need to have been
    created during a manual translation operation with Layer Translator.

    [<bits>] is an optional argument. This is a bit code sum indicating
    which options should be used during translation. These correspond to the
    same options in the Settings dialog in Layer Translator. If the argument
    is not provided, the function uses the Layer Translator dialog's last
    settings. The bits are as follows:

    bit = 1: Force color to Bylayer
    bit = 2: Force linetype to Bylayer
    bit = 4: Translate into blocks
    bit = 8: Write the translation log file

    Examples:

    (acet-laytrans "standard.dws")

    Uses the previously saved file "standard.dws" (which contains layer
    mappings) and the last used options.

    (acet-laytrans "standard.dws" 3)

    Uses the previously saved file "standard.dws" and forces color and
    linetype to BYLAYER.

    (acet-laytrans "standard.dws" 12)

    Uses the previously saved file "standard.dws", forces color and linetype
    to BYLAYER and writes a translation log.
     
    Steve Doman, Apr 22, 2004
    #13
  14. Doug Broad

    Doug Broad Guest

    Steve,

    Thanks. So the first time you run the cadstandards you make a
    map for the layer translation and save that as a dws file. This must
    be done manually. Afterwards, drawings can be made to automatically
    map to the new layers. It doesn't appear to fix arbitrary xrefbind
    prefixes however. :-(

    I do so much casework, millwork, and panelling details that I have
    written a suite of programs to draw the shop drawings semi-automatically.
    How do you create yours?

    Regards,
    Doug


    <snip>
     
    Doug Broad, Apr 22, 2004
    #14
  15. Doug Broad

    Joe Burke Guest

    Doug,

    I'm using A2k2 and some of this is from memory. I don't know if CAD Standards is
    different in later versions, but I doubt it.

    You hit the problem on the head, re: "can it be automated". Not that I know of.
    That's why I said "tedious", and suggested it's only useful given a few drawings to
    convert from one set of standards to another. Example, you've got three drawing to
    convert and all of them need basically the same changes. Doing the first one doesn't
    help with the other two. You have to repeat the entire process with each drawing.

    Here's the rub. That's not the case using Layer Translator. With LT, once you map one
    layer to another, a saved mapping scheme can be applied to subsequent drawings. IOW,
    it learns as you go. As you work through the set of drawings to be "translated", only
    the layers which have not yet been mapped are an issue.

    Now if all of that is true (I hope I have my facts straight...) it's logical to
    wonder why CAD Standards can't do for layers and styles what Layer Translator does.
    Be smart. I already told you this layer should map to that layer. Don't ask me again.
    And since a layer mapping table can be contained in a .dws file, why not also mapping
    tables for text and dimension styles?

    Seems to me CAD Standards is half-baked and could be much better. I imagine if it was
    done right, Layer Translator would go away. CAD Standards would have options,
    translate layers, translate text styles, translate all. Hopefully in the process,
    it's totally ugly interface would go away as well.

    As it stands now, you'd probably be better off running Layer Translator on a set of
    files first. Then run those files through CAD Standards. That way CAD Standards would
    only ask about styles.

    Hope this makes some sense... I'm thoroughly confused. :)

    Joe Burke
     
    Joe Burke, Apr 22, 2004
    #15
  16. Doug Broad

    Joe Burke Guest

    Doug,

    RE:
    No, I don't think so. See my reply below. I suspect you are confusing CAD Standards
    with Layer Translator.

    Hi Steve,

    Always good to see you here. Any thoughts on what I said below? I'm not sure I have
    it right.

    Joe Burke
     
    Joe Burke, Apr 22, 2004
    #16
  17. Doug Broad

    Doug Broad Guest

    Joe,
    Thanks for the comprehensive feedback. Think I'll look into
    the layer translator and try Michael's more generalized truncator.
    I agree with you that the CAD standards program should have
    more options. I haven't used it any myself because I primarily
    work alone and have my own standards, such as they are.
    Architectural Desktop imposes its own standards and so
    the average user doesn't need to worry about layers once they
    understand them. ;-)

    Being able to use an architect's cad drawings to create casework
    drawings beats scaling their prints or scanning their prints. The
    downside is that etransmit, aecobjexplode, and exporttoautocad
    have options that can be overlooked and result in drawings that
    are far more complex than they need to be. A program that
    can simplify such output seems in order. Perhaps Michael's
    already does that. Mine does most of it. I haven't tested it
    long enough to feel good about posting it. You know how that
    is.

    This week has been particularly busy. Our school got hit with
    a new virus that rewrites the hosts file and prevents editing the
    registry and shuts down the virus checkers. It also replicates
    itself across the network to any computer hooked to the network.
    Most of my spare time (at least 12-16 hours) went to squashing
    the virus in my lab. If you check your task manager and you have
    msmscfg.exe running, you have it.

    Thanks again Joe.

    Regards,
    Doug
     
    Doug Broad, Apr 22, 2004
    #17
  18. Doug Broad

    Steve Doman Guest

    Doug,

    Yes you must first create a dws file before running the exposed LayTrans
    function. I have always use the LayTrans *command* to create the dws
    file. But as you pointed out, the new fangled CadStandard app can create
    them too.

    I guess I didn't really understand your goal until now. What I think
    you are trying to do is to clean up the named object mess when a drawing
    that contains Xrefs has had the Xrefs binded, rather then inserted.

    My experience with using LayTrans has been when migrating our drawings
    from our old layer naming convention to our new layer name convention.
    At the time we were running A2ki, and that version of LayTrans came with
    a GUI command and a minus command "-LayTrans", which allowed for scripts.

    For our back-of-house casework, we use an application called MicroVellum
    which runs inside AutoCAD. Works good I'm told, although I've never ran
    it myself. All other millwork is so custom that we just draw it from
    scratch, or modify details from our library.

    Most of my AutoCAd customization has to do with making it easier to find
    reusable details, speed up plotting, and to manage company standards
    such as layer management, dimension and text styles, lineweights, etc.

    Did Michael's code help? I haven't had a chance to try it.

    Steve
     
    Steve Doman, Apr 23, 2004
    #18
  19. Doug Broad

    Steve Doman Guest

    Hi Joe,

    Thanks I hardly have time to reply to the group anymore.

    As for the Cadstandards app, I'm no expert at it. I find that 80% of my
    standardization problems have to do with layers, so the LayTrans command
    fits the bill very well. The other 20% I handle with lisp routines.

    Our company was using A2ki for a long time, which didn't come with the
    Cadstandards app. We have A2k2 presently, so perhaps it's time to take
    another look at CadStandards.

    Keep up the good work.

    Regards,
    Steve Doman
     
    Steve Doman, Apr 23, 2004
    #19
  20. Doug Broad

    Joe Burke Guest

    Doug,

    You're welcome... assuming I got it right.

    There's a reason local firms need more standards translations than is probably common
    on the mainland. It's not at all unusual that projects are designed by mainland firms
    and then handed off to local firms. Typically it happens at the end of Design
    Development. The local firm does construction docs and admin.

    So my client (the local firm) gets a set of drawings that's about 35% complete. The
    whole mess has to be converted to their CAD standards. And since it ain't no fun...
    they dump that job on me. It's not so bad when the design office has reasonably good
    standards, and people follow them. But you know that goes. I often don't see the
    project again afterwards.

    In fact, doing this kind of work is one of the main reasons I wanted to learn what we
    talk about here. I realized some of it was going to be a lot easier if I could make
    my own tools. Steve Doman will recall when I knew next to nothing. It wasn't that
    long ago, three years or so. Still lots more to learn... which makes my work much
    more interesting than it would be otherwise.

    I doubt I would have made it over the initial hump without help from you and others
    here.

    Regards
    Joe
     
    Joe Burke, Apr 23, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.