Jump to content

Error Message: Too Few Arguments


Shady_Potato

Recommended Posts

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.

10 X 8 Supply Register Sets.dwg

Link to comment
Share on other sites

silly me, Here's my 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))
)

Link to comment
Share on other sites

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.

 

 

 

 

Change your first line to this

 

 

(defun c:AS3 ( / sel cfm )

[/Code]

 

Sent from my Pixel XL using Tapatalk

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Try looping and testing like this

 


(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

Link to comment
Share on other sites

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 :unsure::lol:

 

(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)
)
     )
   )
 )
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

(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)
)
     )
   )
 )
)

Link to comment
Share on other sites

try this

 

(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")
 )
)

Link to comment
Share on other sites

The code is responding to the if and else statement which is a good sign. Unfortunately, Im getting out of bounds for every number of blocks in the selection.

However, If I delete

(t (setq val "Out of bounds"))

It prints out the Cfm values. That Is a completely good Sign that it does create the list of values, but I think it ignores the condition statement.

 

 

Thank you so much for helping me out, I really do appreciate your Input! Id give you kudos if I had any :lol:

Link to comment
Share on other sites

It's good to go through and work out what everything does. The cond statement is very common in lisp code you may also want to check out the vl-catch-all-apply command for error trapping

 

Sent from my Pixel XL using Tapatalk

Link to comment
Share on other sites

  • 4 weeks later...

update on the lisp,

 

as it turns out, the sort value was updating, but could not populate the attributes assigned to the block table. and then I came across a forum on this situation:

 

https://forums.autodesk.com/t5/dynamic-blocks/set-dynamic-block-properties-table-through-lisp-without-quot/td-p/3295893

 

Once I messed with the cell value settings and checkboxed to match each row, then I was able to make the lisp work. Woot!

here's the final code:

 

(defun C:cfm ( / LM:reprop LM:Tag_Val findrange SS i o val )

 (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))
 )

 (setq findrange
   (lambda (v L)
     (if (and (numberp v) (listp L))
       (vl-some 
         '(lambda (x / mn mx) 
           (setq mn (caar x)) 
           (setq mx (cadar x)) 
           (if (apply '<= (append (if mn (list mn)) (list v) (if mx (list mx)) )) 
             (cadr x)
           ); if
         ); lambda
         L
       ); vl-some
     ); if 
   ); lambda (v L)
 ); setq findrange

 (if (setq SS (ssget '((0 . "INSERT"))))
   (repeat (setq i (sslength SS))
     (and (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
       (setq val (LM:Tag_Val o "CFM"))
       (setq val 
         (findrange val
           '(
             ( (0 51) "01")
             ( (52 76) "02")
             ( (77 121) "03")
             ( (122 176) "04")
             ( (177 nil) "05")
           )
         )
       )
       (LM:reprop o (list (cons "sort" val)))
     ); and
   ); repeat
 ); if SS
 (princ)
); defun C:cfm

Link to comment
Share on other sites

  • 2 years later...

 

 

 

Please, help me with this program to toggle multiple wire numbers.

Error: too few arguments…

Private Sub ToggleWireNum()

Dim x As AcadEntity

Dim blk As AcadBlock

On Error Resume Next

For Each x In ThisDrawing.ModelSpace

    If TypeName(x) = "IAcadLine" Then

        ThisDrawing.SetVariable "USERS1", x.Handle

        WDCommand ("(setq return (c:ace_get_wnum (handent (getvar ""USERS1""))))" & vbCr)

        WDCommand ("(setvar ""USERS2"" (car return))" & vbCr)

        If Len(ThisDrawing.GetVariable("USERS2")) > 0 Then

            WDCommand ("(setq en (cadr return))" & vbCr)

            WDCommand ("(c:ace_toggle_inline en)" & vbCr)

        End If

    End If

Next x

End Sub

Public Sub WDCommand(Command As String)

' This function calls lisp function

ThisDrawing.SendCommand (Command)

End Sub

Public Sub WDForceStart()

Call WDCommand("(if(not wd_load)(if(setq x(findfile ""wd_load.lsp""))(load x)))(wd_load)" & vbCr)

End Sub

 

Link to comment
Share on other sites

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