Author Topic: Need fresh eyes  (Read 2003 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Need fresh eyes
« on: December 26, 2016, 10:34:49 AM »
I I have to edit more than 500 file. each file containing a block or objects
I have to open each file then move all objects too layer 0 and change text's TEXTSTYLE
I coded this routine:
But have more than one issue
- While running the lisp I have to switch between VLIDE and AUTOCAD to complete the issue
- after run the lisp more than one time I can not edit the lisp
- in VLIDE cpmes the attached image

The code
Code - Auto/Visual Lisp: [Select]
  1. ;  (MoveObjectsTo0)
  2.  
  3. (DEFUN MoveObjectsTo0 ( / )
  4.   (setq StyName "AAWTextStyle")
  5.   (setvar "insunits" 4)
  6.   (if (and
  7.         (setq a (ssget "_X"))
  8.         (vl-cmdf "explode" a )
  9.         (vl-cmdf "._zoom" "Extents" )
  10.         (vl-cmdf "._-purge" "BLOCKS" "*" "n")
  11.         (setq a (ssget "X"))
  12.         (setq p1 (getpoint "Pick Point" ))
  13.         (if (vl-cmdf "_.-insert" "L:/AAW-STND/CAD/Support/GENERAL/GENERAL.dwg" "0,0,0" "1" "1" "0"); inser
  14.           (progn
  15.             (vl-cmdf "_.erase" "last" "")
  16.             (vl-cmdf "_.-purge" "blocks" "GENERAL" "n")))
  17.         )
  18.     (progn
  19.       (IF (/= (GETVAR "DWGTITLED") 1)  
  20.           (vl-cmdf "._qsave")
  21.           )
  22.       (vl-cmdf "_.move" a ""  p1 (list 0. 0. 0.) "")
  23.       (repeat (setq i (sslength a))
  24.         (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
  25.         (vla-put-layer b "0")
  26.         (vla-put-color b 256)
  27.         (vla-put-Linetype b "ByLayer")
  28.         )
  29.       (cond
  30.         ((and
  31.            (setq ss (ssget "X" '((0 . "TEXT,MTEXT,ATTDEF"))))
  32.            (repeat (sslength ss)
  33.              (if
  34.                (and
  35.                  (setq e (ssname ss 0))
  36.                  (setq eVL (vlax-ename->vla-object e))
  37.                  )
  38.              (vla-put-StyleName eVL StyName)
  39.              (ssdel e ss)
  40.            )
  41.          )
  42.         )
  43.          )
  44.       )
  45.       (if               ; LEE MAC
  46.         (and (ssget "_X")
  47.          (progn
  48.            (while
  49.              (not
  50.                (or (= "" (setq n (vl-filename-base (getvar 'dwgname))))
  51.                    (and (snvalid n) (null (tblsearch "block" n))))
  52.                )
  53.              (princ "\nBlock name invalid or already exists.")
  54.            )
  55.            (if (= "" n) (setq n "*U"))
  56.            (setq p (list 0. 0. 0.))))
  57.      (progn
  58.          (setq l (cons o l)))
  59.        (vla-delete s)
  60.        (vlax-invoke
  61.          d
  62.          'copyobjects
  63.          l
  64.          (setq b (vlax-invoke (vla-get-blocks d) 'add (trans p 1 0) n))
  65.        )
  66.        (vlax-invoke
  67.          (vlax-get-property
  68.            d
  69.            (if (= 1 (getvar 'cvport))
  70.              'paperspace
  71.              'modelspace))
  72.          'insertblock (trans p 1 0) (vla-get-name b) 1.0 1.0 1.0 0.0)
  73.        (foreach o l (vla-delete o))))
  74.  
  75.       (vlax-for x blks (vlax-put-property x "Units" 4))
  76.       (vla-put-explodable        (vla-item blks n) :vlax-false)
  77.       (vla-put-BlockScaling      (vla-item blks n) acUniform)
  78.       (vl-cmdf "._REGENALL")
  79.       (vl-cmdf "._zoom" "Extents" )
  80.       (vl-cmdf "._-purge" "ALL" "*" "n")
  81.      
  82.       (setq fp (getvar 'dwgprefix))
  83.       (setq fn (vl-filename-base (getvar 'DWGName)))
  84.      
  85.       (setq blck (ssget "X" (list '(0 . "INSERT") (cons 2 fn))))
  86.       ;(vl-cmdf "_.attsync" "_.select" "" (ssname blck 0))
  87.       (setq blok (vlax-ename->vla-object (ssname blck 0)))
  88.       (vlax-release-object blok)
  89.       (vl-cmdf "._qsave")
  90.       (vl-cmdf "mslide" (strcat fp fn ".sld") )
  91.       (vl-file-delete (strcat fp fn ".bak"))
  92.       (vl-cmdf "._close")
  93.       )
  94.     )
  95.   )

ribarm

  • Gator
  • Posts: 3255
  • Marko Ribar, architect
Re: Need fresh eyes
« Reply #1 on: December 26, 2016, 12:37:16 PM »
If I may ask, why do you need to edit lisp after execution in VLIDE? I've changed your code to be more readable, you haven't localized your variables... If your starting selection set contains more than 1 entity, you have to consider using QAFLAGS=1 temporarily to explode sel. set afterwards... I've put STYLE=Standard if your coded style name don't exist... No need for (cond), just single (if) can do the trick as good as should... I don't see why VLIDE wouldn't load lisp more times, I see no relevant issues regarding this problem... After all, you can put it in your temporary acaddoc.lsp so it will automatically load whenever you open new DWG, just don't know what do you meant by editing lisp meanwhile...

Code - Auto/Visual Lisp: [Select]
  1.                                         ;  (MoveObjectsTo0)
  2.  
  3. (DEFUN MoveObjectsTo0 (/    a    b    blck blks blok d    e    evl
  4.                        fn   fp   i    l    n    p    p1   qaf  s
  5.                        ss   styname
  6.                       )
  7.  
  8.  
  9.   (if (tblsearch "STYLE" "AAWTextStyle")
  10.     (setq styname "AAWTextStyle")
  11.     (setq styname "Standard")
  12.   )
  13.   (setvar "INSUNITS" 4)
  14.   (if (and
  15.         (setq qaf (getvar "QAFLAGS"))
  16.         (setvar "QAFLAGS" 1)
  17.         (setq a (ssget "_X"))
  18.         (vl-cmdf "_.EXPLODE" a)
  19.         (setvar "QAFLAGS" qaf)
  20.         (vl-cmdf "_.ZOOM" "_EXTENTS")
  21.         (vl-cmdf "_.-PURGE" "_BLOCKS" "*" "_N")
  22.         (setq a (ssget "_X"))
  23.         (setq p1 (getpoint "\nPick or specify point : "))
  24.         (if (vl-cmdf
  25.               "_.-INSERT"
  26.               "L:/AAW-STND/CAD/Support/GENERAL/GENERAL.dwg"
  27.               "_non"                     "0,0,0"
  28.               "1"                        "1"
  29.               "0"
  30.              )                          ; insert
  31.           (progn
  32.             (vl-cmdf "_.ERASE" "_LAST" "")
  33.             (vl-cmdf "_.-PURGE" "_BLOCKS" "GENERAL" "_N")
  34.           )
  35.         )
  36.       )
  37.     (progn
  38.       (if (/= (getvar "DWGTITLED") 1)
  39.         (vl-cmdf "_.QSAVE")
  40.       )
  41.       (vl-cmdf "_.MOVE" a "" "_non" p1 "_non" (list 0.0 0.0 0.0) "")
  42.       (repeat (setq i (sslength a))
  43.         (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
  44.         (vla-put-layer b "0")
  45.         (vla-put-color b 256)
  46.         (vla-put-Linetype b "ByLayer")
  47.       )
  48.       (if
  49.         (and
  50.           (setq ss (ssget "_X" '((0 . "TEXT,MTEXT,ATTDEF"))))
  51.           (repeat (setq i (sslength ss))
  52.             (if
  53.               (and
  54.                 (setq e (ssname ss (setq i (1- i))))
  55.                 (setq evl (vlax-ename->vla-object e))
  56.               )
  57.                (vla-put-stylename evl styname)
  58.             )
  59.           )
  60.         )
  61.       )
  62.  
  63.       (if                               ; LEE MAC
  64.         (and
  65.           (ssget "_X")
  66.           (progn
  67.             (while
  68.               (not
  69.                 (or (= "" (setq n (vl-filename-base (getvar 'dwgname))))
  70.                     (and (snvalid n) (null (tblsearch "BLOCK" n)))
  71.                 )
  72.               )
  73.                (princ "\nBlock name invalid or already exists.")
  74.             )
  75.             (if (= "" n)
  76.               (setq n "*U")
  77.             )
  78.             (setq p (list 0. 0. 0.))
  79.           )
  80.         )
  81.          (progn
  82.            (vlax-for o (setq s (vla-get-activeselectionset d))
  83.              (setq l (cons o l))
  84.            )
  85.            (vla-delete s)
  86.            (vlax-invoke
  87.              d
  88.              'copyobjects
  89.              l
  90.              (setq
  91.                b (vlax-invoke (vla-get-blocks d) 'add (trans p 1 0) n)
  92.              )
  93.            )
  94.            (vlax-invoke
  95.              (vlax-get-property
  96.                d
  97.                (if (= 1 (getvar 'cvport))
  98.                  'paperspace
  99.                  'modelspace
  100.                )
  101.              )
  102.              'insertblock
  103.              (trans p 1 0)
  104.              (vla-get-name b)
  105.              1.0
  106.              1.0
  107.              1.0
  108.              0.0
  109.            )
  110.            (foreach o l (vla-delete o))
  111.          )
  112.       )
  113.  
  114.       (setq blks (vla-get-blocks
  115.                    (vla-get-activedocument (vlax-get-acad-object))
  116.                  )
  117.       )
  118.       (vlax-for x blks (vlax-put-property x "Units" 4))
  119.       (vla-put-explodable (vla-item blks n) :vlax-false)
  120.       (vla-put-blockscaling (vla-item blks n) acuniform)
  121.       (vl-cmdf "_.REGENALL")
  122.       (vl-cmdf "_.ZOOM" "_EXTENTS")
  123.       (vl-cmdf "_.-PURGE" "_ALL" "*" "_N")
  124.  
  125.       (setq fp (getvar 'dwgprefix))
  126.       (setq fn (vl-filename-base (getvar 'dwgname)))
  127.       ;|
  128.       (setq blck (ssget "X" (list '(0 . "INSERT") (cons 2 fn))))
  129.                                         ;(vl-cmdf "_.attsync" "_.select" "" (ssname blck 0))
  130.       (setq blok (vlax-ename->vla-object (ssname blck 0)))
  131.       (vlax-release-object blok)
  132.       |;
  133.       (vl-cmdf "_.QSAVE")
  134.       (vl-cmdf "_.MSLIDE" (strcat fp fn ".sld"))
  135.       (vl-file-delete (strcat fp fn ".bak"))
  136.       (vl-cmdf "_.CLOSE")
  137.     )
  138.   )
  139.   (princ)
  140. )
  141.  
« Last Edit: December 26, 2016, 12:41:41 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: Need fresh eyes
« Reply #2 on: December 26, 2016, 05:16:56 PM »
Thanks for quick reply
If I may ask, why do you need to edit lisp after execution in VLIDE? ...
in some cases I need to change unites for some files.

...
If your starting selection set contains more than 1 entity, you have to consider using QAFLAGS=1 ...
Why is this variable added?

...
I've put STYLE=Standard if your coded style name don't exist
...
the inserted file GENERAL.dwg has this style.may be it is better to move after inserting the file.

...
just don't know what do you meant by editing lisp meanwhile
...
As told before some files unites should be Meter and rest should be in Millimeter So I opned more than one file after execution the lisp

Did you see attached pic
what is this symbol? I noticed that the number of symbols are increasing after each time run the lisp.

 Thanks for your valuable help.
« Last Edit: December 27, 2016, 03:35:32 AM by HasanCAD »

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: Need fresh eyes
« Reply #3 on: December 27, 2016, 08:03:30 AM »
Off topic: I know I've see another (many) other threads with the same title. Can we please (please, please, please!) try to have better subject lines for these threads (better subject lines would help others find answers to their problems)?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: Need fresh eyes
« Reply #4 on: December 27, 2016, 09:40:50 AM »
Final Issue

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:CreateNewBlocks (/    a    b    blck blks blok d    e    evl
  2.                        fn   fp   i    l    n    p    p1   qaf  s
  3.                        ss   styname
  4.                       )
  5.   (vl-cmdf "_.-PURGE" "_BLOCKS" "*" "_N")
  6.   (if
  7.     (setq blk (ssget "_X" '((0 . "INSERT"))))
  8.     (progn
  9.       (setq n (vl-filename-base (getvar 'dwgname)))
  10.       (vla-put-explodable        (vla-item blks n) :vlax-true)
  11.       (setq qaf (getvar "QAFLAGS"))
  12.       (setvar "QAFLAGS" 1)
  13.       (vl-cmdf "_.EXPLODE" blk "")
  14.       (setvar "QAFLAGS" qaf)
  15.       (zmPrg)
  16.       )
  17.     (zmPrg)
  18.     )
  19.   (if (and        
  20.         (setq p1 (getpoint "\nPick or specify point : "))
  21.         (if (vl-cmdf
  22.               "_.-INSERT"
  23.               "L:/AAW-STND/CAD/Support/GENERAL/GENERAL.dwg"
  24.               "_non"                     "0,0,0"
  25.               "1"                        "1"
  26.               "0"
  27.              )                          ; insert
  28.           (progn
  29.             (vl-cmdf "_.ERASE" "_LAST" "")
  30.             (vl-cmdf "_.-PURGE" "_BLOCKS" "GENERAL" "_N")
  31.           )
  32.         )
  33.         (setq styname "AAWTextStyle")
  34.         (setq unts 4)           ; 4 millimeter / 6 meter
  35.         (setvar "insunits" unts)
  36.       )
  37.     (progn
  38.       (if (/= (getvar "DWGTITLED") 1) (vl-cmdf "_.QSAVE"))
  39.       (vl-cmdf "_.MOVE" a "" "_non" p1 "_non" (list 0.0 0.0 0.0) "")
  40.       (setq a (ssget "_X"))      
  41.       (repeat
  42.         (setq i (sslength a))
  43.         (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
  44.         (vla-put-layer b "0")
  45.         (vla-put-color b 256)
  46.         ;(vla-put-Linetype b "ByLayer")
  47.       )
  48.       (if (setq ss (ssget "_X" '((0 . "TEXT,MTEXT,ATTDEF"))))
  49.         (repeat
  50.           (setq i (sslength ss))
  51.           (setq e (ssname ss (1- i)))
  52.           (setq evl (vlax-ename->vla-object e))
  53.           (vla-put-stylename evl styname)
  54.           (setq i (1- i))
  55.           )
  56.         )
  57.       (if                               ; LEE MAC
  58.         (and
  59.           (ssget "_X")
  60.           (progn
  61.             (while
  62.               (not
  63.                 (or (= "" (setq n (vl-filename-base (getvar 'dwgname))))
  64.                     (and (snvalid n) (null (tblsearch "BLOCK" n)))
  65.                 )
  66.               )
  67.                (princ "\nBlock name invalid or already exists.")
  68.             )
  69.             (if (= "" n)
  70.               (setq n "*U")
  71.             )
  72.             (setq p (list 0. 0. 0.))
  73.           )
  74.         )
  75.          (progn
  76.            (vlax-for o (setq s (vla-get-activeselectionset d))
  77.              (setq l (cons o l))
  78.            )
  79.            (vla-delete s)
  80.            (vlax-invoke
  81.              d
  82.              'copyobjects
  83.              l
  84.              (setq
  85.                b (vlax-invoke (vla-get-blocks d) 'add (trans p 1 0) n)
  86.              )
  87.            )
  88.            (vlax-invoke
  89.              (vlax-get-property
  90.                d
  91.                (if (= 1 (getvar 'cvport))
  92.                  'paperspace
  93.                  'modelspace
  94.                )
  95.              )
  96.              'insertblock
  97.              (trans p 1 0)
  98.              (vla-get-name b)
  99.              1.0
  100.              1.0
  101.              1.0
  102.              0.0
  103.            )
  104.            (foreach o l (vla-delete o))
  105.          )
  106.       )
  107.  
  108.       (setq blks (vla-get-blocks
  109.                    (vla-get-activedocument (vlax-get-acad-object))
  110.                  )
  111.       )
  112.       (vlax-for x blks (vlax-put-property x "Units" 4))
  113.       (vla-put-explodable (vla-item blks n) :vlax-false)
  114.       (vla-put-blockscaling (vla-item blks n) acuniform)
  115.       (zmPrg)
  116.       (setq fp (getvar 'dwgprefix))
  117.       (setq fn (vl-filename-base (getvar 'dwgname)))
  118.       (vl-cmdf "_.QSAVE")
  119.       (vl-cmdf "_.MSLIDE" (strcat fp fn ".sld"))
  120.       (vl-file-delete (strcat fp fn ".bak"))
  121.       (vl-cmdf "_.CLOSE")
  122.     )
  123.   )
  124.   (princ)
  125. )
  126. (defun zmPrg ( / )
  127.   (vl-cmdf "_.REGENALL")  
  128.   (vl-cmdf "_.ZOOM" "_EXTENTS")
  129.   (vl-cmdf "_.-PURGE" "_ALL" "*" "_N")
  130.   )