Author Topic: Block and symbol replacement  (Read 4304 times)

0 Members and 1 Guest are viewing this topic.

TJAM51

  • Guest
Block and symbol replacement
« on: January 17, 2005, 10:24:33 AM »
I have seen a routine where you can take several enities and create a block without having to assign a name to that block. The routine does it for you. After this I am seeking a good symbol replacement routine. I know of several but does anyone know of one that really works well?

Thanks

whdjr

  • Guest
Block and symbol replacement
« Reply #1 on: January 18, 2005, 12:09:10 PM »
Quote from: TJAM51
After this I am seeking a good symbol replacement routine.


I don't know if this is what you want, but the Autocad expresstools has a good "blockreplace" tool.  The tool replaces all instances of a block with another block as long as it is already defined within that dwg.  
If you don't want it to select all blocks in the dwg you can make a small change that will let you provide a selection set.  Edit the file "blocktoxrefsup.lsp" which is in the Express Tools folder.  Search for the defun titled "acet-block-replace" and remove the "X" from the first ssget function.  This will allow you to select a certain area of your dwg to replace the block in and not the whole dwg.

HTH,

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block and symbol replacement
« Reply #2 on: January 18, 2005, 12:35:59 PM »
Quote from: TJAM51
I have seen a routine where you can take several enities and create a block without having to assign a name to that block. The routine does it for you.

