+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
  1. #1
    Super Member chulse's Avatar
    Computer Details
    chulse's Computer Details
    Operating System:
    Windows 7
    Computer:
    Lenovo W701 mobile workstation
    RAM:
    12GB
    Graphics:
    NVIDIA Quadro FX 3800M
    Monitor:
    17" wide screen laptop w/ 22" acer
    Discipline
    See details...
    chulse's Discipline Details
    Occupation
    Conservation Planner/Arborist
    Discipline
    See details below.
    Details
    Tree Preservation Planning for civil design and developent
    Using
    Civil 3D 2013
    Join Date
    Jul 2007
    Location
    Front Royal, Virginia
    Posts
    1,312

    Question lisp for changing all objects in a block to layer "0"

    Registered forum members do not see this ad.

    Does anyone have a lisp that will change all the objects within all the blocks in a given dwg to layer "0" (while maintaing the block on the layer it was inserted into)? I have tried FixBlock, but it seems to only work on 1 t a time.
    I have many to do and any help would be much appreciated.

    Thanks in advance
    Cary Hulse
    Conservation Planner
    www.TreePreservationPlan.com
    www.Pack53.info

  2. #2
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,540

    Default

    Just a tip: write a small routine to grab all the blocks defined in the drawing and call FixBlock in a loop, with the blocks -one at a time.
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  3. #3
    Super Member chulse's Avatar
    Computer Details
    chulse's Computer Details
    Operating System:
    Windows 7
    Computer:
    Lenovo W701 mobile workstation
    RAM:
    12GB
    Graphics:
    NVIDIA Quadro FX 3800M
    Monitor:
    17" wide screen laptop w/ 22" acer
    Discipline
    See details...
    chulse's Discipline Details
    Occupation
    Conservation Planner/Arborist
    Discipline
    See details below.
    Details
    Tree Preservation Planning for civil design and developent
    Using
    Civil 3D 2013
    Join Date
    Jul 2007
    Location
    Front Royal, Virginia
    Posts
    1,312

    Default

    Quote Originally Posted by fuccaro View Post
    Just a tip: write a small routine to grab all the blocks defined in the drawing and call FixBlock in a loop, with the blocks -one at a time.
    That sounds like a great idea, except I have no idea how to do it. Anyone looking for a project?

    Thanks for the idea!
    Cary Hulse
    Conservation Planner
    www.TreePreservationPlan.com
    www.Pack53.info

  4. #4
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,540

    Default

    Can you post the code for the FixBlock lisp?
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  5. #5
    Super Member chulse's Avatar
    Computer Details
    chulse's Computer Details
    Operating System:
    Windows 7
    Computer:
    Lenovo W701 mobile workstation
    RAM:
    12GB
    Graphics:
    NVIDIA Quadro FX 3800M
    Monitor:
    17" wide screen laptop w/ 22" acer
    Discipline
    See details...
    chulse's Discipline Details
    Occupation
    Conservation Planner/Arborist
    Discipline
    See details below.
    Details
    Tree Preservation Planning for civil design and developent
    Using
    Civil 3D 2013
    Join Date
    Jul 2007
    Location
    Front Royal, Virginia
    Posts
    1,312

    Smile

    here ya go.

    Need to give credit for it since it's not mine: http://www.cadcorner.ca/lisp.php

    Thanks
    Attached Files
    Last edited by chulse; 4th Jan 2008 at 08:30 pm. Reason: can't spell...
    Cary Hulse
    Conservation Planner
    www.TreePreservationPlan.com
    www.Pack53.info

  6. #6
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,540

    Default

    That code is too long for me -it is week end!- so here is my own code.
    Code:
    (defun c:fixblocks( / b1 name ent elist a8 a62)
      (setq b1 (tblnext "BLOCK" t))
      (while b1
        (princ (strcat "\n" (setq name (cdr (assoc 2 b1)))))
        (setq ent (tblobjname "block" name) ent (entnext ent))
        (while ent
          (setq elist (entget ent))
          (setq elist (if (setq a8 (assoc 8 elist)) (subst (cons 8 "0") a8 elist)))
          (setq elist (if (setq a62 (assoc 62 elist)) (subst '(62 . 0) a62 elist)))
          (setq elist (entmod elist))
          (setq ent (entnext ent))
          )
        (setq b1 (tblnext "BLOCK"))
        )
      (princ)
      )
    It is not fully tested and it has no error trap. Sorry, it is all I can do at this time.
    Do a REGEN after runing the lisp.

    ****** editing ******* Test it on a drawing with XREFs
    Last edited by fuccaro; 4th Jan 2008 at 09:40 pm.
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  7. #7
    Super Member chulse's Avatar
    Computer Details
    chulse's Computer Details
    Operating System:
    Windows 7
    Computer:
    Lenovo W701 mobile workstation
    RAM:
    12GB
    Graphics:
    NVIDIA Quadro FX 3800M
    Monitor:
    17" wide screen laptop w/ 22" acer
    Discipline
    See details...
    chulse's Discipline Details
    Occupation
    Conservation Planner/Arborist
    Discipline
    See details below.
    Details
    Tree Preservation Planning for civil design and developent
    Using
    Civil 3D 2013
    Join Date
    Jul 2007
    Location
    Front Royal, Virginia
    Posts
    1,312

    Default

    Thanks a lot, I'll try it.
    Cary Hulse
    Conservation Planner
    www.TreePreservationPlan.com
    www.Pack53.info

  8. #8
    Senior Member kpblc's Avatar
    Using
    AutoCAD 2005
    Join Date
    May 2006
    Location
    Russia, St-Petersburg
    Posts
    317

    Default

    Also try this:
    Code:
    (defun c:norm (/ *error* adoc lst_layer func_restore-layers)
      (defun *error* (msg)
        (func_restore-layers)
        (vla-endundomark adoc)
        (princ msg)
        (princ)
        ) ;_ end of defun
    
      (defun func_restore-layers ()
        (foreach item lst_layer
          (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
          (vl-catch-all-apply
            '(lambda ()
               (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))))
               ) ;_ end of lambda
            ) ;_ end of vl-catch-all-apply
          ) ;_ end of foreach
        ) ;_ end of defun
    
      (vl-load-com)
      (vla-startundomark
        (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
        ) ;_ end of vla-startundomark
      (vlax-for item (vla-get-layers adoc)
        (setq lst_layer (cons (list item
                                    (cons "lock" (vla-get-lock item))
                                    (cons "freeze" (vla-get-freeze item))
                                    ) ;_ end of list
                              lst_layer
                              ) ;_ end of cons
              ) ;_ end of setq
        (vla-put-lock item :vlax-false)
        (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)))
        ) ;_ end of vlax-for
      (vlax-for blk (vla-get-blocks adoc)
        (if (and (equal (vla-get-islayout blk) :vlax-false)
                 (equal (vla-get-isxref blk) :vlax-false)
                 ) ;_ end of and
          (progn
            (vlax-for subent blk
              (vla-put-layer subent "0")
              (vla-put-color subent 0)
              (vla-put-lineweight subent aclnwtbyblock)
              (vla-put-linetype subent "byblock")
              ) ;_ end of vlax-for
            ) ;_ end of progn
          ) ;_ end of if
        ) ;_ end of vlax-for
      (func_restore-layers)
      (vla-endundomark adoc)
      (princ)
      ) ;_ end of defun
    All I say is only my opinion.

  9. #9
    Super Member chulse's Avatar
    Computer Details
    chulse's Computer Details
    Operating System:
    Windows 7
    Computer:
    Lenovo W701 mobile workstation
    RAM:
    12GB
    Graphics:
    NVIDIA Quadro FX 3800M
    Monitor:
    17" wide screen laptop w/ 22" acer
    Discipline
    See details...
    chulse's Discipline Details
    Occupation
    Conservation Planner/Arborist
    Discipline
    See details below.
    Details
    Tree Preservation Planning for civil design and developent
    Using
    Civil 3D 2013
    Join Date
    Jul 2007
    Location
    Front Royal, Virginia
    Posts
    1,312

    Default

    Quote Originally Posted by kpblc View Post
    Also try this:
    That worked!
    Cary Hulse
    Conservation Planner
    www.TreePreservationPlan.com
    www.Pack53.info

  10. #10
    Forum Newbie
    Using
    Civil 3D 2006
    Join Date
    Jul 2008
    Posts
    2

    Default Norm.lsp

    Registered forum members do not see this ad.

    Quote Originally Posted by kpblc View Post
    Also try this:
    Code:
    (defun c:norm (/ *error* adoc lst_layer func_restore-layers)
      (defun *error* (msg)
        (func_restore-layers)
        (vla-endundomark adoc)
        (princ msg)
        (princ)
        ) ;_ end of defun
     
      (defun func_restore-layers ()
        (foreach item lst_layer
          (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
          (vl-catch-all-apply
            '(lambda ()
               (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))))
               ) ;_ end of lambda
            ) ;_ end of vl-catch-all-apply
          ) ;_ end of foreach
        ) ;_ end of defun
     
      (vl-load-com)
      (vla-startundomark
        (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
        ) ;_ end of vla-startundomark
      (vlax-for item (vla-get-layers adoc)
        (setq lst_layer (cons (list item
                                    (cons "lock" (vla-get-lock item))
                                    (cons "freeze" (vla-get-freeze item))
                                    ) ;_ end of list
                              lst_layer
                              ) ;_ end of cons
              ) ;_ end of setq
        (vla-put-lock item :vlax-false)
        (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)))
        ) ;_ end of vlax-for
      (vlax-for blk (vla-get-blocks adoc)
        (if (and (equal (vla-get-islayout blk) :vlax-false)
                 (equal (vla-get-isxref blk) :vlax-false)
                 ) ;_ end of and
          (progn
            (vlax-for subent blk
              (vla-put-layer subent "0")
              (vla-put-color subent 0)
              (vla-put-lineweight subent aclnwtbyblock)
              (vla-put-linetype subent "byblock")
              ) ;_ end of vlax-for
            ) ;_ end of progn
          ) ;_ end of if
        ) ;_ end of vlax-for
      (func_restore-layers)
      (vla-endundomark adoc)
      (princ)
      ) ;_ end of defun
    IMO that is the best thing since flush toilets!
    I found this by mistake while looking for something else. The company where I work used to use Medusa (!?) and when all the old files were converted to .dwg files (by an outside company) the "clumps" (groups, dimensions, blocks etc.) in Medusa created an enormous amount of blocks in AutoCAD; a real nightmare to work with.
    Norm.lsp has been a revelation so far, but today I ran it on a drawing file and received the error message lisp value has no coercion to VARIANT with this type: -2. Any ideas? A mod to the lisp perhaps?
    Many thanks for the original and thanks in advance for any replies.

Similar Threads

  1. Old "Layer Manager" state in ACAD2008
    By King of Maine in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 31st Aug 2007, 01:31 am
  2. Having objects "stay connected" when moved
    By Siberian in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 9th Jun 2007, 06:58 pm
  3. Lisp for Changing Objects layer
    By EScholtz in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 30th Mar 2007, 01:40 am
  4. Lisp routine to delete a file form "C" drive
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 28th Mar 2007, 09:01 pm
  5. Lisp for "dividing" objects
    By fade2blackened in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 16th Mar 2005, 02:55 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts