TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on September 22, 2004, 01:40:15 PM

Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 01:40:15 PM
on mdubs recommendation i have started a new topic. i am trying to run a script to turn on and make a layer non plot. the problem is i have tons of drawings with this layer that i don't have time to find. how can i search for drawings containing a given layer?
Title: find drawings containing layer
Post by: David Bethel on September 22, 2004, 01:48:25 PM
I can do via ZTree with just a regular text search on .dwg files.  The layer name needs to be a unquie non-ACAD term.  -David
Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 01:50:16 PM
the layer is called z-barcode
Title: find drawings containing layer
Post by: M-dub on September 22, 2004, 02:13:48 PM
Dan, just out of curiosity, have you tried Discovery?  Search for z-barcode.
Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 02:22:35 PM
yeah tried nuttin. speakin od discovery mdub i'm messin with it right now. there must be a way to open the autocad drawing from the preview screen but i can't seem to get it. i would get a dialogue box but then i unchecked always ask so now when i try to open it just keeps repeating a file download box and i have to completly close out explorer. tried several ways but no go
Title: find drawings containing layer
Post by: M-dub on September 22, 2004, 02:27:43 PM
Well, those will be hyperlinks to the dwf files that Discovery creates.  That's why I'm trying to find out how to convert hyperlinks to text in the Office Forum.  If we can do that, you could do a search for whatever it is, have it display the list instead of the previews, copy it into Excel and modify it into a script....if you wanted to, but at the very least, you could get your list that way......
Title: find drawings containing layer
Post by: M-dub on September 22, 2004, 02:29:19 PM
It would require some monkeying around with the program and the html to have it open up the actual file in Acad...unfortunately...I tried that long ago...
Title: find drawings containing layer
Post by: Keith™ on September 22, 2004, 02:32:31 PM
It is really irrelevant if the drawing has the layer or not.

Do this ...

Compile a list of all of the drawings you want to "fix" this problem in (if it exists) ...

Use a simple lisp program to test for the existence of this layer, if it exists, turn it on and set it to not plot.

In your script that processes the drawings, simply run the lisp.

Of course I wouldn't bother with doing that unless you are either..
a) sending these out to be plotted
b) plot from a program other than AutoCAD

what I would do is....

In the acaddoc.lsp (on your computer as well as other users) add this:
Code: [Select]

(if (tblsearch "layer" "z-barcode")
 (command "-layer" "ON" "z-barcode" "Thaw" "z-barcode" "P" "N" "z-barcode")
)


You do not need to make it a function unless you want to and then on EVERY drawing you (or others) open it is done for you. No spending time searching for the drawings to "fix" .... noone has to build and run a script, wait for it to run etc... a simple housecleaning routine.
This will also reset it to not plot if a user changes the layer setting while editing.
Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 02:38:31 PM
good idea keith but if i go mokeyin with others system files they start to shake. maybe some covert ops are in order good advice. it's mostly ok none it's all just part of my idiot proof brainstorming. whose the idiot for not thinking of all the possibilities....shhhh it's me
Title: find drawings containing layer
Post by: M-dub on September 22, 2004, 02:49:00 PM
Keith to the rescue again...:)
Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 03:42:52 PM
ok did a search and found about 200 possible drawings containing layer. opened them in batches and with a little help the layer appeared and i saved it. so i would consider your idea a success keith thank you very much  :wink:
Title: find drawings containing layer
Post by: M-dub on September 22, 2004, 03:43:57 PM
:oops:
Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 03:47:32 PM
see you learn sumpthin new everyday mdub  :wink:
Title: find drawings containing layer
Post by: ronjonp on September 22, 2004, 04:23:35 PM
You also might want to look at ezscript pro for making the script files. Very easy to use, especially if you want to run a lisp in each drawing.

Ron
Title: find drawings containing layer
Post by: ELOQUINTET on September 22, 2004, 04:49:08 PM
ron where you been i was askin about ezscript. downloaded setup ran and nada how does that work?
Title: find drawings containing layer
Post by: Jeff_M on September 22, 2004, 05:47:49 PM
Quote from: Keith

what I would do is....

In the acaddoc.lsp (on your computer as well as other users) add this:
Code: [Select]

(if (tblsearch "layer" "z-barcode")
 (command "-layer" "ON" "z-barcode" "Thaw" "z-barcode" "P" "N" "z-barcode")
)


According to the help file
Quote from: ACAD HELP

If you use the command function in an acad.lsp, acaddoc.lsp or MNL file, it should be called only from within a defun statement. Use the S::STARTUP function to define commands that need to be issued immediately when you begin a drawing session. The S::STARTUP function is described in S::STARTUP Function—Post-Initialization Execution.

I don't recall the specifics as to why they say this, but I believe it had to do with some commands not behaving properly before Acad has completely initialized.
Title: find drawings containing layer
Post by: Keith™ on September 22, 2004, 06:08:38 PM
Hmm... never read that before and I have never had a problem ... but the issue is easily resolved by doing the following ...
Code: [Select]

