Can anyone help?

Discussion in 'AutoCAD' started by spectrefish, Mar 15, 2005.

  1. spectrefish

    spectrefish Guest

    Does anyone have a lisp that can search a drawing, find all the hidden lines, create a layer called "Hidden" with a color I specify, and place all hidden lines on this layer?

    I know very little about lisp and would appreciate if someone could help me out.

    Thank you very, very, very, much in advance.
     
    spectrefish, Mar 15, 2005
    #1
  2. spectrefish

    Casey Guest

    What do you mean by 'hidden lines'? Lines drawing with a linetype of hidden
    (not bylayer?)

    If so,
    (Defun c:hideit ( / ss usrcolor)
    (setq usrcolor (getint "Color Number:> "))
    (command "layer" "make" "HIDDEN" "")
    (setq ss (ssget "x" '((6 . "HIDDEN"))))
    (command "chprop" ss "" "layer" "HIDDEN" "COLOR" usrcolor "")
    )

    Please note, this will assign a color to the objects, not the layer (which
    is bad practice in my opinion).

    Also note, that if you enter a color number out of the valid range, (up to
    255), it will just error out. Entities will be on the 'hidden' layer, but
    without color assigned. This could be fixed, but I don't have the time at
    this second.
     
    Casey, Mar 15, 2005
    #2
  3. (defun c:LAYHID ()
    (command ".-layer" "make" "HIDDEN" "c" "GREEN" "HIDDEN" "l" "HIDDEN" "HIDDEN" "")
    (setq lst (list '(6 . "HIDDEN") '(6 . "HIDDEN2") '(6 . "HIDDENX2")))
    (foreach x lst
    (setq x (list x))
    (setq ss (ssget "x" x))
    (if (/= ss nil)
    (progn
    (setq ssl (sslength ss))
    (while (> ssl 0)
    (setq eg (entget (ssname ss (1- ssl))))
    (setq eg (subst (cons '8 "HIDDEN") (assoc '8 eg) eg))
    (entmod (subst (cons '6 "BYLAYER") (assoc '6 eg) eg))
    (setq ssl (1- ssl))
    );while
    );progn
    );if
    );foreach
    (princ)
    );defun

    This will change any object that has a Hidden Hidden2 or HiddenX2 linetype to a Hidden layer. To change the color, replace the word GREEN in the second line. I hope it helps.
     
    whitesquirrel44, Mar 15, 2005
    #3
  4. QSELECT would work nicely also...
     
    Paul Richardson, Mar 15, 2005
    #4
  5. spectrefish

    MP Guest

    lines, create a layer called "Hidden" with a color I specify, and place all
    hidden lines on this layer?
    This is just the kind of task that may make you want to learn more about
    lisp.
    And this is just the place to help you learn.

    The problem (and any problem) can be broken down into individual steps to
    help simplify getting to the solution

    Get all lines
    Check each line to see if it is one you're interested in
    If so process the line

    ;Begin basic program
    The first part is easiest
    Simplest way is use filtered selection set (see help for more info)
    to get a selection set of all lines
    (setq linelist(ssget "x" (list(cons 0 "LINE")))

    Now loop through the selection set checking each line in turn
    (setq idx 0)
    (while(setq ent(ssname linelist idx))
    'for each item in sel set, run a function on it to see if it's in your
    problem domain
    (checkThisLine ent)
    (setq idx(1+ idx))'increment counter
    );end while loop
    ;End Basic program

    ;rest is subfunctions used in basic program

    ;subfunction
    (defun CheckThisLine(ent)
    ;See if their linetype property is set to hidden,
    (if
    (isLinetypeHidden ent);function to write - see if ent has hidden
    linetyp property
    ;If so, put in list to process
    (PutInList ent);function to write - put item in your list
    (CheckLayerOfEnt ent);Function to write
    If not, see if set to byLayer,
    If so, see if the layers' linetype is hidden
    If so, put line in list to process
    ;etc etc
    );end if
    );end check this line

    Once you have all the lines in your list to process,

    Make sure the Layer "Hidden" exists
    (MakeHiddenLayer);function to write to checkfor the existance of and create
    if needed
    Make sure it has the characteristics you want(linetype hidden, color
    whatever)

    then just set your lines to that layer and linetype byLayer
    (and while you're at it reset color to byLayer also
    For each line in ListofStuff
    (putLineType lineent acByLayer);function to write to set the linetype of
    the entity
    (putLineColor lineent acByLayer);function to write to set the color of
    the entity
    (putLayer Lineent "Hidden");function to write to set the layer of the
    entity
    Next line

    voila

    now all you have to do is fill in the blanks
    :)
    welcome to lispaholics anonymous
     
    MP, Mar 15, 2005
    #5
  6. spectrefish

    spectrefish Guest

    Thanks whitesquirrel44,

    This one works perfectly! EXCELLENT!!

    Do you know how I can get this to work by loading it into my startup suite? What I mean is I don't want to have to type in LAYHID every time.
     
    spectrefish, Mar 15, 2005
    #6
  7. spectrefish

    Tom Smith Guest

    Sheesh, talk about a convoluted approach to a simple request! :) If I weren't into lisp already, that would put me off it.

    The first solution posted eliminated the rigamarole that you're proposing to introduce -- there's no need to cycle through a selection set looking for a linetype, when you can use ssget filtering from the get-go to eliminate the need.

    The short line (setq ss (ssget "x" '((6 . "HIDDEN")))) accomplishes in one whack what you spend a couple of dozen lines of prose describing. And the simple chprop command call accomplishes all the rest. There's no need to check what an existing property is -- just make it be what you want. There are other ways to accomplish this besides chprop, obviously, but the command call works, and it's simple.

    All that was needed, to make the first suggestion work, was to change the two command calls to more closely suit the request. It's still a 5 line routine, doesn't need to be elaborated upon or made more complicated to do what was requested. If we really wanted to gussy this up, we might check for layer locking, but I wouldn't do that until an actual need arose.

    I understand you're trying to be helpful, but to my eye, this was just too, too much to be of benefit to a beginner. You're lecturing rather than addressing the request. And IMO a good part of it is just unnecessarily confusing, or arguably poor practice, like the superfluous selection set processing, and the idea of creating separate functions to change different properties. If I thought ! needed a home-made property-changing function to use in lieue of the various built-in methods, I'd at least generalize it to handle all properties. But I can't see sending a rookie off on that particular snipe hunt, when a simple call to chprop will do the job at hand.
     
    Tom Smith, Mar 15, 2005
    #7
  8. I don't know if it's a good practice or not but I use my mnl file to auto load lisp routines. I use this because somewhere around R13, R14 or 2000, they changed the way acad.lsp worked. I don't fully understand what they did or why they did it. I have a custom menu for all my lisp routines and in the mnl file of the custom menu I put autoload functions:

    (autoload "LayHid" '("LayHid"))

    This functions loads the LayHid.lsp file anytime you start the LayHid command. I personally wouldn't set it to run the program everytime you start/open a drawing. I can't give a good reason why not, just that I wouldn't.

    However, if you want it to run you could just put the following code in any lisp file that automatically runs when you open a new drawing.

    (load "LayHid.lsp") (c:LayHid)

    You may want to put another posting on this Discussion group to ask that question.
     
    whitesquirrel44, Mar 15, 2005
    #8
  9. spectrefish

    Steve Adams Guest

    Tom,

    Please see my post intended for you up the list about 3 post up.


    --
    Thanks,
    Steve



    weren't into lisp already, that would put me off it.
    to introduce -- there's no need to cycle through a selection set looking for
    a linetype, when you can use ssget filtering from the get-go to eliminate
    the need.
    whack what you spend a couple of dozen lines of prose describing. And the
    simple chprop command call accomplishes all the rest. There's no need to
    check what an existing property is -- just make it be what you want. There
    are other ways to accomplish this besides chprop, obviously, but the command
    call works, and it's simple.
    two command calls to more closely suit the request. It's still a 5 line
    routine, doesn't need to be elaborated upon or made more complicated to do
    what was requested. If we really wanted to gussy this up, we might check
    for layer locking, but I wouldn't do that until an actual need arose.
    too, too much to be of benefit to a beginner. You're lecturing rather than
    addressing the request. And IMO a good part of it is just unnecessarily
    confusing, or arguably poor practice, like the superfluous selection set
    processing, and the idea of creating separate functions to change different
    properties. If I thought ! needed a home-made property-changing function to
    use in lieue of the various built-in methods, I'd at least generalize it to
    handle all properties. But I can't see sending a rookie off on that
    particular snipe hunt, when a simple call to chprop will do the job at hand.
     
    Steve Adams, Mar 17, 2005
    #9
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.