Author Topic: Xref block  (Read 3598 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Xref block
« on: December 19, 2013, 02:55:56 AM »
Hello guys .

Is there a way to not select Xref blocks with the ssget function ?

Code: [Select]
(setq bks (ssget '((0 . "INSERT")))) ;
Thanks in advance  :-)

kruuger

  • Swamp Rat
  • Posts: 633
Re: Xref block
« Reply #1 on: December 19, 2013, 04:01:18 AM »
Hello guys .

Is there a way to not select Xref blocks with the ssget function ?

Code: [Select]
(setq bks (ssget '((0 . "INSERT")))) ;
Thanks in advance  :)
yes. you need to create BlockNameFilter function:
Code: [Select]
(ssget (list (cons 0 "INSERT") (cd:009_BlockNameFilter)))
Code: [Select]
(defun cd:009_BlockNameFilter ()
  (cons 2 (strcat "`*U*," (cd:STR_ReParse (cd:SYS_CollList "BLOCK" (+ 2 4) ",")))
)
it is a part of this program:
http://cad.pl/ftp/Tools/009_RedefineBlockProperties/RedefineBlockProperties.lsp


library functions are here (CadPack.lsp):
http://forum.cad.pl/cadpl-pack-v1-lsp-t78161.html
kruuger

Coder

  • Swamp Rat
  • Posts: 827
Re: Xref block
« Reply #2 on: December 19, 2013, 07:57:18 AM »
Thank you kruuger for your help .

I lost with all these options that you posted  :embarrassed:

Can you please clarify ?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Xref block
« Reply #3 on: December 19, 2013, 08:43:34 AM »
Try this:
Code: [Select]
(defun _foo (/ b fltr)
  (setq fltr "")
  (while (setq b (tblnext "block" (not b)))
    (and (assoc 1 b) (setq fltr (strcat "~" (cdr (assoc 2 b)) "," fltr)))
  )
  (if (zerop (strlen fltr))
    "*"
    fltr
  )
)
(setq bks (ssget "_X" (list '(0 . "INSERT") (cons 2 (_foo)))))
« Last Edit: December 19, 2013, 09:26:19 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Xref block
« Reply #4 on: December 19, 2013, 09:08:13 AM »
Maybe this :

Code: [Select]
(defun c:ss~xref ( / ss adoc blks l )
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq blks (vla-get-blocks adoc))
  (vlax-for item blks
    (if (eq (vla-get-isxref item) :vlax-true)
      (progn
        (setq l (cons (list item (vl-catch-all-apply 'vla-get-xrefdatabase (list item))) l))
        (vla-unload item)
      )
    )
  )
  (setq ss (ssget '((0 . "INSERT"))))
  (foreach item l
    (if (eq (type (cadr item)) 'vla-object)
      (vla-reload (car item))
    )
  )
  (sssetfirst nil ss)
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kruuger

  • Swamp Rat
  • Posts: 633
Re: Xref block
« Reply #5 on: December 19, 2013, 09:20:00 AM »
Thank you kruuger for your help .

I lost with all these options that you posted  :oops:

Can you please clarify ?

if BL1, BL2, BL3 (xref), BL4, BL5 (xref) are dwg blocks
you need to go thru all all of them - omit xref's - and create string:
Code: [Select]
"BL1,BL2,BL4"and this one pass to ssget
Code: [Select]
(ssget (list (cons 0 "INSERT") (cons 2 "BL1,BL2,BL4")))k.

Coder

  • Swamp Rat
  • Posts: 827
Re: Xref block
« Reply #6 on: December 20, 2013, 04:06:53 AM »
Hello guys .

ron your codes didn't work .  :-(
ribarm your codes unloaded one xref only to allow me to select blocks but the other xrefblocks didn't unloaded and they included with the selection .

kruuger , your guide is ok and I hope I can make it .

Many thanks

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Xref block
« Reply #7 on: December 20, 2013, 08:29:21 AM »
This seems to work:
Code: [Select]
(defun _foo (/ b fltr)
  (setq fltr "")
  (while (setq b (tblnext "block" (not b)))
    (and (assoc 1 b) (setq fltr (strcat (cdr (assoc 2 b)) "," fltr)))
  )
    fltr
)
(setq bks (ssget "_X" (list '(0 . "INSERT") '(-4 . "<NOT") (cons 2 (_foo)) '(-4 . "NOT>"))))
« Last Edit: December 21, 2013, 08:28:39 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Xref block
« Reply #8 on: December 20, 2013, 09:02:19 AM »
ribarm your codes unloaded one xref only to allow me to select blocks but the other xrefblocks didn't unloaded and they included with the selection .

I didn't notice that CAD won't unload all attached Xrefs, only what I thought was the issue was how to reload them back as previous state was... Here is my slight improvement ab that... On my CAD it unloads all Xrefs... But if it doesn't try my second code from this post...

Code: [Select]
(defun c:ss~xref ( / ss adoc blks )
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark adoc)
  (setq blks (vla-get-blocks adoc))
  (vlax-for item blks
    (if (eq (vla-get-isxref item) :vlax-true)
      (vla-unload item)
    )
  )
  (setq ss (ssget '((0 . "INSERT"))))
  (command "_.undo" "")
  (sssetfirst nil ss)
  (princ)
)

Code: [Select]
(defun c:ss~xref ( / ss adoc )
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark adoc)
  (command "_.-xref" "u" "*")
  (setq ss (ssget '((0 . "INSERT"))))
  (command "_.undo" "")
  (sssetfirst nil ss)
  (princ)
)
« Last Edit: December 20, 2013, 09:08:02 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Xref block
« Reply #9 on: December 20, 2013, 07:03:02 PM »
I would follow a similar route to Ron, but would probably write it like this:

Code - Auto/Visual Lisp: [Select]
  1. (
  2.     (lambda ( / a b )
  3.         (while (setq a (tblnext "block" (null a)))
  4.             (if (= 4 (logand 4 (cdr (assoc 70 a))))
  5.                 (setq b (vl-list* "," (cdr (assoc 2 a)) b))
  6.             )
  7.         )
  8.         (ssget "_X"
  9.             (cons '(0 . "INSERT")
  10.                 (if b
  11.                     (list
  12.                        '(-4 . "<NOT")
  13.                         (cons 2 (apply 'strcat (cdr b)))
  14.                        '(-4 . "NOT>")
  15.                     )
  16.                 )
  17.             )
  18.         )
  19.     )
  20. )

Ron, note that your code will not select anything if there are no xrefs present in the drawing  :wink:

Coder

  • Swamp Rat
  • Posts: 827
Re: Xref block
« Reply #10 on: December 21, 2013, 08:02:56 AM »
the last three posts work as i wanted , thank you all for your great help .  :-)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Xref block
« Reply #11 on: December 21, 2013, 08:26:38 AM »
I would follow a similar route to Ron, but would probably write it like this:

Code - Auto/Visual Lisp: [Select]
  1. (
  2.     (lambda ( / a b )
  3.         (while (setq a (tblnext "block" (null a)))
  4.             (if (= 4 (logand 4 (cdr (assoc 70 a))))
  5.                 (setq b (vl-list* "," (cdr (assoc 2 a)) b))
  6.             )
  7.         )
  8.         (ssget "_X"
  9.             (cons '(0 . "INSERT")
  10.                 (if b
  11.                     (list
  12.                        '(-4 . "<NOT")
  13.                         (cons 2 (apply 'strcat (cdr b)))
  14.                        '(-4 . "NOT>")
  15.                     )
  16.                 )
  17.             )
  18.         )
  19.     )
  20. )

Ron, note that your code will not select anything if there are no xrefs present in the drawing  ;)


I see that now  :oops:   **Fixed  :D


..  I wonder why the ~name1,~name2 filter would not work?
« Last Edit: December 21, 2013, 08:44:15 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Xref block
« Reply #12 on: December 21, 2013, 11:50:08 AM »
I wonder why the ~name1,~name2 filter would not work?

The pattern argument for wcmatching (I believe the underpinning for ssget filtering) functions akin to an 'OR', not an 'AND'.

For example, if you had inserts by the names of "A", "B" and "C" (ssget "x" '((0 . "insert")(2 . "~A,~B,~C"))) would actually select them all (because "A" matches "~B" etc).

In order to achieve what you intended you would have to do something like:

Code - Auto/Visual Lisp: [Select]
  1. (ssget "x"
  2.    '(   (0 . "insert")
  3.         (-4 . "<and")
  4.         (2 . "~A")
  5.         (2 . "~B")
  6.         (2 . "~C")
  7.         (-4 . "and>")
  8.     )
  9. )

Thus, given a variable xref_names that's self describing:

(interactive)
Code - Auto/Visual Lisp: [Select]
  1.     (append
  2.        '((0 . "insert")(-4 . "<and"))
  3.         (mapcar (function (lambda (x) (cons 2 (strcat "~" x)))) xref_names)
  4.        '((-4 . "and>"))
  5.     )
  6. )

(non-interactive)
Code - Auto/Visual Lisp: [Select]
  1. (ssget "x"
  2.     (append
  3.        '((0 . "insert")(-4 . "<and"))
  4.         (mapcar (function (lambda (x) (cons 2 (strcat "~" x)))) xref_names)
  5.        '((-4 . "and>"))
  6.     )
  7. )

Of course, only applicable if xrefs are actually present in the drawing, in the interests of brevity <something I'm not usually known for> that (pre)determination not detailed here.

All that said, the (-4 . "<not") ... (-4 . "not>") alternative Lee detailed would be the route I'd suggest -- just thought I'd respond to your "wonder why ..." musing.

Cheers. :)
« Last Edit: December 21, 2013, 12:14:23 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst