Results 1 to 7 of 7

Thread: How to modify lisp to convert blocks with different prefix to anonymous

  1. #1
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default How to modify lisp to convert blocks with different prefix to anonymous

    Hi all,

    I am using this routine below to convert my two specific blocks to anonymous block and purge, but the problem apears when I attach drawing as xref (drawing with blocks) to another drawing and bind it, than my blocks got name like: "x-plan$0$block1" and ""x-plan$0$block2".
    How to modify this routine to make it find blocks with specific word in name?
    Thanks in advance.

    Code:
    (defun c:tntblock (/ _data data fdata ss i e from info)(vl-load-com)
    (setq blks (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))))  
    (defun _data (en func l1 l2 rv)
          (if l2
        (mapcar '(lambda (j k)
               (func en j (if (and rv (/= 0 rv)
                                (eq j "Rotation")) (- k rv) k))) l1 l2)
          (mapcar '(lambda (j)          
               (func en j)) l1)
          )
      )
    
    
    (setq data '( "InsertionPoint" "Height" "TextAlignmentPoint")
          Fdata '("Textstring" "color" "Rotation"  "StyleName" "Alignment" "Layer"
                  "ScaleFactor" "UpsideDown" "Backward" 
                   )
          )
    (if
      (setq ss (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "BLOCK1,BLOCK2,`*U*"))))
              (repeat (setq i (sslength ss))
                  (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
                            (setq r (vla-get-rotation e))
                      (if (member  (strcase (vla-get-effectivename e)) '("BLOCK1" "BLOCK2"))
                        (progn
                (vlax-invoke e 'ConvertToAnonymousBlock)
                (setq from (mapcar '(lambda (k)
                        (setq info (_data k vlax-get fdata nil nil))
                              (vla-delete k) info)          
                            (vlax-invoke e 'GetAttributes)))      
                                   
            (vlax-for itm (setq blk (vla-item
                         blks
                         (vla-get-name e)
                       ))
        (if (eq "AcDbAttributeDefinition" (vla-get-objectname itm))
            (progn
                      (setq fd (car from))
              (setq old (_data itm vlax-get data nil nil))
              (setq new (vlax-invoke blk 'AddText (car fd) (car old) (cadr old)))
              (_data new vlax-put fdata fd r)
                      (vlax-invoke new 'Move '(0.0 0.0 0.0) (last old))
              (vla-delete itm)
          
              (setq from (cdr from))
              )
          )
              ) 
              )
          )
                      )
              )
    (command "-Purge" "B" "BLOCK1" "N" )
    (command "-Purge" "B" "BLOCK2" "N" )
    (princ)
      )

  2. #2
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    0

    Default Re: How to modify lisp to convert blocks with different prefix to anonymous

    Why don't you bind your xrefs using the "insert" option (instead of "bind")?

    That way you don't get the "....$0$....." in the name, then maybe it won't be an issue?

    Just a thought

  3. #3
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: How to modify lisp to convert blocks with different prefix to anonymous

    Thanks tedg for replay. You are right, this is a solution, but our client require binded xrefs.... that's annoying, i know, but client is your master
    I tested it using your way, I changed BINDTYPE variable to insert xrefs and found another problem: my two specific blocks are inside another block (inserted xref) and routine does not work.... any ideas?

  4. #4
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    0

    Default Re: How to modify lisp to convert blocks with different prefix to anonymous

    Quote Originally Posted by Arterius View Post
    Thanks tedg for replay. You are right, this is a solution, but our client require binded xrefs.... that's annoying, i know, but client is your master
    I tested it using your way, I changed BINDTYPE variable to insert xrefs and found another problem: my two specific blocks are inside another block (inserted xref) and routine does not work.... any ideas?
    I tried testing your routine, I couldn't get it to work even without a bound xref with blocks "BLOCK1" and "BLOCK2", I'm not sure what it actually does, a bit over my head.
    But maybe someone else who's more lisp savvy than I am can help you.

    Going back to your original question, you could use wild cards to find the bound xref block names like *$0$BLOCK1" and *$0$BLOCK2
    But I'm not sure how that would apply to your routine, maybe another setq?

  5. #5
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: How to modify lisp to convert blocks with different prefix to anonymous

    Please test it on blocks with attributes.

  6. #6
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    0

    Default Re: How to modify lisp to convert blocks with different prefix to anonymous

    Quote Originally Posted by Arterius View Post
    Please test it on blocks with attributes.
    Ok got it to work, but I haven't found a way to answer your question changing the bound xref blocks "...$0$BLOCK1" (etc).

    I did find that if you use "bind" "insert" on the xref, and explode the bound xref block, it will change the blocks as you want.

  7. #7
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: How to modify lisp to convert blocks with different prefix to anonymous

    Hi Tedg,
    yes, exploding is a solution, but it is a detour and I cannot make lisp to explode xref, because usually my xrefs got different name for different building, level or even project...
    The best way is to force this routine to rename blocks in binded xref, I am sure this is possible, but it is beyond my skills

Similar Threads

  1. Convert all blocks to anonymous
    By Arterius in forum AutoLISP
    Replies: 14
    Last Post: 2013-03-11, 01:26 PM
  2. Modify LISP to Include Nested Blocks
    By stusic in forum AutoLISP
    Replies: 0
    Last Post: 2013-01-30, 06:28 PM
  3. Anonymous Blocks
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 8
    Last Post: 2006-06-12, 06:59 PM
  4. Replies: 6
    Last Post: 2006-04-03, 07:19 AM
  5. Anonymous Blocks
    By seppanen.75334 in forum AutoCAD General
    Replies: 9
    Last Post: 2005-01-27, 08:40 PM

Posting Permissions

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