Author Topic: Need fresh eyes to check this part of code  (Read 2243 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Need fresh eyes to check this part of code
« on: December 22, 2014, 10:55:37 AM »
I want to place all Xrefs on layer 0
Ehy is this not working
Code: [Select]
(setq XrefTrgtLyr "0")
(vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (if (= :vlax-true (vla-get-isxref blk))
    (progn
      (setq blkLyr (vla-get-layer blk))
      (if (= :vlax-true (vla-get-lock blkLyr))
(progn
  (vla-put-lock blkLyr :vlax-false)
  (vla-put-layer blk XrefTrgtLyr)
  (vla-put-lock blkLyr :vlax-true)
  )
(vla-put-layer blk XrefTrgtLyr)
)
      )
    )
  )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Need fresh eyes to check this part of code
« Reply #1 on: December 22, 2014, 11:08:58 AM »
One issue 'blkLyr' is a string and you're checking if it's locked?
Code: [Select]
(= :vlax-true (vla-get-lock blkLyr))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Need fresh eyes to check this part of code
« Reply #2 on: December 23, 2014, 02:23:58 AM »
Assuming that your Xrefs are in Model Space .

Code - Auto/Visual Lisp: [Select]
  1. (defun _move:xref:to:zero:layer (/ _d l)
  2.   ;;    Tharwat 23.12.2014      ;;
  3.     (if (and (eq (vla-get-objectname x) "AcDbBlockReference")
  4.              (vlax-property-available-p x 'Path)
  5.         )
  6.       (if
  7.         (eq :vlax-true
  8.             (vla-get-lock
  9.               (setq l (vla-item (vla-get-layers _d) (vla-get-layer x)))
  10.             )
  11.         )
  12.          (progn
  13.            (vla-put-lock l :vlax-false)
  14.            (vla-put-layer x "0")
  15.            (vla-put-lock l :vlax-true)
  16.          )
  17.          (vla-put-layer x "0")
  18.       )
  19.     )
  20.   )
  21.   (princ)
  22.  

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need fresh eyes to check this part of code
« Reply #3 on: December 23, 2014, 10:54:03 AM »
Thanks ronjonp
Thanks Tharwat

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Need fresh eyes to check this part of code
« Reply #4 on: December 23, 2014, 11:59:35 AM »
Thanks Tharwat
You are welcome .
Hope you got it working as you've been looking for .

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Need fresh eyes to check this part of code
« Reply #5 on: December 24, 2014, 02:34:13 AM »
Thanks Tharwat
You are welcome .
Hope you got it working as you've been looking for .

Thanks for your effort. But I want to know whats wrong.
I have xrefs in both model and layouts
Code - Auto/Visual Lisp: [Select]
  1.   (if (= :vlax-true (vla-get-isxref x))
  2.     (progn
  3.       (if (eq :vlax-true
  4.               (vla-get-lock
  5.                 (setq blkLyr (vla-item (vla-get-layers doc) (vla-get-layer x)))))
  6.         (progn
  7.           (vla-put-lock blkLyr :vlax-false)
  8.           (vla-put-layer x XrefTrgtLyr)
  9.           (vla-put-lock blkLyr :vlax-true)
  10.           )
  11.         (vla-put-layer x XrefTrgtLyr)
  12.         )
  13.       )
  14.     )
  15.   )
This code gives error
Code: [Select]
; error: ActiveX Server returned the error: unknown name: Layer

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Need fresh eyes to check this part of code
« Reply #6 on: December 24, 2014, 03:02:59 AM »
Thanks Tharwat
You are welcome .
Hope you got it working as you've been looking for .

Thanks for your effort. But I want to know whats wrong.
I have xrefs in both model and layouts
Code - Auto/Visual Lisp: [Select]
  1.   (if (= :vlax-true (vla-get-isxref x))
  2.     (progn
  3.       (if (eq :vlax-true
  4.               (vla-get-lock
  5.                 (setq blkLyr (vla-item (vla-get-layers doc) (vla-get-layer x)))))
  6.         (progn
  7.           (vla-put-lock blkLyr :vlax-false)
  8.           (vla-put-layer x XrefTrgtLyr)
  9.           (vla-put-lock blkLyr :vlax-true)
  10.           )
  11.         (vla-put-layer x XrefTrgtLyr)
  12.         )
  13.       )
  14.     )
  15.   )
This code gives error
Code: [Select]
; error: ActiveX Server returned the error: unknown name: Layer

Because you are iterating though Blocks table , so you can not put it on any layer ;)

Try the following which runs across all layouts including Model Space :

Code - Auto/Visual Lisp: [Select]
  1. (defun _move:xref:to:layer (layer / _d l)
  2.   ;;    Tharwat 23.12.2014      ;;
  3.   (if (tblsearch "LAYER" layer)
  4.     (vlax-for y
  5.                 (vla-get-layouts
  6.                   (setq
  7.                     _d (vla-get-ActiveDocument (vlax-get-acad-object))
  8.                   )
  9.                 )
  10.       (vlax-for x (vla-get-block y)
  11.         (if (and (eq (vla-get-objectname x) "AcDbBlockReference")
  12.                  (vlax-property-available-p x 'Path)
  13.             )
  14.           (if
  15.             (eq :vlax-true
  16.                 (vla-get-lock
  17.                   (setq
  18.                     l (vla-item (vla-get-layers _d) (vla-get-layer x))
  19.                   )
  20.                 )
  21.             )
  22.              (progn
  23.                (vla-put-lock l :vlax-false)
  24.                (vla-put-layer x layer)
  25.                (vla-put-lock l :vlax-true)
  26.              )
  27.              (vla-put-layer x layer)
  28.           )
  29.         )
  30.       )
  31.     )
  32.     (alert (strcat "Layer name : "
  33.                    layer
  34.                    " is not found in drawing "
  35.            )
  36.     )
  37.   )
  38.   (princ)