- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been working to create a lisp to update all the lineweights in a drawing that are assigned to existing layers and existing objects (including objects contained in blocks), with different values. I have some code (see below) where I would like some expert advice, if I made a significant error even though it seems to work in my testing?
I'm currently reviewing a lot of AutoCAD DWG drawings (they tend to be very old) that are imported to/exported from Microstation DGN. These drawings aren't plotted based on color dependancy for lineweight assignments, nor are properties always assigned and controlled by layer. For example, hundreds of text objects on a TEXT layer may have independant object colors and lineweights.
I've had some excellent help and feedback with my other recent queries on this forum. Regarding this lineweight issue, I was able to compile my own lisp starting awhile back, but it only worked for layers and objects not confined in blocks. I started with SSGET functions (of which I was more familiar) for objects, then tried to learn about and apply VLA/VLAX to update the layers. I've decided to revisit the blocks issue when I saw examples of other code using the layers and blocks collection, and I thought I might be able to finally do this.
Please see my current code below. It's not fancy or efficient, but the best I could do on my own and right now I stripped it down just for testing. What really puzzles me is the unexpected outcome - the part of the code I thought would work only for blocks, actually seems to update all objects in the drawing, whether or not they are confined in blocks. Is this a "happy little accident"? I'm concerned that if it's a fluke, and the code isn't proper, could I run into problems in the future with different drawing files?
Thanks in advance for your feedback.
;;; --- BEGIN CODE
(vl-load-com)
(defun C:UpdateLwts ()
;; Cycle through all entities within a block
(vlax-for blk blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))
(vlax-for obj blk
(if (= (vla-get-Lineweight obj) 40) (vla-put-Lineweight obj 70)) ; if DGN 3
(if (= (vla-get-Lineweight obj) 30) (vla-put-Lineweight obj 50)) ; if DGN 2
(if (= (vla-get-Lineweight obj) 13) (vla-put-Lineweight obj 40)) ; if DGN 1
(if (= (vla-get-Lineweight obj) 5) (vla-put-Lineweight obj 25)) ; if DGN 0
(if (= (vla-get-Lineweight obj) 0) (vla-put-Lineweight obj 25)) ; if 0.00 mm
(if (= (vla-get-Lineweight obj) -3) (vla-put-Lineweight obj 25)) ; if Default
) ; end of vlax-for obj blk
) ; end of vlax-for blk blocks
;; Cycle through all layers in the drawing
(vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (= 40 (vla-get-Lineweight layer))(vla-put-Lineweight layer 70)) ; if DGN 3
(if (= 30 (vla-get-Lineweight layer))(vla-put-Lineweight layer 50)) ; if DGN 2
(if (= 13 (vla-get-Lineweight layer))(vla-put-Lineweight layer 40)) ; if DGN 1
(if (= 5 (vla-get-Lineweight layer))(vla-put-Lineweight layer 25)) ; if DGN 0
(if (= 0 (vla-get-Lineweight layer))(vla-put-Lineweight layer 25)) ; if 0.00 mm
(if (= -3 (vla-get-Lineweight layer))(vla-put-Lineweight layer 25)) ; if Default
) ; end of vlax-for layer
(princ)
); defun
Solved! Go to Solution.