Page 1 of 4 1234 LastLast
Results 1 to 10 of 39

Thread: Renaming a block using LISP

  1. #1
    Active Member
    Join Date
    2007-02
    Location
    Calgary, Alberta, Canada
    Posts
    73
    Login to Give a bone
    0

    Default Renaming a block using LISP

    I have a block I would like to rename, but the old name isn't consistant.

    I was thinking of using (entget (car (entsel))) to dump the data to command line and then picking out what I need and somehow renaming the block from there.

    This is what I get when I dump data:

    Code:
    Command: (entget (car (entsel)))
    
    Select object: ((-1 . <Entity name: -401d0390>) (0 . "INSERT") (330 . <Entity 
    name: -401d03f0>) (5 . "E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . 
    "Border1") (100 . "AcDbBlockReference") (66 . 1) (2 . "A1-TITLEBLOCK") (10 
    -10.0 -10.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) 
    (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
    The relevant information I need is (0 . "INSERT") and (2 . "A1-TITLEBLOCK).

    I need to rename whatever (2 . " " ) happens to be, to something else.

    Ideas?

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    You can't rename an INSERT.
    You'll have to operate on the block definition.

    Sample:

    Code:
    
    
    (vla-put-Name
      (vla-item
        (vla-get-Blocks
          (vla-get-ActiveDocument
            (vlax-get-acad-object)
          )
        )
      "333") ;;;<-- old block name
    "NewName") ;;;< -- new block name
    
    
    R.K. McSwain | CAD Panacea |

  3. #3
    Active Member
    Join Date
    2007-02
    Location
    Calgary, Alberta, Canada
    Posts
    73
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Thanks! Works great!

    The only problem is that I don't know that name of the block because it may be different in each drawing, but the block that needs to be renamed will be in a selection set (because they user has to manually select the block). Is there a way to take the block name out of the selection set (it's show in my first post as (2 . "A1-TITLEBLOCK") and then run it in the code you showed me?

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by mikelf View Post
    Thanks! Works great!

    The only problem is that I don't know that name of the block because it may be different in each drawing, but the block that needs to be renamed will be in a selection set (because they user has to manually select the block). Is there a way to take the block name out of the selection set (it's show in my first post as (2 . "A1-TITLEBLOCK") and then run it in the code you showed me?
    Sure, add these three lines at the top, and then change the "333" to name.

    Code:
    
    
    (setq blki (entsel))
    (setq obj (vlax-ename->vla-object (car blki)))
    (setq name (vla-get-EffectiveName obj))
    
    
    R.K. McSwain | CAD Panacea |

  5. #5
    I could stop if I wanted to
    Join Date
    2001-07
    Posts
    319
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by rkmcswain View Post
    ...
    (setq obj (vlax-ename->vla-object (car blki)))
    ...
    and add
    (vlax-release-object obj)

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by clovis View Post
    and add
    (vlax-release-object obj)
    Isn't this only needed for objects outside of AutoCAD...?

    Copied from 2009 Help: Developer Documentation

    vlax-release-object

    Releases a drawing object

    (vlax-release-object obj)

    When an AutoLISP routine no longer uses an object outside AutoCAD, such as a Microsoft Excel object, call the (vlax-release-object) function to make sure that the associated application closes properly. Objects released with (vlax-release-object...) may not be released immediately. The actual release may not happen until the next automatic garbage collection occurs. You can call (gc) directly to force the garbage collection to occur at a specific location within your code. However, calling (gc) may degrade performance, and it is recommended that you avoid placing calls to (gc) in locations where it is likely to be called many times in a row, such as within loops.

    If an object-associated application does not close after calling the (gc) function, the (vlax-release-object) function was not called for all objects outside AutoCAD.

    Arguments

    obj

    A VLA-object.

    After release, the drawing object is no longer accessible through obj.

    Return Values

    Unspecified.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by BlackBox View Post
    Isn't this only needed for objects outside of AutoCAD...?
    Yes, I agree with that statement. There is no need to release AutoCAD's own objects. In fact, you can geta few interesting fatal errors when going a bit too far.
    Last edited by BlackBox; 2013-04-26 at 07:29 PM.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by rkmcswain View Post
    ... good to hear it from someone such as you Robert.
    I'm feeling the love RK... feeling the looove.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by BlackBox View Post
    I'm feeling the love RK... feeling the looove.
    Sorry - did not mean it that way.
    Message removed.
    Last edited by BlackBox; 2013-04-26 at 07:30 PM.
    R.K. McSwain | CAD Panacea |

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Renaming a block using LISP

    Quote Originally Posted by rkmcswain View Post
    Sorry - did not mean it that way.
    Message removed.
    That saddens me, RK.

    You've not offended me, nor do I feel disrespected in any way. Not that you care, but I'm former US Army AIRBORNE, I don't think you could offend me if you tried. Ha, ha!

    Contrary to what you may have thought, I enjoyed your comment. It keeps me grounded - despite my being correct, and that I beat RobertB to the punch, I still got looked over in your statement!
    (You're still the man, RobertB, I just beat the man on that one! LOL)

    Your post actually made my day, in a dark humor kind of way.

    If possible, I'd encourage you to put your post back in, I really don't mind.

    ALL IN FAVOR OF RK REMOVING POLITICAL CORRECTNESS, SAY AYE...!???
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Page 1 of 4 1234 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 2015-05-11, 09:03 PM
  2. BLOCK RENAMING
    By Wish List System in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2012-08-08, 05:54 PM
  3. Inserting a block and renaming it - simultaneously
    By alex.mankiewicz in forum AutoCAD Customization
    Replies: 9
    Last Post: 2009-04-22, 08:33 PM
  4. Renaming block definition
    By jbeaman in forum Dynamic Blocks - Technical
    Replies: 4
    Last Post: 2007-08-09, 01:09 PM
  5. Renaming a Note block family.
    By sifuentes in forum Revit Architecture - General
    Replies: 1
    Last Post: 2004-11-30, 12:49 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
  •