TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TJAM51 on April 06, 2005, 10:37:42 AM

Title: Replacing block without changing attribute
Post by: TJAM51 on April 06, 2005, 10:37:42 AM
I have a block named 1a. This block has an attribute with information typed into the attribute. I need to replace this block 1a with a new block 2a but need to retain the attribute information...only the physical block shape and size are affected......any ideas?


Thanks
Title: Replacing block without changing attribute
Post by: David Hall on April 06, 2005, 11:14:49 AM
What happens if you redefine 1a = 2a?  I think the block will update as long as the Attributes are the same.  Can you post the 2 blocks and we can test it?
Title: Replacing block without changing attribute
Post by: hudster on April 06, 2005, 11:23:25 AM
if the attributes are the same, can you export them from block a and import to block b?
Title: Replacing block without changing attribute
Post by: ronjonp on April 06, 2005, 11:36:28 AM
If all you are doing is changing the way the block looks by redefining it, the attribute values should stay the same. Post the drawing you are working on.

Ron
Title: Replacing block without changing attribute
Post by: Keith™ on April 06, 2005, 11:36:38 AM
Here is one I use quite regularly

Code: [Select]

;;;   UB.LSP
;;;   Copyright (C) 1997-2005 by K.E. Blackie
;;;
;;;   kblackie -AT- resourcecad.com
;;;
;;;   Permission to use, copy, modify, and distribute this software
;;;   for any purpose and without fee is hereby granted, provided
;;;   that the above copyright notice appears in all copies and that
;;;   both that copyright notice and this permission notice appear in
;;;   all supporting documentation.
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;;
;;;
;;;   15 March 1997
;;;   8 August 1998
;;;   29 November 2001
;;;   12 January 2005
;;;
;;;----------------------------------------------------------------------------
;;;   DESCRIPTION
;;;----------------------------------------------------------------------------
;;;   C:UB
;;;
;;;   This function replaces a block reference specified by the user
;;;   to another block already inserted in the drawing.
;;;   All attributes are left in place and remain unmodified.
;;;   No error checking is provided. It is presumed the user will
;;;   know what blocks are already inserted and available for use.
;;;
;;;----------------------------------------------------------------------------
;;;----------------------------------------------------------------------------

(DEFUN C:UB( / as e index newname ss ssl)
  (setq ss (ssget '((0 . "insert"))))
  (setq newname (getstring t "\nReplace with block name: "))
  (setq ssl(sslength ss))
  (setq index 0)
  (repeat ssl
   (setq e (entget(ssname ss index)))
   (setq as (assoc 2 e))
   (setq e (subst (cons 2 newname) as e))
   (entmod e)
   (setq index (+ 1 index))
  )
 (PRINC)
)
Title: Replacing block without changing attribute
Post by: CottageCGirl on April 06, 2005, 12:09:53 PM
copy the block- explode the copy, edit the shape-make the revised one back into a block of the same name (be sure to select a base point) -click ok and the origional  will be redefined  [by copying it, it is a double check that it works-you just erase the duplicate when you are done]

this will work for all of the same blocks in a drawing
Title: Replacing block without changing attribute
Post by: dubb on April 06, 2005, 01:24:16 PM
cant you also use the "refedit" command?
Title: Replacing block without changing attribute
Post by: VerticalMojo on August 11, 2005, 10:56:52 AM
Keith, is there a way to use your lisp but have it ask for the block name instead of selecting objects that way you can globally do a change?
Title: Replacing block without changing attribute
Post by: Keith™ on August 11, 2005, 11:28:46 AM
Should be able to be done easily enough ... If I get some time, I'll look at it ... kinda busy right now ...
Title: Replacing block without changing attribute
Post by: Bob Wahr on August 11, 2005, 11:32:48 AM
-insert 1a=2a

or if you need the name to change as well, use rename to rename 1a to 2a then -insert 2a=
Title: Replacing block without changing attribute
Post by: Amsterdammed on August 11, 2005, 02:54:44 PM
Bob,

that's a cool one.

There are always thinks in Acad i don't know about yet.

Thanks,

Bernd