+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default Need help making a routine to insert a certain set of blocks all at once at 0,0?

    Registered forum members do not see this ad.

    I use autocad 2000 at my job to create drawings for CAM. The machining paths are numbered between 521-850 (this is the block name) each time with numbers being used throughout this range, not nessecarily in order. What I want to do is get only these numbered blocks to insert all at once with one command at 0,0. Question one: Can I get a list of just the block names with autolisp? Question 2: Can I filter the block names with some sort of < > cond? or will I have to go about that another way?

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Check this out ... Would insert all your block at the coordinates 0,0,0 and would print the name of your inserted blocks to the command line ..

    Code:
    (defun c:TesT (/ Block Blockname lst)
      (while
        (setq Block (tblnext "BLOCK" (null Block)))
         (entmake
           (list '(0 . "INSERT")
                 (cons 10 '(0. 0. 0.))
                 (cons 2 (setq Blockname (cdr (assoc 2 Block))))
                 '(41 . 1.)
                 '(42 . 1.)
                 '(43 . 1.)
                 '(50 . 0.)
           )
         )
         (setq lst (cons Blockname lst))
      )
      (print lst)
      (princ)
    )

  3. #3
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default I will try it out.

    Thanks Man! Too bad I have to wait until I get to work tonight to try it out.

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Quote Originally Posted by jeremyearle5 View Post
    Thanks Man! Too bad I have to wait until I get to work tonight to try it out.
    No problem ,

    And forgot to say , welcome to the forum .

    Tharwat

  5. #5
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    1,232

    Default

    Maybe this :

    Code:
    (defun BlocksFound ( / a b )
        (while (setq a (tblnext "BLOCK" (null a)))
            (if
                (and
                    (/= 4 (logand 4 (cdr (assoc 70 a))))
                    (if (assoc 1 a) (not (findfile (cdr (assoc 1 a)))) T)
                )
                (setq b (cons (cdr (assoc 2 a)) b))
            )
        )
        b
    )
    
    (defun sortblocklist ()
      (vl-sort (blocksfound) '(lambda ( a b ) (< a b)))
    )
    
    (defun filterblocklist ( / pref stno enno no blname filtbllst )
      (setq pref (getstring T "\nInput prefix for blocks : "))
      (setq stno (getint "\nInput start number for filtering block list : "))
      (setq enno (getint "\nInput end number for filtering block list : "))
      (setq no (- stno 1))
      (while (<= no enno)
        (setq no (1+ no))
        (setq blname (strcat pref (itoa no)))
        (if (member blname (sortblocklist)) (setq filtbllst (cons blname filtbllst)))
      )
      (setq filtbllst (reverse filtbllst))
    )
    
    (defun c:insfilblcks nil
      (foreach bl (filterblocklist)
        (command "_.-insert" bl "0,0,0")
        (while (eq 1 (logand 1 (getvar 'cmdactive))) (command ""))
      )
    (princ)
    )
    M.R.

  6. #6
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default

    Registered forum members do not see this ad.

    It worked great Marko! I just switched out the user input with the starting and ending numbers I needed. I appreciate it.

Similar Threads

  1. autolisp routine to read coordinates and insert entities points
    By teknomatika in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 22nd Sep 2010, 06:51 pm
  2. Routine to insert Xref's
    By rami_9630 in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 24th Mar 2010, 02:48 pm
  3. Making a toolbar icon for a lisp routine
    By Organic in forum AutoCAD General
    Replies: 4
    Last Post: 16th Apr 2009, 09:37 pm
  4. Replies: 2
    Last Post: 12th May 2008, 03:22 pm
  5. Making a sub routine public
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 8th Mar 2007, 12:47 pm

Tags for this Thread

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