Author Topic: How to develop this lisp to avoid Xref layers?  (Read 384 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1204
How to develop this lisp to avoid Xref layers?
« on: September 27, 2017, 05:11:54 am »
This lispd draws a line and a text with layer name and description for each layer

I am wondering, How to avoid layers for XREFs to apply
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LLD () (c:LayerLegend))
  2.  
  3. (defun c:LayerLegend ( / df i ln p1 pt sp ) ;; Lee Mac 2011
  4.  (if
  5.    (and
  6.      (setq pt (getpoint "\nSpecify Point for Legend: "))
  7.      (setq ln (* 100 (getvar 'TEXTSIZE))) ;(getdist  "\nSpecify Length of Lines: " pt))
  8.      (setq pt (trans pt 1 0))
  9.      (setq i -1)
  10.      (setq sp (* 1.5 (getvar 'TEXTSIZE)))
  11.    )
  12.    (while (setq df (tblnext "LAYER" (null df)))
  13.      (setq ent (vlax-ename->vla-object (tblobjname "LAYER" (cdr (assoc 2 df)))))
  14.      (setq dsc (vlax-get-property ent 'Description))
  15.      (setq nm  (vlax-get-property ent 'name))
  16.      (entmakex (list
  17.  (cons 0 "LINE")
  18.  (cons 8 (cdr (assoc 2 df)))
  19.  (cons 6 "ByLayer")
  20.  (cons 62 256)
  21.  (cons 10
  22. (setq p1 (polar pt (* 1.5 pi) (* (setq i (1+ i)) sp)))
  23. )
  24.  (cons 11 (polar p1 0. ln))
  25.  (cons 370 -1)
  26.  )
  27. )
  28.  
  29.      (entmakex (list (cons 0 "TEXT") ;***
  30.                 (cons 1 (strcat (cdr (assoc 2 df)) " : " dsc)) ;* (the string itself)
  31.                 (cons 6 "BYLAYER") ; Linetype name
  32.                 (cons 7 (getvar 'TEXTSTYLE)) ;* Text style name, defaults to STANDARD, not current
  33.                 (cons 8 (cdr (assoc 2 df))) ; layer
  34.                 (cons 10 p1) ;* First alignment point (in OCS)
  35.                 (cons 11 p1) ;* Second alignment point (in OCS)
  36.                 (cons 39 0.0) ; Thickness (optional; default = 0)
  37.                 (cons 40 (getvar 'TEXTSIZE)) ;* Text height
  38.                 (cons 41 1.0) ; Relative X scale factor, Width Factor, defaults to 1.0
  39.                 (cons 62 256) ; color
  40.                 (cons 71 0) ; Text generation flags
  41.                 (cons 72 0) ; Horizontal text justification type
  42.                 (cons 73 1) ; Vertical text justification type
  43.                 (cons 210 (list 0.0 0.0 1.0))
  44. (cons 370 -1)
  45.      ))      
  46.      )    )
  47.  (princ)
  48.  )
« Last Edit: September 27, 2017, 06:55:20 am by HasanCAD »

Grrr1337

  • Bull Frog
  • Posts: 447
Re: How to develop this lit to avoid Xref layers?
« Reply #1 on: September 27, 2017, 06:00:25 am »
Like this, I guess:
Code - Auto/Visual Lisp: [Select]
  1. (defun GetNonXrefLayers ( / d L )
  2.  (while (setq d (tblnext "LAYER" (not d)))
  3.    (and
  4.      (/= 16 (logand 16 (cdr (assoc 70 d))))
  5.      (setq L (cons (cdr (assoc 2 d)) L))
  6.    )
  7.  )
  8.  L
  9. ); defun GetNonXrefLayers

HasanCAD

  • Swamp Rat
  • Posts: 1204
Re: How to develop this lisp to avoid Xref layers?
« Reply #2 on: September 27, 2017, 09:27:25 am »
Thanks Grrr1337
Working perfict

Grrr1337

  • Bull Frog
  • Posts: 447
Re: How to develop this lisp to avoid Xref layers?
« Reply #3 on: September 27, 2017, 10:18:56 am »
Thanks Grrr1337
Working perfict

No problem, I'm glad this helped. :)

cmwade77

  • Swamp Rat
  • Posts: 1034
Re: How to develop this lit to avoid Xref layers?
« Reply #4 on: October 02, 2017, 07:51:01 pm »
Like this, I guess:
Code - Auto/Visual Lisp: [Select]
  1. (defun GetNonXrefLayers ( / d L )
  2.  (while (setq d (tblnext "LAYER" (not d)))
  3.    (and
  4.      (/= 16 (logand 16 (cdr (assoc 70 d))))
  5.      (setq L (cons (cdr (assoc 2 d)) L))
  6.    )
  7.  )
  8.  L
  9. ); defun GetNonXrefLayers

Much more elegant than what I as going to suggest, my suggestion was going to be to see if the layername has | in it, if it does, it is an xRef layer since you can't add that character yourself to layer names.

Grrr1337

  • Bull Frog
  • Posts: 447
Re: How to develop this lisp to avoid Xref layers?
« Reply #5 on: October 02, 2017, 08:19:33 pm »
Yeah, the other option would be:

Code - Auto/Visual Lisp: [Select]
  1. (wcmatch (cdr (assoc 2 d)) "~*|*")

HasanCAD

  • Swamp Rat
  • Posts: 1204
Re: How to develop this lisp to avoid Xref layers?
« Reply #6 on: October 03, 2017, 10:47:08 am »
Thanks Grrr1337

Both solutions working very well

Grrr1337

  • Bull Frog
  • Posts: 447
Re: How to develop this lisp to avoid Xref layers?
« Reply #7 on: October 03, 2017, 04:41:02 pm »
Thanks Grrr1337

Both solutions working very well

No problem. I've got null experience when dealing with xref layers, so I'm happy to learn something new by a little practice.

Much more elegant than what I as going to suggest, my suggestion was going to be to see if the layername has | in it, if it does, it is an xRef layer since you can't add that character yourself to layer names.

I guess that the name wcmatching approach is rarely used because...

Code: [Select]
_$ (vla-Add (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) "MyNew|Layer")
#<VLA-OBJECT IAcadLayer 00000093e05a3198>

One could add programatically layer with a "xref" name.

roy_043

  • Water Moccasin
  • Posts: 1513
  • BricsCAD 16
Re: How to develop this lisp to avoid Xref layers?
« Reply #8 on: October 04, 2017, 11:25:40 am »
@Grrr1337: In BricsCAD the _Audit command will fix such faulty names.

ronjonp

  • Needs a day job
  • Posts: 6430
Re: How to develop this lisp to avoid Xref layers?
« Reply #9 on: October 04, 2017, 11:40:53 am »
@Grrr1337: In BricsCAD the _Audit command will fix such faulty names.
Same in AutoCAD:
Quote
Command: AUDIT
Fix any errors detected? [Yes/No] <N>: y
Auditing Header
Auditing Tables
Auditing Entities Pass 1
Pass 1 200     objects audited
Non XREF-dependent record "Test|Test" contains vertical bar.
  Changed to "AUDIT_I_171004093954-0".


Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC

Grrr1337

  • Bull Frog
  • Posts: 447
Re: How to develop this lisp to avoid Xref layers?
« Reply #10 on: October 04, 2017, 01:38:17 pm »
Thanks guys, I was not aware that AUDIT does that.