Results 1 to 4 of 4

Thread: BCOUNT in a LISP

  1. #1
    Member
    Join Date
    2016-10
    Posts
    6
    Login to Give a bone
    0

    Default BCOUNT in a LISP

    Hi,

    I hope someone can help me with a LISP routine.

    I currently use BCOUNT to check if certain blocks have been inserted into a drawing when I am checking them.

    What I would ideally like is some kind of routine that when it is activated can check if certain blocks are in the drawing. If the block isn't there then I would like an alert to pop up to say something like 'No valve on drawing!' etc.
    If the block is there then a pop up appears to say something like 'There are 2 x valves on the drawing'.

    I hope someone can help with this, thanks in advance.

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: BCOUNT in a LISP


  3. #3
    Member
    Join Date
    2016-10
    Posts
    6
    Login to Give a bone
    0

    Default Re: BCOUNT in a LISP

    Quote Originally Posted by Tom Beauford View Post
    Thanks for that. I have looked at the code and tried to tweak it to suit (bear in mind I am a beginner). The below code almost does what I am looking for but instead of placing the MText onto the drawing I would prefer if an alert pops up to give the info regrading the blocks?

    Code:
    (defun C:Test (/ acsp adoc ang atch axss com_data count_lst count_text ldobj mtx osm p1 p2 ss)
    
        (vl-load-com)
        (setq adoc (vla-get-activedocument
    		 (vlax-get-acad-object)
    	       )
    	  acsp (vla-get-modelspace adoc)
        )
        (setvar "cmdecho" 0)
        (setq osm (getvar "osmode"))
        (setvar "osmode" 0)
        (vla-endundomark adoc)
        (vla-startundomark adoc)  
        (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 410 (getvar "CTAB")))))
        (setq axss (vla-get-activeselectionset adoc))
        
        (vlax-for a	axss
          (setq com_data (cons (vla-get-effectivename a) com_data))
        )
    
        (setq count_lst (count_occurs com_data))
    
        (setq count_lst (vl-sort count_lst (function (lambda (a b)(< (cdr a)(cdr b))))))
        (setq count_text
    	   (apply 'strcat
    	   (mapcar (function (lambda(x)(strcat "(" (itoa (cdr x)) ") " (car x) "\\P")))
        count_lst)))
    
        (setq p1 (getpoint)
    	  p2 (getpoint p1)
    	  )
        (cond
        ((< 0 ang 90)(setq atch 4))
        ((< 90 ang 180)(setq atch 6))
        ((< 180 ang 270)(setq atch 6))
        ((< 270 ang 360)(setq atch 4)))
    
        (setq	mtx (vlax-invoke
    	      acsp 'AddMtext p2	0.0 count_text)
        )
        (vlax-put mtx 'Layer "0");<--layer name
        (vlax-put mtx 'Color 256);<--color bylayer
    
        (vla-endundomark adoc)
        (princ)
        ) 
        (prin1)

  4. #4
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: BCOUNT in a LISP

    Your missing a defun Count_occurs in your code so did not test, but something like this

    Code:
    ;    (setq p1 (getpoint)
    ;	  p2 (getpoint p1)
    ;	  )
    ;    (cond
    ;    ((< 0 ang 90)(setq atch 4))
    ;    ((< 90 ang 180)(setq atch 6))
    ;    ((< 180 ang 270)(setq atch 6))
    ;    ((< 270 ang 360)(setq atch 4)))
    ;
    ;    (setq	mtx (vlax-invoke
    ;	      acsp 'AddMtext p2	0.0 count_text)
    ;    )
     ;   (vlax-put mtx 'Layer "0");<--layer name
    ;    (vlax-put mtx 'Color 256);<--color bylayer
    (alert count_text)

Similar Threads

  1. Replies: 2
    Last Post: 2013-12-02, 02:06 AM
  2. Replies: 3
    Last Post: 2012-05-07, 08:16 PM
  3. BCount Leader LISP
    By jmarck in forum AutoLISP
    Replies: 15
    Last Post: 2010-08-06, 01:50 PM
  4. Update BCount tool to count Dynamic Blocks
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2010-03-29, 02:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •