CadFrank Posted July 26, 2011 Author Posted July 26, 2011 (edited) Hi i arrived at work and this is error accured when i tried using the routine you gave me everything was good but now it isnt working and i dont know why i haven't done anything different. BLOCK COUNT: DYNAMIC ; error: Automation Error. Calling method AddItems of interface IAcadSelectionSet failed i don't know if it's because i have to many different dynamic block or that i would need to make a Sync of some sort. Anyways if you would help me out again could be appreciated. Thank you! Edited July 26, 2011 by CadFrank Quote
BlackBox Posted July 26, 2011 Posted July 26, 2011 This *may* be happening as a result of your attempting to run the command prior to the drawing being initialized (read prior to you selecting something, or clicking in model space). Give this a read for more information. HTH Quote
CadFrank Posted July 26, 2011 Author Posted July 26, 2011 Hi i have removed the process of opening the command prior now it gives me this BLOCK COUNT: DYNAMIC ; error: bad argument type for compare: "CLAMP PLAN (WN)" 937.796 BLOCK COUNT: DYNAMIC ; error: bad argument type for compare: "CLAMP PLAN (NN)" 937.796 clearly i don't understand what they mean Quote
Lee Mac Posted July 26, 2011 Posted July 26, 2011 Renderman, A tip: AFAIK, the first dynamic block property is not always going to be the Visibility State. Quote
Tharwat Posted July 26, 2011 Posted July 26, 2011 One more error here . BLOCK COUNT: DYNAMIC ; error: bad argument type for compare: 320.0 "Maximum" Quote
pBe Posted July 26, 2011 Posted July 26, 2011 (edited) I encountered the same problem once or twice, i modified the code a bit (like LM suggested) (defun c:BCD () (c:BlockCountDynamic)) ;;; RenderMan ;;; (defun c:BlockCountDynamic ( / ss item val valList) (vl-load-com) (princ "\rBLOCK COUNT: DYNAMIC ") (if (setq ss (ssget "_x" (list '(0 . "INSERT") '(2 . "`*U*") (cons 410 (getvar 'ctab))))) (progn (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))) (if (and (= :vlax-true (vla-get-isdynamicblock x)) [color=blue](setq val (vl-remove-if-not '(lambda (x) (eq (vla-get-PropertyName x) "Visibility")) (vlax-invoke x 'getdynamicblockproperties))) (setq val (vlax-get (car val) 'value))) [/color] (if (setq item (assoc val valList)) (setq valList (subst (cons val (1+ (cdr item))) item valList)) (setq valList (cons (cons val 1) valList))))) (foreach item (vl-sort valList '(lambda (x y) (< (car x) (car y)))) (prompt (strcat "\n >> " (car item) " Total = " (rtos (cdr item) 2 0)))) (vla-delete ss)) (prompt "\n** Nothing selected ** ")) (textscr) (princ)) Not sure if it works for you EDIT: Once more Frank Edited July 26, 2011 by pBe Quote
CadFrank Posted July 26, 2011 Author Posted July 26, 2011 Originally Posted by pBe I encountered the same problem once or twice, i modified the code a bit (like LM suggested) well i tried adding your code and it give me a different error BLOCK COUNT: DYNAMIC ; error: bad argument type: VLA-OBJECT nil Quote
pBe Posted July 26, 2011 Posted July 26, 2011 Post updated I paste the code in its entirety.. try it again EDIT: just a thought: close your drawing and try the code. chances are when the program crash the variable SS messed up and causing the error. (thats for the first error anway) PS: its not my code. its rendermans' Quote
CadFrank Posted July 26, 2011 Author Posted July 26, 2011 well it gives me the same error as the post 29. clearly my dynamic blocks just dont want to be counted Quote
pBe Posted July 26, 2011 Posted July 26, 2011 Thats because one of your many dynamic blocks doesnt have "VISIBILTY" property..... just a guess EDIT: Post updated (in blue color) Quote
Lee Mac Posted July 26, 2011 Posted July 26, 2011 (edited) Give this a try CADFrank: (defun c:dbcount ( / _Assoc++ _PadBetween lst prp ss ) ;; © Lee Mac 2011 (defun _Assoc++ ( key alist ) ( (lambda ( pair ) (if pair (subst (cons key (1+ (cdr pair))) pair alist) (cons (cons key 1) alist) ) ) (assoc key alist) ) ) (defun _PadBetween ( s1 s2 ch ln ) ( (lambda ( a b c ) (repeat (- ln (length b) (length c)) (setq c (cons a c))) (vl-list->string (append b c)) ) (ascii ch) (vl-string->list s1) (vl-string->list s2) ) ) (if (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'CTAB)))) (progn (vlax-for obj (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (and (eq :vlax-true (vla-get-isdynamicblock obj)) (setq prp (car (vl-member-if (function (lambda ( a ) (and (setq a (vlax-get a 'allowedvalues)) (listp a) (vl-every '(lambda ( b ) (eq 'STR (type b))) a) ) ) ) (vlax-invoke obj 'getdynamicblockproperties) ) ) ) ) (setq lst (_Assoc++ (vlax-get prp 'value) lst)) ) ) (vla-delete ss) (princ (_PadBetween "\nVisibility State" "Count" "." 41)) (princ (_PadBetween "\n" "" "=" 41)) (foreach x (vl-sort lst '(lambda ( a b ) (< (car a) (car b)))) (princ (_PadBetween (strcat "\n" (car x)) (itoa (cdr x)) "." 41)) ) (textpage) ) ) (princ) ) (vl-load-com) (princ) Edited July 26, 2011 by Lee Mac Add Sort, Replaced '_PadBetween' function for faster, iterative version, added (textpage) Quote
BlackBox Posted July 26, 2011 Posted July 26, 2011 I am still unsure what is causing the listed errors. However, after some minor revisions, and multiple tests (using the OP's block), and accounting for the Visibility state potentially not being the first dynamic block property, I have come to a successful result (on my end): Command: bcd BLOCK COUNT: DYNAMIC Total: Visibility state: 3 >> LU CADRE PLAN (2) 2'-6" 10 >> LU CADRE PLAN (2) 5'-4" 1 >> LU CADRE PLAN (4) 3'-7" 1200 >> LU CADRE PLAN (4) 9'-5" 6 >> LU CADRE PLAN 1'-0" Command: You can find the revised code here. Quote
Lee Mac Posted July 26, 2011 Posted July 26, 2011 However, after some minor revisions, and multiple tests (using the OP's block), and accounting for the Visibility state potentially not being the first dynamic block property, I have come to a successful result (on my end) Note that a Visibility State property may not always be called 'Visibility', or even contain that phrase. :wink: Quote
BlackBox Posted July 26, 2011 Posted July 26, 2011 Note that a Visibility State property may not always be called 'Visibility', or even contain that phrase. :wink: I leave this to your capable hands then... In my limited experience, that has never been an issue. I really did not plan on putting in this much effort. I was simply trying to help CADFrank out, and simply do not have the time to incorporate a contingency for every little thing. Thankfully, you've provided a great example for me to learn from. Edit: Thanks for the feedback, Lee. Cheers! Quote
CadFrank Posted July 26, 2011 Author Posted July 26, 2011 Well cheers to both of you they both work in the end. In do time after reading my book i might be able to help out but for now i am very gratefull. Thanks alot for your time RenderMan even if you might of not had the time well it is a succes. Even the command prompt opens with succes. Lee well thanks also for you help on your side.. cheers ! Quote
Lee Mac Posted July 26, 2011 Posted July 26, 2011 I leave this to your capable hands then... In my limited experience, that has never been an issue. I really did not plan on putting in this much effort. I was simply trying to help CADFrank out, and simply do not have the time to incorporate a contingency for every little thing. Thankfully, you've provided a great example for me to learn from. Edit: Thanks for the feedback, Lee.: No worries Renderman I don't program for Dynamic Block Properties too often so there are still many things I too have to learn in this area, but I believe each dynamic property type cannot be determined solely by the property name; I would say this is somewhat analogous to trying to determine whether a standard attribute has multiple lines, or is invisible for example, merely from the tag name. The difference (and difficulty) being that dynamic block properties don't have additional properties such as the 'MTextAttribute' property or the 'Invisible' property, so one must find other ways to distinguish between them. Glad I could shed some light, Lee Quote
Lee Mac Posted July 26, 2011 Posted July 26, 2011 You can find the revised code here. Sorry to nitpick, but one more thing I noticed: Since Dynamic Blocks only become anonymous when the visibility state is changed, your ssget filter list may miss those blocks which have been inserted but whose properties haven't been altered. :wink: Quote
CadFrank Posted July 26, 2011 Author Posted July 26, 2011 just another question like that and i only want the answer no code if i would like for some dynamic blocks not to be count would they be a possible way of doing it even so they are in the drawing. 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.