Jump to content

Recommended Posts

Posted

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

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • BlackBox

    13

  • Lee Mac

    10

  • Michaels

    8

  • David Bethel

    3

Top Posters In This Topic

Posted

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)

Posted

YES. great hint Lee.

 

I modified it, but it gives me an error,

 

; error: bad argument type: stringp 12

 

Why is that please ?

Posted (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 by BlackBox
Changed "BLOCK" to "INSERT"
Posted

Or this, perhaps? :geek:

 

(defun c:Bcount ()
(alert (strcat "You have :" [color=red](itoa [/color](sslength 
 (ssget "_x" '((0 . "[color=red]INSERT[/color]"))))[color=red])[/color] "Blocks .."))
(princ)
)

Posted

That's perfect RenderMan.

 

But don't forget to change the ((0 . "BLOCK")) TO '((0 . "INSERT")) as Lee indicated to Please.

 

Many thanks.

Posted
Or this, perhaps? :geek:

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

Posted

Oooo... Sorry, sorry. It appears you're too late, as that has already been done, my friend! 8)

 

I noticed it right after posting, and quickly fixed accordingly.

 

Cheers! :beer:

Posted
All right, Nice one. :)

 

Thank you so much.

 

Glad I could contribute a small tid-bit.

Posted
Or this, perhaps? :geek:

 

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

Posted
Type

 

(sslength nil)

 

at the command line.

 

Okay... I must be missing something, Lee??? :?

 

Command: (sslength nil)
; error: bad argument type: lselsetp nil

Posted
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!!! :ouch:

 

Will re-write accordingly.....

Posted

Ohhh! I get it, now!!! :ouch:

 

Will re-write accordingly.....

 

But I did not get yet.

 

Could you rise it up please. :)

Posted
Ohhh! I get it, now!!! :ouch:

 

Will re-write accordingly.....

 

Sorry, Michaels. In my haste, I may have led you astray with the combined alert-ssget combo. :oops:

 

Doing so, precludes any error checking :ouch: - 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

Posted

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

Posted
Again I urge you to consider

 

(sslength nil)

 

Wow - I have been silly today. :oops: 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

Posted

Exactly - so we must allow for no blocks: i.e. ssget returning nil.

 

EDIT: You got it :)

Posted
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! :thumbsup:

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