Jump to content

Dynamic blocks losing grips when scaled using AutoLISP


Recommended Posts

Posted

Hi,

 

I have created some code that enables me to zoom to a specified area, and then scale all the blocks by an amount defined by an equation. The problem is that sometimes the blocks lose their dynamic grips when they are scaled a large amount. I think that what is happening is that they are getting scaled a slightly different amount in each direction, and this is causing the grips to disappear. If I select the blocks and set their scale to the same value it already has using the properties window the grips return.

 

Can anybody suggest any fixes to the below code to prevent this strange behaviour? I am new at AutoLisp, so any help would be appreciated.

 

Thanks.

 

(defun C:SZ()
 (setq firstPoint (getpoint "\nSelect Area: "))            ; Select Area Of Interest    
 (setq secondPoint (getcorner "\nKeep Going: " firstPoint))
 
 (command "._ZOOM" "W" firstPoint secondPoint)                ; Zoom to AOI
 
 (setq planDist (- (nth 1 secondPoint) (nth 1 firstPoint)))        ; Get the height of the AOI
 (if (> 0 planDist)                            ; If the height is negative, make it positive
   (setq planDist (* -1 planDist))
 ) ; end if
 
 (setq iconScale (+(* 0.000021 planDist) 0.2727))            ; Equation that scales the icons by the height of the AOI
 
 (setq iconScaleStr (rtos iconScale 2 3))                ; Print some info to the screen
 (setq planDistStr (rtos planDist 2 3))
 (print (strcat "Icon Scale is: " iconScaleStr " times the original (2000mm) and Plan Height is: " planDistStr "mm"))

 (QS)                                    ; Call the quick scale tool
)

(defun QS()
 (command "._UNDO" "Begin")                        ; Set Undo Group start
 (setq count 0)                            ; Initialise count variable
 
 (setq sSet (ssget "X" '((0 . "INSERT"))))                ; Create a selection set from all blocks in the database
 
 (setq sLeng (sslength sSet))                        ; Get the length of the selection set
 
 (while (< count sLeng)                        ; While the count is less than the number of objects:
   (setq entName (ssname sSet count))                    ; Set entname to the ssname of the object in the sset indexed by count
   
   (setq oldScale (cdr (assoc 41 (entget entName))))            ; Get the scale from the current object
   (setq insertPoint (cdr (assoc 10 (entget entName))))        ; Get the insert point
   (command "._SCALE" entname "" insertPoint "REF" oldScale iconScale)    ; Scale the block using ref, the old scale and the new scale

   (setq count (+ 1 count))                        ; Increment the count
 )    ; end while
 (command "._UNDO" "End")                        ; Set Undo Group end
)    

Posted

one remedy for this during block creation check the option for scaling uniformly or if the block is already existing go to the block editor space of the block then properties>set "yes" the scaling uniformly property.

Posted

Yeah, they are all set to scale uniformly. It seems strange that the scale in the properties for the block is correct, and shows the same value for X,Y & Z (to two decimal places), but the grips are gone. When I check the properties of the block using entget, it seems like the scales are all the same! Then, when I enter the same value into the X scale (because the blocks are set to scale uniformly the others are blanked out), the grips reappear.

Posted
Yeah, they are all set to scale uniformly. It seems strange that the scale in the properties for the block is correct, and shows the same value for X,Y & Z (to two decimal places), but the grips are gone. When I check the properties of the block using entget, it seems like the scales are all the same! Then, when I enter the same value into the X scale (because the blocks are set to scale uniformly the others are blanked out), the grips reappear.

Your codes seems ok. Try checking your precision settings. Set them to 12. If your setting is a bit low like 4, It could miss important decimal places like your 0.000021 value could be read as 0.00002 only.

  • 1 month later...
Posted

You may like this routine, i was just checking posts, found yours and its similar to this command... check it out..

 

This routine Updates selected blocks (normal blocks, blocks with attributes and dynamic blocks) to current dimscale. It may help you when working with blocks and dynamic blocks

 

;;; BXY by David Harrington; Modified by Paulo Gil Soto (added annotation scale reset to 1:1)
;;; updates selected blocks x,y and z values to current Dimscale
;;;
;;; Main Program
;;;
(defun c:Bu (/ ss xs ys zs num x na lst editxyz_error olcmdecho old_err) 
(defun editxyz_error (msg) 
 (if (or
   (= msg "Function cancelled")
   (/= msg "quit / exit abort")
  ) 
  (princ (strcat "Error: " msg))
 ) 
 (command ".UNDO" "E" "UNDO" "") 
 (setq *error*  old_err
    old_err  nil
 )
 (setvar "CMDECHO" olcmdecho)
 (princ)
) 
(setq old_err *error* 
   olcmdecho (getvar "CMDECHO")
   *error* editxyz_error
) 
(setvar "CMDECHO" 0)
       (setq dms (getvar "dimscale"))
(command ".UNDO" "BE")  (prompt "\nSelect Blocks to match current dimscale: ")
(cond
 ((setq ss (ssget '((0 . "INSERT"))))
        (command "-objectscale" ss "" "add" "1:1" "" "cannoscale" "1:1") 
  (setq num (sslength ss))
  (setq x 0)
  (repeat num 
   (setq na (ssname ss x)) 
   (setq lst (entget na))
   (setq lst (subst (cons 41 dms) (assoc 41 lst) lst))
   (setq lst (subst (cons 42 dms) (assoc 42 lst) lst))
   (setq lst (subst (cons 43 dms) (assoc 43 lst) lst))
   (entmod lst) 
   (entupd na) 
   (setq x (+ x 1))
  )
 )
)
(command "attsync" "name" "*")
       (command ".UNDO" "E") 
(setq *error* old_err)
(setvar "CMDECHO" olcmdecho)
(princ)
)

Posted

I have the same problem with my dynamic blocks. And I'm only scaling it manually, not with any lisp.:( Still don't know if there's a fix.

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...