Here is a quickie:
Code: [Select]
(defun c:myblock(/ ss pt)
  (prompt "\nSelect objects to make a block.")
  (setq ss (ssget))
  (if (and ss (> (sslength ss) 0))
    (progn
      (while
        (not (setq pt (getpoint "\nPlease select a base point: ")))
        (princ "\nPlease try again..."))
      (Command "_copybase" pt ss "")
      (command "_pasteblock" pause)

    )
  )
  (princ)
)
(prompt "\nMyBlock loaded enter Myblock to run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Block and symbol replacement
« Reply #3 on: January 18, 2005, 01:00:56 PM »
i have this one i use from time to time

Code: [Select]
;| BLKSWP.LSP    c.2000  Rob Herr    robherr@hotmail.com
   'Swap Blocks Globally'    v 2.0    28 Mar 2000

  Pick one block. Pick one other block. Each instance of these blocks
  are switched throughout the drawing. Not recommended for attributes,
  unless blocks have complementary attribute locations, etc.
 
  ___________________________________________________________________
  |     PERMISSION HEREBY GRANTED BLA, BLA, BLA, TO MODIFY ETC.     |
  |   As long as name and email remain with the original program    |
  | unaltered. However I would like to know of any bugs or problems |
  |   that arise with the actual program. And of course I take no   |
  |  responsibility for lost limbs, auto repair bills, mechanical   |
  |         or electronic difficulties, or snake venom.             |
  -------------------------------------------------------------------

  v1.1 added osnap control
  v1.2 added attribute exclusion
  v2.0 changed routine from 'reinsertion' to 'redefine xdata'
       and removed attribute exclusion
|;

(defun C:blkswp (/ osm a1 b1 a2 a3 aasc an aset alen b2 b3 basc bn
                   bset blen cnt anxt anfo bnxt bnfo)
 (setvar "CMDECHO" 0)
 (setq osm (getvar "OSMODE"))
 (setvar "OSMODE" 0)
 (setq a1 (entsel "\nSelect Block to Swap..."))
 (setq b1 (entsel "\nSelect Block to Swap with..."))
 (command "REGENAUTO" "Off")
 (setq a2 (car a1))
 (setq a3 (entget a2))
 (if (= (cdr (assoc 0 a3)) "INSERT")
   (progn
    (setq aasc (assoc '2 a3))
    (setq an (cdr aasc))
    (setq aasc (list aasc))
    (setq aset (ssget "X" aasc))
    (setq alen (sslength aset))
    (princ "\nUpdating blocks...")
  )
  (progn
   (setq aset nil)
   (setvar "OSMODE" osm)
   (setvar "CMDECHO" 1)
   (princ "\nThat is not a block! ")
   (exit)
  )
 )
 (setq b2 (car b1))
 (setq b3 (entget b2))
 (if (= (cdr (assoc 0 b3)) "INSERT")
   (progn
    (setq basc (assoc '2 b3))
    (setq bn (cdr basc))
    (setq basc (list basc))
    (setq bset (ssget "X" basc))
    (setq blen (sslength bset))
    (princ "\nUpdating blocks...")
  )
  (progn
   (setq bset nil)
   (setvar "OSMODE" osm)
   (setvar "CMDECHO" 1)
   (princ "\nThat is not a block! ")
   (exit)
  )
 )
 (setq cnt 0)
 (while (< cnt alen)
  (setq anxt (ssname aset cnt))
  (setq anfo (entget anxt))
  (if (= (cdr (assoc 0 anfo)) "INSERT")
   (progn
    (setq anfo (subst (cons 2 bn) (assoc 41 anfo) anfo))
    (entmod anfo)
    (entupd anxt)
   );progn
   (princ "\nA Block was not Selected! ")
  );if
  (setq cnt (1+ cnt))
 );end while
 (setq cnt 0)
 (while (< cnt blen)
  (setq bnxt (ssname bset cnt))
  (setq bnfo (entget bnxt))
  (if (= (cdr (assoc 0 bnfo)) "INSERT")
   (progn
    (setq bnfo (subst (cons 2 an) (assoc 41 bnfo) bnfo))
    (entmod bnfo)
    (entupd bnxt)
   );progn
   (princ "\nA Block was not Selected! ")
  );if
  (setq cnt (1+ cnt))
 );end while
 (command "REGENAUTO" "On")
 (setvar "CMDECHO" 1)
 (setvar "OSMODE" osm)
 (prompt "\nBy Rob Herr   robherr@hotmail.com")(print)
)

TJAM51

  • Guest
Block and symbol replacement
« Reply #4 on: January 19, 2005, 08:31:31 AM »
Thanks guys....really appreciate it. On the MYBLOCK routine it keeps the orginal enities after the block is created. Is there anyway these could be erases and only the block kept?


Thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Block and symbol replacement
« Reply #5 on: January 19, 2005, 08:51:40 AM »
Code: [Select]
(defun c:myblock(/ ss pt)
  (prompt "\nSelect objects to make a block.")
  (setq ss (ssget))
  (if (and ss (> (sslength ss) 0))
    (progn
      (while
        (not (setq pt (getpoint "\nPlease select a base point: ")))
        (princ "\nPlease try again..."))
      (Command "_copybase" pt ss "")
      (command "._erase" ss "")
      (command "_pasteblock" pause)

    )
  )
  (princ)
)
(prompt "\nMyBlock loaded enter Myblock to run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Anonymous

  • Guest
Block and symbol replacement
« Reply #6 on: January 19, 2005, 09:47:59 AM »
The new routine does not want to erase the enities the block is created from.......

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Block and symbol replacement
« Reply #7 on: January 19, 2005, 09:54:51 AM »
Quote from: Anonymous
The new routine does not want to erase the enities the block is created from.......

Works here ACAD2000
Are the objects on a LOCKED layer?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BAshworth

  • Guest
Block and symbol replacement
« Reply #8 on: January 19, 2005, 10:09:09 AM »
Any reason to not just use the GROUP command?

ELOQUINTET

  • Guest
Block and symbol replacement
« Reply #9 on: January 19, 2005, 10:11:39 AM »
i like that cab niiiiice

Anonymous

  • Guest
Block and symbol replacement
« Reply #10 on: January 19, 2005, 10:15:45 AM »
I am using 2004 ADT. None of the layers were locked. For the group command that would be a great idea but I need the ability to actualluy use a routine called symbol replacement to accomplish my task....wish it were simple.....thanks

BAshworth

  • Guest
Block and symbol replacement
« Reply #11 on: January 19, 2005, 10:18:26 AM »
Quote from: Anonymous
I am using 2004 ADT. None of the layers were locked. For the group command that would be a great idea but I need the ability to actualluy use a routine called symbol replacement to accomplish my task....wish it were simple.....thanks


Oh, I misunderstood then.  I thought you were looking for two separate routines.  One to create the temporary block, and another to do the block replacement.  Didn't know you were looking for one, all inclusive routine.

Anonymous

  • Guest
Block and symbol replacement
« Reply #12 on: January 19, 2005, 10:20:28 AM »
For some reason it may be something in this drawing. I went to another drawing and it works fine.......??????? go figure....thanks guys