+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Forum Newbie
    Discipline
    HVAC
    Using
    MEP 2018
    Join Date
    Oct 2017
    Posts
    8

    Exclamation Error Message: Too Few Arguments

    Registered forum members do not see this ad.

    So Im getting a "too few Arguments" error message and after debugging I still cant seem to find which line is causing this error. The function of this lisp is supposed to select a register bock [attached below]: create a list for each block selected based on the cfm values in its [cfm] attribute. if the value falls within a certain range then it should've selected the property sort value. any help would be much appreciated.
    Attached Files

  2. #2
    Forum Newbie
    Discipline
    HVAC
    Using
    MEP 2018
    Join Date
    Oct 2017
    Posts
    8

    Default

    silly me, Here's my code

    Code:
    (defun c:AS3 ( sel cfm  ) ;; Define function, declare local variables
        (if ;; If the following expression returns a non-nil value
            (setq sel ;; Assign the value returned by the following expression to the symbol 'sel'
                (ssget ;; Prompt the user to make a selection and return the selection set if successful
                   '((0 . "INSERT")) ;; Filter the selection to block references only (INSERTs)
                ) ;; end ssget
            ) ;; end setq
            (repeat ;; Repeat the enclosed expressions the following number of times:
                (sslength sel) ;; Return the number of items in the selection set
    		(foreach sel
    		(setq cfm (LM:Tag_Val "CFM"))
    		 (if
    		   (and
    		     (>= cfm 51)
    		     (<= cfm 0)
    		   )			;and
    		    (LM:reprop "sort" "01" sel)
    		    (princ "properly goes through reprop")
    		 )			;if
    		 (if
    		   (and
    		     (>= cfm 76)
    		     (<= cfm 52)
    		   )			;and
    		    (LM:reprop "sort" "02" sel)
    		 )			;if
    		 (if
    		   (and
    		     (>= cfm 121)
    		     (<= cfm 77)
    		   )			;and
    		    (LM:reprop "sort" "03" sel)
    		 )			;if
    		 (if
    		   (and
    		     (>= cfm 176)
    		     (<= cfm 122)
    		   )			;and
    		    (LM:reprop "sort" "04" sel)
    		 )			;if
    		 (if
    		   (and
    		     (>= cfm 177)
    
    		   )			;and
    		    (LM:reprop "sort" "05" sel)
    		 )
    		)
    	  
            ) ;; end repeat
        ) ;; end if
    ) ;; end defun
    
    
    (defun LM:reprop ( blk lst / itm )
        (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst))
        (foreach x (vlax-invoke blk 'getdynamicblockproperties)
            (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
                (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x))))
            )
        )
    )
    
    (defun LM:Tag_Val ( blk tag )
        (setq tag (strcase tag))
        (vl-some '(lambda (att) (if (= tag (strcase (vla-get-tagstring att))) (atoi (vla-get-TextString att)))) (vlax-invoke blk 'getattributes))
    )

  3. #3
    Full Member
    Using
    AutoCAD 2012
    Join Date
    Apr 2015
    Posts
    48

    Default

    Change your first line to this

    Code:
     
    
    (defun c:AS3 ( / sel cfm )
    Sent from my Pixel XL using Tapatalk

  4. #4
    Forum Newbie
    Discipline
    HVAC
    Using
    MEP 2018
    Join Date
    Oct 2017
    Posts
    8

    Default :?:

    Looks Like we're getting somewhere, the error break seems to be pointing to
    (setq cfm (LM:Tag_Val "CFM"))

    Though Im still wondering what Im not defining properly.




    Quote Originally Posted by dan113 View Post
    Change your first line to this

    Code:
     
    
    (defun c:AS3 ( / sel cfm )
    Sent from my Pixel XL using Tapatalk

  5. #5
    Full Member
    Using
    AutoCAD 2012
    Join Date
    Apr 2015
    Posts
    48

    Default

    You have a couple of mistakes I can see to start with, one you are only passing 1 variable to the tag_Val function, the other seems to be you have a repeat that loops the length of the selection set but then you have an incomplete foreach call. The foreach command requires 2 arguments. Also you cannot loop a selection set with foreach. A quick look further down you have quite a lot of if statements, try using a cond statement instead.

    Sent from my Pixel XL using Tapatalk

  6. #6
    Full Member
    Using
    AutoCAD 2012
    Join Date
    Apr 2015
    Posts
    48

    Default

    Try looping and testing like this

    Code:
    (Setq I -1)
    
    (While (setq ent (ssname as (setq I (1+ I))))
    
    ;Ent will need converting to an object before the following will work fully
    
    (setq val (LM:Tag_Val ent "CFM"))
    
    (Cond
    ;If
     ((= Val 1)
       ;;Do stuff
    )
     ;Else
    ((= Val 2)
      ;;Do stuff
    )
    ;Else
    ((=Val 3)
      ;Do stuff
    )
    );End cond
    );End while

  7. #7
    Forum Newbie
    Discipline
    HVAC
    Using
    MEP 2018
    Join Date
    Oct 2017
    Posts
    8

    Default

    So far so good; The code looks much cleaner and the "too few arguments" error is gone, but now I have a bad argument type: consp -1

    Code:
    (defun c:AS3 (/ val sel cfm)
      ;; Define function, declare local variables
      (if ;; If the following expression returns a non-nil value
          (setq sel	;; Assign the value returned by the following expression to the symbol 'sel'
    		(ssget ;; Prompt the user to make a selection and return the selection set if successful
    		       '
    			((0 . "INSERT"))
    		       ;; Filter the selection to block references only (INSERTs)
    		)
    		;; end ssget
          )
        ;; end setq
        (repeat ;; Repeat the enclosed expressions the following number of times:
    	    (sslength sel)
          ;; Return the number of items in the selection set
          (foreach sel
    		   (Setq I -1)
    
    	(While (setq ent (ssname as (setq I (1+ I))))
    
    					;Ent will need converting to an object before the following will work fully
    
    	  (setq val (LM:Tag_Val ent "CFM"))
    
    	  (Cond
    					;If
    	    ((>= val 51)
    	     (<= val 0)
    	     (LM:reprop "sort" "01" sel)
    	    )
    					;Else
    	    ((>= val 76)
    	     (<= val 52)
    	     (LM:reprop "sort" "02" sel)
    	    )
    					;Else
    	    ((>= val 121)
    	     (<= val 77)
    	     (LM:reprop "sort" "03" sel)
    	    )
    	    ((>= val 176)
    	     (<= val 122)
    	     (LM:reprop "sort" "04" sel)
    	    )
    	    ((>= val 177)
    	     (LM:reprop "sort" "05" sel)
    	    )
    	  )				;End cond
    	)				;End while
    
          )
          ;; end defun
    
    
          (defun LM:reprop (blk lst / itm)
    	(setq
    	  lst (mapcar '(lambda (x) (cons (strcase (car x)) (cdr x)))
    		      lst
    	      )
    	)
    	(foreach x (vlax-invoke blk 'getdynamicblockproperties)
    	  (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
    	    (vla-put-value
    	      x
    	      (vlax-make-variant
    		(cdr itm)
    		(vlax-variant-type (vla-get-value x))
    	      )
    	    )
    	  )
    	)
          )
    
          (defun LM:Tag_Val	(blk tag)
    	(setq tag (strcase tag))
    	(vl-some '(lambda (att)
    		    (if	(= tag (strcase (vla-get-tagstring att)))
    		      (atoi (vla-get-TextString att))
    		    )
    		  )
    		 (vlax-invoke blk 'getattributes)
    	)
          )
        )
      )
    )

  8. #8
    Full Member
    Using
    AutoCAD 2012
    Join Date
    Apr 2015
    Posts
    48

    Default

    You need to get rid of the repeat and for each parts as thee are taken care of by the while also put in (LM:tag_val (vlax-ename->vla-object ent) "CFM")) this is what I meant by the inline comment.

    Sent from my Pixel XL using Tapatalk

  9. #9
    Forum Newbie
    Discipline
    HVAC
    Using
    MEP 2018
    Join Date
    Oct 2017
    Posts
    8

    Default Alrighty

    Quote Originally Posted by dan113 View Post
    You need to get rid of the repeat and for each parts as thee are taken care of by the while also put in (LM:tag_val (vlax-ename->vla-object ent) "CFM")) this is what I meant by the inline comment.

    Sent from my Pixel XL using Tapatalk

    Sweet! My code is error free. Unfortunately, It only spits out an integer of -1.

    Code:
    (defun c:AS3 (/ ent val cfm)
      ;; Define function, declare local variables
      (if ;; If the following expression returns a non-nil value
          (setq ent	;; Assign the value returned by the following expression to the symbol 'sel'
    		(ssget ;; Prompt the user to make a selection and return the selection set if successful
    		       '
    			((0 . "INSERT"))
    		       ;; Filter the selection to block references only (INSERTs)
    		)
    		;; end ssget
          )
        ;; end setq
    
        (Setq I -1)
    
        (While (setq ent (ssname as (setq I (1+ I))))
    
          (setq val (LM:Tag_Val (vlax-ename->vla-object ent) "CFM"))
    
    
          (Cond
    					;If
    	((>= val 51)
    	 (<= val 0)
    	 (LM:reprop "sort" "01" ent)
    	)
    					;Else
    	((>= val 76)
    	 (<= val 52)
    	 (LM:reprop "sort" "02" ent)
    	)
    					;Else
    	((>= val 121)
    	 (<= val 77)
    	 (LM:reprop "sort" "03" ent)
    	)
    	((>= val 176)
    	 (<= val 122)
    	 (LM:reprop "sort" "04" ent)
    	)
    	((>= val 177)
    	 (LM:reprop "sort" "05" ent)
    	)
          )					;End cond
    
    
          (defun LM:reprop (blk lst / itm)
    	(setq
    	  lst (mapcar '(lambda (x) (cons (strcase (car x)) (cdr x)))
    		      lst
    	      )
    	)
    	(foreach x (vlax-invoke blk 'getdynamicblockproperties)
    	  (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
    	    (vla-put-value
    	      x
    	      (vlax-make-variant
    		(cdr itm)
    		(vlax-variant-type (vla-get-value x))
    	      )
    	    )
    	  )
    	)
          )
    
          (defun LM:Tag_Val	(blk tag)
    	(setq tag (strcase tag))
    	(vl-some '(lambda (att)
    		    (if	(= tag (strcase (vla-get-tagstring att)))
    		      (atoi (vla-get-TextString att))
    		    )
    		  )
    		 (vlax-invoke blk 'getattributes)
    	)
          )
        )
      )
    )

  10. #10
    Full Member
    Using
    AutoCAD 2012
    Join Date
    Apr 2015
    Posts
    48

    Default

    Registered forum members do not see this ad.

    try this

    Code:
    (defun c:AS3 (/ LM:reprop LM:Tag_Val ss i ent val cfm)
    
      (defun LM:reprop (blk lst / itm)
    	(setq
    	  lst (mapcar '(lambda (x) (cons (strcase (car x)) (cdr x)))
    		      lst
    	      )
    	)
    	(foreach x (vlax-invoke blk 'getdynamicblockproperties)
    	  (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
    	    (vla-put-value
    	      x
    	      (vlax-make-variant
    		(cdr itm)
    		(vlax-variant-type (vla-get-value x))
    	      )
    	    )
    	  )
    	)
          )
    
          (defun LM:Tag_Val	(blk tag)
    	(setq tag (strcase tag))
    	(vl-some '(lambda (att)
    		    (if	(= tag (strcase (vla-get-tagstring att)))
    		      (atoi (vla-get-TextString att))
    		    )
    		  )
    		 (vlax-invoke blk 'getattributes)
    	)
          )
      
      (if
        (setq ss (ssget '((0 . "INSERT"))))
    
        (progn
    
          (Setq I -1)
    
          (While (setq ent (ssname ss (setq i (1+ i))))
    
    	(setq val (LM:Tag_Val (vlax-ename->vla-object ent) "CFM"))
    
    
    	(Cond
    	  ;;If
    	  ((and
    	     (>= val 51)
    	     (<= val 0)
    	   )
    	   (LM:reprop "sort" "01" ent)
    	  )
    	  ;;Else
    	  ((and
    	     (>= val 76)
    	     (<= val 52)
    	   )
    	   (LM:reprop "sort" "02" ent)
    	  )
    	  ;;Else
    	  ((and
    	     (>= val 121)
    	     (<= val 77)
    	   )
    	   (LM:reprop "sort" "03" ent)
    	  )
    	  ;;Else
    	  ((and
    	     (>= val 176)
    	     (<= val 122)
    	   )
    	   (LM:reprop "sort" "04" ent)
    	  )
    	  ;;Else
    	  ((>= val 177)
    	   (LM:reprop "sort" "05" ent)
    	  )
    	  ;;Else
    	  (t (setq val "Out of bounds"))
    	)
    
    	;; This is where you can do what you ned to with the result
    	;; i have just printed it to the command line
    	;; you could add it to a list and/or export it
    	(print val)
          )
        )
        (alert "Nothing selected")
      )
    )

Similar Threads

  1. Too many arguments error
    By LosGirk in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 16th Oct 2014, 09:57 pm
  2. Error: Too few arguments ?
    By Xelathrone in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 3rd Apr 2014, 05:13 am
  3. Error: too few arguments
    By arunr_18 in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 20th Jul 2013, 09:49 pm
  4. ; error: too few arguments
    By satishrajdev in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 7th Feb 2013, 12:22 pm
  5. too many arguments error on lsp anyone know why
    By chelsea1307 in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 17th Jun 2009, 09:34 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts