Author Topic: find drawings containing layer  (Read 6961 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
find drawings containing layer
« Reply #15 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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
find drawings containing layer
« Reply #16 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))
  )
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7529
find drawings containing layer
« Reply #17 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")
    )
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

sinc

  • Guest
find drawings containing layer
« Reply #18 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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
find drawings containing layer
« Reply #19 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")
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
find drawings containing layer
« Reply #20 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7529
find drawings containing layer
« Reply #21 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 :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC