Message 1 of 14
Lisp to Fix Block scale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear All,
I am working on a code which can remove the scale factor from the block and make it 1,1,1.
For this, I have taken the following method
Used the scale factor of the block and then scaled the content of the block taking base point of the block as reference.(As to avoid shifting of the blocks)
Then reset the block scale factor to 1,1,1 for x , y , z.
The problem I am facing :
The code is correctly scaling the block, But the code is unable to correctly detect the base point of the block. And the block gets shifted from its location.
Help Need:
Kindly help to fix the code such that the block does not move from its location.
(defun c:FixBlocksScale_v2 (/ ss ent scX scY scZ insertionPoint scaleFactor)
;; Prompt the user to select block references
(setq ss (ssget '((0 . "INSERT")))) ;; Filter only block references (INSERT entities)
;; If selection is not empty, proceed
(if ss
(progn
;; Loop through all selected blocks
(setq i 0)
(while (< i (sslength ss))
;; Get the current block reference
(setq ent (ssname ss i))
;; Get the current X, Y, Z scale factors
(setq scX (cdr (assoc 41 (entget ent))))
(setq scY (cdr (assoc 42 (entget ent))))
(setq scZ (cdr (assoc 43 (entget ent))))
;; Get the insertion point of the block
(setq insertionPoint (cdr (assoc 10 (entget ent))))
;; Apply scaling to the block's contents using the current scale factor
(progn
;; Store the current uniform scale factor (use X scale factor)
(setq scaleFactor scX)
;; Scale the contents of the block
(command "BEDIT" (cdr (assoc 2 (entget ent)))) ;; Open block editor
(command "ZOOM" "E") ;; Zoom to extents in block editor
(command "SCALE" "ALL" "" insertionPoint scaleFactor) ;; Scale all objects
(command "BCLOSE" "SAVE") ;; Close and save block editor changes
;; Reset the block scale factor to 1,1,1 for X, Y, Z
(entmod (subst (cons 41 1.0) (assoc 41 (entget ent)) (entget ent))) ;; X scale to 1
(entmod (subst (cons 42 1.0) (assoc 42 (entget ent)) (entget ent))) ;; Y scale to 1
(entmod (subst (cons 43 1.0) (assoc 43 (entget ent)) (entget ent))) ;; Z scale to 1
;; Update the block entity in the drawing
(entupd ent)
)
;; Move to the next block in the selection set
(setq i (1+ i))
)
(prompt "\nAll selected blocks processed.")
)
(prompt "\nNo blocks were selected.")
)
(princ)
)
;; Open the block definition to get the base point
(setq blockName (cdr (assoc 2 (entget ent))))
(setq blockDef (tblsearch "BLOCK" blockName))
;; Retrieve the base point from the block definition
(setq basePoint (cdr (assoc 10 blockDef))) ;; Assuming the base point is stored as 10
;; Open the block editor and scale the contents using the base point
(command "BEDIT" blockName) ;; Open block editor
(command "ZOOM" "E") ;; Zoom to extents in block editor
;; Select all objects in the block
(command "SELECTALL")
;; Scale using base point and the current scale factors
(command "SCALE" "P" "" basePoint scX) ;; Scale using the X scale factor
(command "BCLOSE" "SAVE") ;; Close and save block editor changes
I used this part of this code to detect the basepoint of the block in the block.
But there was no luck.