Jump to content

Redefine blocks in drawing by re-inserting them from a folder


Recommended Posts

Posted (edited)

MyBlocks.zip

(defun c:foo ( / a1 a2 oldCMDECHO s r pt folderPath BlockNames oldEnt newEnt blk )
  (setq oldCMDECHO (getvar "CMDECHO")
        a1 (getvar "ATTDIA")
        a2 (getvar "ATTREQ")
        pt (list 0.0 0.0)
        s 0.5
        r 0.0)
  (setvar "CMDECHO" 0)
  (setvar "ATTDIA" 0)
  (setvar "ATTREQ" 0)

  (setq folderPath "C:/MyBlocks/" BlockNames (list "BLK1.dwg" "BLK2.dwg" "BLK3.dwg"))

  (setq oldEnt (entlast))

  (foreach blk BlockNames
    (setq blk (strcat folderPath blk))
    (command "_.-insert" blk pt s s r)
    (setq newEnt (entlast))
    (if (and newEnt (/= oldEnt newEnt))
      (entdel newEnt)
    )
  )

  (setvar "ATTDIA" a1)
  (setvar "ATTREQ" a2)
  (setvar "CMDECHO" oldCMDECHO)

  (princ "\nBlocks inserted successfully.")
  (princ)
)
Edited by DavidP
Attach Blocks
Posted (edited)

I have drawing with blocks some of which have be change by the drafters... I want to re-insert & redefine the blocks from a local folder.

What I'm I missing?  My blocks are Dynamic blocks.

Edited by DavidP
Added additional info
Posted

you may try to change:

(command "_.-insert" blk pt s s r)

(setq newEnt (entlast))

(if (and newEnt (/= oldEnt newEnt)) (entdel newEnt) )

to

(command "_.-insert" (strcat (vl-filename-base blk) "=" blk) pt)

(while (> (getvar "CMDACTIVE") 0) (command ""))

(entdel(entlast)) ; Delete the temp insert block

 

This will force AutoCAD to update a block from a drawing. you will need to make sure the block name is same as the DWG's name.

Since you are working wirth dynamic blocks, the safer way is to get the dynamic property values for each block reference before update it and apply the data back to blocks after the definition is updated, in case dynamic parameters may have been changed in definition.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...