(if (setq lay (tblobjname "layer" "z-barcode"))
  (progn
    (setq laydata (entget lay))
    (setq templay (subst (cons 62 (abs (cdr (assoc 62 laydata)))) (assoc 62 laydata) laydata))
    (setq templay (subst (cons 70 0) (assoc 70 templay) templay))
    (entmod (subst (cons 290 0) (assoc 290 templay) templay))
  )
)
Title: find drawings containing layer
Post by: ronjonp on September 22, 2004, 08:10:12 PM
Keith,

Code: [Select]
(if (tblsearch "layer" "z-barcode")
 (command "-layer" "ON" "z-barcode" "Thaw" "z-barcode" "P" "N" "z-barcode")
)


How do you make this return a prompt to the command line that layer does not exist?

want something like:

Code: [Select]
(if (tblsearch "layer" "z-barcode")
  (then
    (command "-layer"  "ON"       "z-barcode"  "Thaw"
    "z-barcode"  "P"       "N"    "z-barcode"
   )
    (else
      (prompt "Layer does not exist")
    )
  )
)
Title: find drawings containing layer
Post by: sinc on September 22, 2004, 09:07:16 PM
The "command" function works by running Autocad commands in the current drawing session.  The acad.lsp and acaddoc.lsp routines are run BEFORE the Autocad drawing session is initialized, so there is no Autocad session to run the Autocad command in.  Therefore, "command" won't work.

When the drawing session finishes initializing, the first thing it does is run the "S::STARTUP" function.  Therefore, if you want to do something at startup that uses the "command" function, you need to add it to this function.
Title: find drawings containing layer
Post by: Keith™ on September 22, 2004, 09:13:32 PM
You re soooo... close ....

Code: [Select]
(if (tblsearch "layer" "z-barcode")
    (command "-layer" "ON" "z-barcode" "Thaw" "z-barcode" "P" "N" "z-barcode" "")
    (prompt "Layer does not exist")
)


Using the second version without the command call...

Code: [Select]
(if (setq lay (tblobjname "layer" "z-barcode"))
  (progn
    (setq laydata (entget lay))
    (setq templay (subst (cons 62 (abs (cdr (assoc 62 laydata)))) (assoc 62 laydata) laydata))
    (setq templay (subst (cons 70 0) (assoc 70 templay) templay))
    (entmod (subst (cons 290 0) (assoc 290 templay) templay))
  )
  (prompt "Layer does not exist")
)



VLisp version ...

Code: [Select]
(setq *acad* (vlax-get-acad-object)
      *doc* (vla-get-activedocument *acad*)
      *layers* (vla-get-layers *doc*)
      found nil
)
(vlax-for *layer* *layers*
  (if (= (vla-get-Name *layer*) "0")
    (progn
      (vla-put-layeron *layer* :vlax-true)
      (vla-put-freeze *layer* :vlax-false)
      (vla-put-Lock *layer* :vlax-false)
      (vla-put-plottable *layer* :vlax-false)
      (setq found T)
    )
  )
)
(if (not found)
  (prompt "Layer does not exist")
)
Title: find drawings containing layer
Post by: Keith™ on September 22, 2004, 09:39:20 PM
Quote from: sinc
The "command" function works by running Autocad commands in the current drawing session.  The acad.lsp and acaddoc.lsp routines are run BEFORE the Autocad drawing session is initialized, so there is no Autocad session to run the Autocad command in.  Therefore, "command" won't work.

When the drawing session finishes initializing, the first thing it does is run the "S::STARTUP" function.  Therefore, if you want to do something at startup that uses the "command" function, you need to add it to this function.


I tested the above scenario on A2k4 ... the results are:

Quote from: AutoCAD 2004 Command Line
Regenerating model.

AutoCAD Express Tools Copyright © 2002-2003 Autodesk, Inc.

ACAD2004.LSP loaded
ACAD2004DOC.LSP loaded
ACADDOC.LSP loaded
-layer
Current layer:  "0"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
ON
Enter name list of layer(s) to turn on: 0 Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
Thaw
Enter name list of layer(s) to thaw: 0 Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
P
Enter a plotting preference [Plot/No plot] <Plot>: N
Enter layer name(s) for this plot preference <0>: 0 Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
AutoCAD menu utilities loaded.
ACAD.LSP loaded


Note the order in which the files are loaded .....

AutoCAD Express Tools
ACAD2004.LSP
ACAD2004DOC.LSP
ACADDOC.LSP
ACAD.MNL
ACAD.LSP

Also note that the command called in ACADDOC.LSP executed without fault and also note that modelspace was regenerated before any of these modules loaded. To me that indicates a readiness to accept commands.

As I said... I have used that scenario for many years, probably since R10, of course we only used ACAD.LSP until R14, but I have experienced no negative problems.
Title: find drawings containing layer
Post by: ronjonp on September 23, 2004, 10:27:07 AM
Thanks Keith  :D . I wish I could learn this stuff. I spent about 45 minutes yesterday trying different variations :?