Redefining Block

Redefining Block

Geoffrey.ReynoldsSCCMH
Contributor Contributor
352 Views
3 Replies
Message 1 of 4

Redefining Block

Geoffrey.ReynoldsSCCMH
Contributor
Contributor

Hi All,

I've written a AutoLisp function to cycle blocks in a drawing, trying to find a match
in a specified folder. If a match is found then insert that block.

Usually if I were do this within Autocad using the INSERT command, it will trigger a "already defined in this this drawing" and then select "Redefine Block" which is what I want. 

Unfortunately I'm not getting that dialog or command box alert to do this. Below is the current code which is working fine, I'm just not getting the option to redefine. 

(defun c:RedefineMe()
  ; Get list of all blocks in drawing
   (setq block-refs nil)
  (setq block-names nil)
  (setq ent (entnext))
  (while ent
    (if (eq (cdr (assoc 0 (entget ent))) "INSERT")
        (setq block-refs (cons ent block-refs))
    )
    (setq ent (entnext ent))
  )
  (reverse block-refs)
    (foreach block-ref block-refs
		(setq block-name (cdr (assoc 2 (entget block-ref))))
		(if (not (member block-name block-names))
			(progn
			  (setq block-names (cons block-name block-names))
			  (princ "\n")
			  (setq dir "O:\\CAD Admin\\CAD Builds\\Company\\Symbols - Elec Schematic (A1)")
			  (setq file (strcat block-name ".dwg"))
			  (setq full-file-path (findfile (strcat dir "\\" file)))
			  (if full-file-path
				  (progn
					  (princ (strcat "Match found: " full-file-path))
					  (command "insert" full-file-path "0,0" "1" "0" "")
					  (princ "\n")
					  
				  )
			  )
			)
		)
	)
)

 
 

0 Likes
353 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor

This link should give you a clue but basically: insert blockname=dwgfilename

https://www.cadtutor.net/forum/topic/70950-redefining-blocks-when-inserting-into-a-drawing-from-a-bl...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 4

Geoffrey.ReynoldsSCCMH
Contributor
Contributor

Thanks 🙂

0 Likes
Message 4 of 4

paullimapa
Mentor
Mentor

You are welcome...cheers 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes