Jump to content

Recommended Posts

Posted (edited)

After entering the scaling factor, the code returns an error:

; error: invalid argument type: numberp: nil

(defun c:SclCrQuadr ( / quadrant ss scl ent elst center radius basePt )

  (prompt "\nSelect the quadrant to scale [Upper/Bottom/Right/Left]: ")
  (setq quadrant (getstring))  

  (setq quadrant (substr (strcase quadrant) 1 1))

  (prompt "\nSelect the circles to scale...")
  (setq ss (ssget '((0 . "CIRCLE"))))
  (if (not ss)
    (progn
      (prompt "\nNo circles are selected. Interruption.\n")
      (exit)
    )
  )

  (setq scl (getreal "\nEnter the scaling factor: "))
  (if (not scl)
    (progn
      (prompt "\nScaling factor is not set. Interruptionе.\n")
      (exit)
    )
  )

    (repeat (setq i (sslength ss))
    (setq ent   (ssname ss (setq i (1- i)))) 
          elst  (entget ent)                 
          center (cdr (assoc 10 elst))       
          radius (cdr (assoc 40 elst))       
    )

      (cond
      
      ((= quadrant "U") (setq basePt (list (car center) (+ (cadr center) radius))))
      
      ((= quadrant "B") (setq basePt (list (car center) (- (cadr center) radius))))
      
      ((= quadrant "R") (setq basePt (list (+ (car center) radius) (cadr center))))
      
      ((= quadrant "L") (setq basePt (list (- (car center) radius) (cadr center))))
      (T (progn
           (prompt "\nAn incorrect quadrant has been entered. Interruption.\n")
           (exit)
         )
      )
    )

      (command "_.SCALE" ent "" basePt scl)
 
  (prompt "\nScaling is completed.\n")
  (princ)
)

How can this be fixed? Thank ...

 

quadrants.png

Edited by Nikon
Posted (edited)

The first obvious problem is this first line.

You close the bracket for setq at the end of line 1.

This means that the rest of the lines don't do setq.

So elst, radius, center do not get set

 

		(setq ent   (ssname ss (setq i (1- i)))) 
			  elst  (entget ent)                 
			  center (cdr (assoc 10 elst))       
			  radius (cdr (assoc 40 elst))       
		)

 

 

--------

 

I removed that bracket.

And put it way down below the code.  That bracket now closes the repeat loop.

 

(defun c:SclCrQuadr ( / i quadrant ss scl ent elst center radius basePt )

  (prompt "\nSelect the quadrant to scale [Upper/Bottom/Right/Left]: ")
  (setq quadrant (getstring))  

  (setq quadrant (substr (strcase quadrant) 1 1))

  (prompt "\nSelect the circles to scale...")
  (setq ss (ssget '((0 . "CIRCLE"))))
  (if (not ss)
    (progn
      (prompt "\nNo circles are selected. Interruption.\n")
      (exit)
    )
  )

  (setq scl (getreal "\nEnter the scaling factor: "))
  (if (not scl)
    (progn
      (prompt "\nScaling factor is not set. Interruptionе.\n")
      (exit)
    )
  )

    (repeat (setq i (sslength ss))

		(setq ent   (ssname ss (setq i (1- i)))
			  elst  (entget ent)                 
			  center (cdr (assoc 10 elst))       
			  radius (cdr (assoc 40 elst))       
		)			  
		
		(cond
		  
		  ((= quadrant "U") (setq basePt (list (car center) (+ (cadr center) radius))))
		  
		  ((= quadrant "B") (setq basePt (list (car center) (- (cadr center) radius))))
		  
		  ((= quadrant "R") (setq basePt (list (+ (car center) radius) (cadr center))))
		  
		  ((= quadrant "L") (setq basePt (list (- (car center) radius) (cadr center))))
		  (T (progn
			   (prompt "\nAn incorrect quadrant has been entered. Interruption.\n")
			   (exit)
			 )
		  )
		)
		(princ "*")
        (command "_.SCALE" ent "" basePt scl)
		
    )   ;; Her is where the repeat must end
 
  (prompt "\nScaling is completed.\n")
  (princ)
)

 

Edited by Emmanuel Delay
  • Like 1
Posted
44 minutes ago, Emmanuel Delay said:

I removed that bracket.

And put it way down below the code. That bracket now closes the repeat loop.

Thanks a lot, it's working the way it should now!

  • Like 1
Posted

Is it possible to add the ability to scale circles and text inside them together to this code?

Text - circle.png

Posted
On 2/5/2025 at 12:27 PM, Nikon said:

Is it possible to add the ability to scale circles and text inside them together to this code?

The code added a selection of objects inside the circle for joint scaling, but there is an error...

; error: no function definition: CIRCLE->POLYGON

Please help me find the error. Thank...

(defun c:SclCircQuadrObj (/ quadrant ss scl ent elst center radius basePt i ssInside polyPts)

(defun circle->polygon (cen rad / i N ang x y ptlst)
    (setq N  36                
          i  0
          ptlst '()
    )
    (while (< i N)
      (setq ang (* 2.0 pi (/ i (float N))))
            x   (+ (car cen) (* rad (cos ang)))
            y   (+ (cadr cen) (* rad (sin ang))))
      (setq ptlst (append ptlst (list (list x y))))
      (setq i (1+ i))
    )
    (setq ptlst (append ptlst (list (car ptlst))))
    ptlst
  )

  (prompt "\nSelect the quadrant to scale [Upper/Bottom/Right/Left]: ")
  (setq quadrant (getstring))    

  (setq quadrant (substr (strcase quadrant) 1 1))  
  
  (prompt "\nnSelect the circles to scale...")
  (setq ss (ssget '((0 . "CIRCLE"))))
  (if (not ss)
    (progn
      (prompt "\nNo circles are selected. Interruption.\n")
      (exit)
    )
  )

  (setq scl (getreal "\nEnter the scaling factor: "))
  (if (not scl)
    (progn
      (prompt "\nScaling factor is not set. Interruption?.\n")
      (exit)
    )
  )
  
  (setq i (sslength ss))
  (while (> i 0)
    (setq i (1- i))

  
    (setq ent   (ssname ss i)
          elst  (entget ent)
          center (cdr (assoc 10 elst))  
          radius (cdr (assoc 40 elst))  
    )
   
    (cond
      
      ((= quadrant "U") (setq basePt (list (car center) (+ (cadr center) radius))))    
      ((= quadrant "B") (setq basePt (list (car center) (- (cadr center) radius))))      
      ((= quadrant "R") (setq basePt (list (+ (car center) radius) (cadr center))))      
      ((= quadrant "L") (setq basePt (list (- (car center) radius) (cadr center))))
      (T (progn
           (prompt "\nAn incorrect quadrant has been entered. Interruption.\n")
           (exit)
         )
      )
    )
   
    (setq polyPts (circle->polygon center radius))      
    (setq ssInside (ssget "_WP" polyPts))    
    (setq ssInside (cond
                     (ssInside (ssadd ent ssInside))  
                     (t        (ssadd ent))           
                   )
    )
   
    (command "_.SCALE" ssInside "" basePt scl)
  ) ;; end while
  (prompt "\nScaling is completed.\n")
  (princ)
)

 

Posted

I think you have an extra parenthesis after '... (* rad (without ang))))'
There should be 3 parentheses, not 4

  • Thanks 1
Posted
3 hours ago, GLAVCVS said:
I think you have an extra parenthesis after '... (* rad (without ang))))'''


There should be 3 parentheses, not 4

Unfortunately, it gives an error again.
; error: invalid list of points

Posted

 

There is some other parentheses misplaced in the 'circle->polygon' function.

 

(defun circle->polygon (cen rad / i N ang x y ptlst)
    (setq N 36
	  i 0
	  ptlst	'()
    )
    (while (< i N)
      (setq ang	(* 2.0 pi (/ i (float N)))
	    x
		(+ (car cen) (* rad (cos ang)))
	    y
		(+ (cadr cen) (* rad (sin ang)))
      )
      (setq ptlst (append ptlst (list (list x y))))
      (setq i (1+ i))
    )
    (setq ptlst (append ptlst (list (car ptlst))))
    ptlst
  )

 

  • Like 1
Posted

You can find these errors with the Visual Lisp debugger.
Don't you use it?

  • Thanks 1
Posted
23 minutes ago, GLAVCVS said:
You can find these errors with the Visual Lisp debugger.

Don't you use it?

I thought that the error might be in the function, I checked the closing brackets, but found nothing.

Thanks a lot for your help, now the code scales circles with objects inside.

Here is the corrected code:

(defun c:SclCircQuadrObject (/ quadrant ss scl ent elst center radius basePt i ssInside polyPts)

(defun circle->polygon (cen rad / i N ang x y ptlst)
 (setq N 36
 i 0
 ptlst '()
 )
 (while (< i N)
 (setq ang (* 2.0 pi (/ i (float N)))
 x
 (+ (car cen) (* rad (cos ang)))
 y
 (+ (cadr cen) (* rad (sin ang)))
 )
 (setq ptlst (append ptlst (list (list x y))))
 (setq i (1+ i))
 )
 (setq ptlst (append ptlst (list (car ptlst))))
 ptlst
 )

 (prompt "\nSelect the quadrant to scale [Upper/Bottom/Right/Left]: ")
 (setq quadrant (getstring)) 

 (setq quadrant (substr (strcase quadrant) 1 1)) 
 
 (prompt "\nnSelect the circles to scale...")
 (setq ss (ssget '((0 . "CIRCLE"))))
 (if (not ss)
 (progn
 (prompt "\nNo circles are selected. Interruption.\n")
 (exit)
 )
 )

 (setq scl (getreal "\nEnter the scaling factor: "))
 (if (not scl)
 (progn
 (prompt "\nScaling factor is not set. Interruption?.\n")
 (exit)
 )
 )
 
 (setq i (sslength ss))
 (while (> i 0)
 (setq i (1- i))

 
 (setq ent (ssname ss i)
 elst (entget ent)
 center (cdr (assoc 10 elst)) 
 radius (cdr (assoc 40 elst)) 
 )
 
 (cond
 
 ((= quadrant "U") (setq basePt (list (car center) (+ (cadr center) radius)))) 
 ((= quadrant "B") (setq basePt (list (car center) (- (cadr center) radius)))) 
 ((= quadrant "R") (setq basePt (list (+ (car center) radius) (cadr center)))) 
 ((= quadrant "L") (setq basePt (list (- (car center) radius) (cadr center))))
 (T (progn
 (prompt "\nAn incorrect quadrant has been entered. Interruption.\n")
 (exit)
 )
 )
 )
 
 (setq polyPts (circle->polygon center radius)) 
 (setq ssInside (ssget "_WP" polyPts)) 
 (setq ssInside (cond
 (ssInside (ssadd ent ssInside)) 
 (t (ssadd ent)) 
 )
 )
 
 (command "_.SCALE" ssInside "" basePt scl)
 ) ;; end while
 (prompt "\nScaling is completed.\n")
 (princ)
)


 

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