Hey guys,
I'm new in this forum and l would need your help.
I'm using a blocklibrary, where I stored all my blocks, most of them have attributes.
Now I'd like to simplify my workflow and want to update the blocks that I inserted in a drawing trough LISP.
Is there a way to update all inserted blocks and attributes of the whole drawing a once? The idea is, that the LISP checks the whole blocklibrary and updates the inserted blocks that to not match with the once from the library.
thanks for your help!
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Is there anyway to modify this Routine for blocks within the current drawing rather than within a directory path?
This issue I have is that importing a drawing file ignores duplicate block definitions which I then have to force redefine by re-inserting the drawing and then running an attsync for the dynamic blocks to update.
Krazeymike,
Yes, untested, but should work. Just changed the 'dir to be (getvar "dwgprefix").
;; Posted: 09-13-2013 by Lee Mac
;; Redefine All Blocks - Lee Mac
;; Modified by ECCAD - 06-16-2024 for 'Krazeymike'
;; Changes:
;; Changed 'dir to be Current Folder
;;
(defun c:redefall ( / bln dir doc dwg lst obj org spc )
;;; (setq dir "I:\\AutoCAD Blöcke\\Template\\Support") ;; Directory of Block Library; nil to use Support Path
(setq dir (getvar "dwgprefix")); Includes the "\\" on the end.
(if dir
(setq dir (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)) "\\"))
(setq dir "")
)
(cond
( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
(princ "\nCurrent layer locked.")
)
( (setq doc (vla-get-activedocument (vlax-get-acad-object))
spc (vla-get-modelspace doc)
org (vlax-3D-point 0 0)
)
(terpri)
(vlax-for blk (vla-get-blocks doc)
(if
(and
(= :vlax-false (vla-get-isxref blk))
(= :vlax-false (vla-get-islayout blk))
(not (wcmatch (setq bln (vla-get-name blk)) "`**,*|*"))
)
(if (setq dwg (findfile (strcat dir bln ".dwg")))
(progn
(princ (strcat "Redefining block: " dwg "\n"))
(setq obj (vla-insertblock spc org dwg 1.0 1.0 1.0 0.0))
(if (= :vlax-true (vla-get-hasattributes obj))
(setq lst (vl-list* "," bln lst))
)
(vla-delete obj)
)
(princ (strcat "Unable to locate block: " dir bln ".dwg\n"))
)
)
)
(if lst
(progn
(princ "Synchronising attributes for redefined blocks...\n")
(vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst)))
)
)
(textscr)
(vla-regen doc acallviewports)
)
)
(princ)
)
(vl-load-com) (princ)
;; end of File
ECCAD
Thankyou for this,
Seems to work but when I import a DXF the block does not show at all even after running this command.
I still can't seem to find a way around having to re-insert the DXF to force Redefine for my current blocks to show.
I posted a video on this thread here so you can see what I mean.
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/please-help-with-lisp-for-dxf-import...
Thanks for your help
Your prior question:
"Is there anyway to modify this Routine for blocks within the current drawing rather than within a directory path?"
You didn't mention any dxf type files. Viewing your video, seems you can manually do what you need,
if it's a case of 'automating' those procedures, I wouldn't have a clue as how to do that, given the fact
that you are inserting a dxf that can have (many) blocks, and the Lisp I pointed you to, doesn't even
look for .dxf type of files. So, sorry, I cannot help.
ECCAD
Thanks for the reply ECCAD,
All my blocks are .dwg files. The issue is that we export a .dxf from the Survey Program (Magnet Office).
I have to essentially insert it twice to prompt the "Redefine Block" option.
Then after exploding I have to run an attsync on these blocks and set their scales back to one.
Just looking for an easier way that's all.
I thought "(Magnet Office)" had a export to dwg rather than DXF. Are you sure its not there. Ex Topcon employee.
Yes you're right that it does still have the export to dwg option.
However the drawing type doesn't seem to be the issue.
When exporting as dwg I still have to delete the import and then re-insert from recent blocks to "Redefine" it.
Otherwise the command line shows "Duplicate definition of block ignored".
It's these definitions that I want to redefine upon insert. Then attsync them and set their scales back to 1.
Maybe I'm going about it the wrong way.
The video I posted here is exactly the same no matter if I export a dxf or dwg from Magnet
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/please-help-with-lisp-for-dxf-import...
@krazeymike I make extensive changes to the Magnet dwg, one being to delete the Point_cross, what is probably easier is to replace this block with a new one using lisp. Say with invisible attributes. You can check if new block exists if not entmake so no need to read from another dwg. Then erase each Point_cross. The other is to make a COGO point of the point cross so no longer needed. Thats if your going to do stuff in CIV3D.
The image of the point_cross was always a bit over powering.
I changed some of the linetypes, convert civilcad blocks to bylayer properties, converted objects to Z=0, plus more.
If you post the block you want to use to replace Point_cross can do something for you.
The block is already in the "Sample Template Model.dwg" found here.
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/please-help-with-lisp-for-dxf-import...
It's named identically to the Magnet "POINT_CROSS".
So the Magnet.dxf is the vanilla POINT_CROSS and the Template has my custom version destined to overwrite it.
I have a few variations of this Point Cross drawing depending on what template we are using. So my method is always to superceed the Magnet block by redefining it in whichever template we import it into.
Some POINT_CROSS blocks are modified to display Z values and others simply for attribute data like point numbers etc.
Hopefully I've explained this properly 🙂 Thanks for the help
Maybe we should start moving replies over to the other thread 🙂
Can't find what you're looking for? Ask the community or share your knowledge.