Shady_Potato Posted October 11, 2017 Posted October 11, 2017 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 Quote
Shady_Potato Posted October 11, 2017 Author Posted October 11, 2017 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)) ) Quote
dan113 Posted October 11, 2017 Posted October 11, 2017 Change your first line to this (defun c:AS3 ( / sel cfm )[/Code] Sent from my Pixel XL using Tapatalk Quote
Shady_Potato Posted October 11, 2017 Author Posted October 11, 2017 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 Quote
dan113 Posted October 11, 2017 Posted October 11, 2017 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 Quote
dan113 Posted October 11, 2017 Posted October 11, 2017 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 Quote
Shady_Potato Posted October 11, 2017 Author Posted October 11, 2017 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 (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) ) ) ) ) ) Quote
dan113 Posted October 12, 2017 Posted October 12, 2017 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 Quote
Shady_Potato Posted October 12, 2017 Author Posted October 12, 2017 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) ) ) ) ) ) Quote
dan113 Posted October 13, 2017 Posted October 13, 2017 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") ) ) Quote
Shady_Potato Posted October 13, 2017 Author Posted October 13, 2017 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 Quote
dan113 Posted October 13, 2017 Posted October 13, 2017 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 Quote
Shady_Potato Posted October 13, 2017 Author Posted October 13, 2017 you have definitely Enlightened me thus far my dude Quote
Shady_Potato Posted November 9, 2017 Author Posted November 9, 2017 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 Quote
asos2000 Posted November 13, 2017 Posted November 13, 2017 Taka a look at this http://lee-mac.com/errormessages.html Hassan Quote
AndySkur Posted April 28, 2020 Posted April 28, 2020 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 Quote
BIGAL Posted April 28, 2020 Posted April 28, 2020 You should have posted in the VBA section, side note "IAcadLine" I don't think is correct. Moderator may move. Quote
Recommended Posts
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.