+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Junior Member
    Using
    AutoCAD 2010
    Join Date
    Feb 2012
    Posts
    10

    Default Bcount lisp for named blocks

    Registered forum members do not see this ad.

    Is there a way to incorporate the bcount command into a lisp to count only blocks named "E" for example. I need to somehow select all the blocks named "E" prior to running the bcount command. Any suggestions? Thanks.

  2. #2
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,633

    Default

    Code:
    (if (setq ss (ssget "_x" '((2 . "E"))))
      (sssetfirst nil ss)
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  3. #3
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,008

    Default

    Also the built-in commands QSELECT and FILTER will do this for you.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  4. #4
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    3,791

    Default

    Tharwat I was supprised the code worked with only the one dxf code of 2 theres lots of other objects that use 2 also, would it be better to add the search for blocks only (0 . "insert") as a more general example of using ssget's.

    Code:
    '((0 . "INSERT")(2 . "E"))
    A man who never made mistakes never made anything

  5. #5
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,635

    Default

    It is possible, though highly unlikely. Things like AttDefs (2 = TagName), Hatch (2 = Pattern), Shape (2 = Shape Name), Dimensions (2 = Anonymous Block Name - *D-prefix), Table (2 = Anonymous Block Name - *T-prefix), etc. could have similar stuff in the code 2 item. Though to make sure your way would be more complete & unambiguous.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  6. #6
    Senior Member ketxu's Avatar
    Computer Details
    ketxu's Computer Details
    Operating System:
    Sorry, my English not well :(
    Computer:
    Sorry, my English not well :(
    Motherboard:
    Sorry, my English not well :(
    CPU:
    Sorry, my English not well :(
    RAM:
    Sorry, my English not well :(
    Graphics:
    Sorry, my English not well :(
    Primary Storage:
    Sorry, my English not well :(
    Secondary Storage:
    Sorry, my English not well :(
    Monitor:
    Sorry, my English not well :(
    Using
    AutoCAD 2007
    Join Date
    Sep 2010
    Location
    Sorry, my English not well :(
    Posts
    169

    Default

    Registered forum members do not see this ad.

    Or maybe : (it works with dynamic block also - quick and dirty with some acet function)

    Code:
    (defun c:bcc (/ table dcl lsblk nm ss tol)
    ;Ketxu 2012
     (vl-load-com) 
        (defun table (s / d r)
        (while (setq d (tblnext s (null d)))
        (setq r (cons (cdr (assoc 2 d)) r))
        )
        )
        (defun DCL(Title @ ThongTin lstVal / fl ret)   
             (setq fl (vl-filename-mktemp "mip" nil ".dcl"))
             (setq  ret (open fl "w"))
             (mapcar
            '(lambda (x) (write-line x ret))
            (list 
            "mip_msg : dialog { "
            (strcat "label=\"" title "\"; width = 40;fixed_width = true;")  ; 
            ":popup_list {label = \"Block : \";key=\"kLst\";}" 
            ": column {"
            ": row {"
            "    fixed_width = true;"
            "    alignment = centered;"
            ":button {label = \"\OK\"; is_cancel = true;fixed_width = true;width = 1;}"
            "    : spacer { width = 2; }"
            ":button {label = \"About\";fixed_width = true;width = 1;key = \"kThongTin\";}" 
            "}"
            "}"
            " :text_part {alignment=centered;"
             (strcat "label=\"" @ "\";")
             "}}"
            )    
             ) ;_ end of mapcar
             (setq ret (close ret))
             (if (and (not (minusp (setq dcl_id (load_dialog fl))))
              (new_dialog "mip_msg" dcl_id)
             ) ;_ end of and
            (progn 
            (start_list "kLst" 3)
            (mapcar '(lambda(x)(add_list x)) lstVal)
            (end_list)
            (action_tile "kLst" "(setq ret (nth (atoi $value) lstVal))")
            (start_dialog) 
            ) ;_ end of progn
             ) ;_ end of if
             (unload_dialog dcl_id)  
             (vl-file-delete fl)
             ret 
        )
    (setq lstBlk (vl-remove-if '(lambda(x)(wcmatch x "`**"))(acad_strlsort (table "Block")))) 
    (cond ((setq nm (DCL "Select block :" "@Ketxu" "Count choiced block @Ketxu" lstBlk))
    (setq  ss  (ssget (list (cons 0 "INSERT")(cons 2 (strcat nm ",`**"))))
    tol (length (setq tmp (vl-remove-if-not '(lambda(x)(= (vla-get-EffectiveName (vlax-ename->vla-object x)) nm)) (acet-ss-to-list ss))))
    )
    ))
    (cond ((> tol 0)
    (sssetfirst nil (acet-list-to-ss tmp))
    (princ (strcat "Number of block " nm " in selection area : " (itoa tol) ))
    )(T (princ "Nothing"))
    )
    (princ)
    )

Similar Threads

  1. Counting Blocks - BCOUNT/EATTEXT
    By 3smees23 in forum AutoCAD General
    Replies: 3
    Last Post: 25th Jan 2012, 01:53 pm
  2. Printing blocks with named plot styles
    By the ber in forum AutoCAD Drawing Management & Output
    Replies: 5
    Last Post: 11th Dec 2011, 10:01 am
  3. lisp to print named views
    By sadhu in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 1st Apr 2010, 01:12 pm
  4. Problem with bcount & dynamic blocks
    By yrnomad in forum AutoCAD General
    Replies: 3
    Last Post: 8th Jan 2009, 12:56 pm
  5. acad named blocks
    By mmoreno in forum AutoCAD General
    Replies: 2
    Last Post: 30th Dec 2008, 08:53 pm

Bookmarks

Posting Permissions

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