Michaels Posted August 23, 2010 Share Posted August 23, 2010 Hello there, I wonder why this routine is not counting my blocks , (defun c:Bcount (/ Blk) (setq Blk (ssget "_x" '((0 . "BLOCK")))) (alert (strcat "You have :" (sslength Blk) "Blocks ..")) (princ) ) Any help. Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 23, 2010 Share Posted August 23, 2010 Hint: You need to be counting INSERTS, not blocks... a block is the definition, the insert is the 'block reference' a representation of the definition in the drawing. Also, you will need to allow for this: (sslength nil) Quote Link to comment Share on other sites More sharing options...
Michaels Posted August 23, 2010 Author Share Posted August 23, 2010 YES. great hint Lee. I modified it, but it gives me an error, ; error: bad argument type: stringp 12 Why is that please ? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 (edited) This may be what you need: (defun c:Bcount (/ Blk) (setq Blk (ssget "_x" '((0 . "[color=red]INSERT[/color]")))) (alert (strcat "You have :" [color=red](itoa [/color](sslength Blk)[color=red])[/color] "Blocks ..")) (princ) ) Edited August 23, 2010 by BlackBox Changed "BLOCK" to "INSERT" Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Or this, perhaps? (defun c:Bcount () (alert (strcat "You have :" [color=red](itoa [/color](sslength (ssget "_x" '((0 . "[color=red]INSERT[/color]"))))[color=red])[/color] "Blocks ..")) (princ) ) Quote Link to comment Share on other sites More sharing options...
Michaels Posted August 23, 2010 Author Share Posted August 23, 2010 That's perfect RenderMan. But don't forget to change the ((0 . "BLOCK")) TO '((0 . "INSERT")) as Lee indicated to Please. Many thanks. Quote Link to comment Share on other sites More sharing options...
Michaels Posted August 23, 2010 Author Share Posted August 23, 2010 Or this, perhaps? (defun c:Bcount () (alert (strcat "You have :" [color=red](itoa [/color](sslength (ssget "_x" '((0 . "[color=red]INSERT[/color]"))))[color=red])[/color] "Blocks ..")) (princ) ) All right, Nice one. Thank you so much. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Oooo... Sorry, sorry. It appears you're too late, as that has already been done, my friend! I noticed it right after posting, and quickly fixed accordingly. Cheers! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 All right, Nice one. Thank you so much. Glad I could contribute a small tid-bit. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 23, 2010 Share Posted August 23, 2010 Or this, perhaps? (defun c:Bcount () (alert (strcat "You have :" [color=red](itoa [/color](sslength (ssget "_x" '((0 . "[color=red]INSERT[/color]"))))[color=red])[/color] "Blocks ..")) (princ) ) Type (sslength nil) at the command line. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Type (sslength nil) at the command line. Okay... I must be missing something, Lee??? Command: (sslength nil) ; error: bad argument type: lselsetp nil Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Hint: You need to be counting INSERTS, not blocks... a block is the definition, the insert is the 'block reference' a representation of the definition in the drawing. Also, you will need to allow for this: (sslength nil) Okay... I must be missing something, Lee??? Command: (sslength nil) ; error: bad argument type: lselsetp nil Ohhh! I get it, now!!! Will re-write accordingly..... Quote Link to comment Share on other sites More sharing options...
Michaels Posted August 23, 2010 Author Share Posted August 23, 2010 Ohhh! I get it, now!!! Will re-write accordingly..... But I did not get yet. Could you rise it up please. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 23, 2010 Share Posted August 23, 2010 Think about what it means for no blocks to be found. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Ohhh! I get it, now!!! Will re-write accordingly..... Sorry, Michaels. In my haste, I may have led you astray with the combined alert-ssget combo. Doing so, precludes any error checking - limited as an IF statement may be, it is better than nothing! There still may be a better solution (Lee?), but this is certainly preferable over my earlier post: (defun c:Bcount (/ blockCount) [color=red](if [/color](setq blockCount (itoa (sslength (ssget "_x" '((0 . "INSERT")))))) (alert (strcat "You have : " blockCount " Blocks ...")) [color=red](alert "No Blocks Detected In Active Drawing. "))[/color] (princ)) ;_end defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 23, 2010 Share Posted August 23, 2010 Again I urge you to consider (sslength nil) Quote Link to comment Share on other sites More sharing options...
Michaels Posted August 23, 2010 Author Share Posted August 23, 2010 Either used routine when Blocks not found, or (sslength nil), the same outcome would come up. Command: bcount ; error: bad argument type: lselsetp nil Command: Command: (sslength nil) ; error: bad argument type: lselsetp nil Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Again I urge you to consider (sslength nil) Wow - I have been silly today. I know better! Of course, if there is no selection set (ss), then (sslength ss) = nil, which throws an error. (defun c:Bcount (/ ss) (if (setq ss (ssget "_x" '((0 . "INSERT")))) (alert (strcat "You have : " (itoa (sslength ss)) " Blocks ...")) (alert "No Blocks Detected In Active Drawing. ")) (princ)) ;_end defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 23, 2010 Share Posted August 23, 2010 Exactly - so we must allow for no blocks: i.e. ssget returning nil. EDIT: You got it Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 23, 2010 Share Posted August 23, 2010 Exactly - so we must allow for no blocks: i.e. ssget returning nil. EDIT: You got it Thanks for making me think it through, Lee! Quote Link to comment Share on other sites More sharing options...
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.