Assembly Traversal, how to delete duplicates?

Discussion in 'SolidWorks' started by SW Monkey, Nov 9, 2006.

  1. SW Monkey

    SW Monkey Guest

    I am using the Assembly Traversal function in my macro to go thru the
    current assembly, grap the Item & Description custom property, and
    export that into a .TXT file. If I have the same part multiple times
    in an assemlby or subassemlby, the part is in the TXT file multiple
    times.

    Anyone know how I can prevent these duplicates? I am not trying to
    keep track of the QTY, so this isnt needed.
     
    SW Monkey, Nov 9, 2006
    #1
  2. SW Monkey

    TOP Guest

    The easiest thing is to run a gawk script on the text file after you
    create it.
     
    TOP, Nov 9, 2006
    #2
  3. SW Monkey

    SW Monkey Guest


    Whats a gawk script?
     
    SW Monkey, Nov 9, 2006
    #3
  4. SW Monkey

    SW Monkey Guest

    Nevermind, just did some research.

    Do you have a AWK script to do this?
     
    SW Monkey, Nov 9, 2006
    #4
  5. SW Monkey

    TOP Guest

    Yes.

    # remove duplicate, consecutive lines (emulates "uniq")
    awk 'a !~ $0; {a=$0}'

    # remove duplicate, nonconsecutive lines
    awk '! a[$0]++' # most concise script
    awk '!($0 in a) {a[$0];print}' # most efficient script

    http://www.student.northpark.edu/pemente/awk/awk1line.txt

    You would have to do some tweaking because you probably want to remove
    based on a field in the record. Pretty straightforward, NOT.

    Another way if you have Access is to read in the text file and run a
    query such as

    SELECT DISTINCT * FROM yourfile;

    You enter this in SQL view, it is much easier than trying to figure out
    MSoft's way.
     
    TOP, Nov 10, 2006
    #5
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.