+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Senior Member
    Computer Details
    Glen Smith's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell Studio XPS 1645
    CPU:
    Intel i7 Q720 @ 1.6Ghz
    RAM:
    8 Gig
    Using
    Electrical 2010
    Join Date
    May 2008
    Location
    Cary, NC
    Posts
    418

    Default block object insertion point?

    Registered forum members do not see this ad.

    I'm trying to modify a LISP that Lee MAc Wrote for me a couple weeks ago, I'm using it to insert a block at the same insertion point as the existing block. Lee's code uses an excell spread sheet as input for a list of blocks to find in the drawing. Since the code already finds each block, I figure it ought to be able to insert the new block as well. I just can't figure out how to code the insertion point without making the user click it.

    Code:
    (defun c:BLOCKINSERT (/ file nl lst Minp Maxp pts elst ipt)
      (vl-load-com)
      (if (setq file
                 (getfiled "Select Text File"
                           (if *load
                             *load
                             ""
                           )
                           "txt"
                           8
                 )
          )
        (progn
          (setq *load file
                file  (open file "r")
          )
          (while (setq nl (read-line file))
            ;(princ nl)
            (setq lst (cons (car (StrBrk nl 9)) lst))
          )
          (close file)
          (princ "\n<< Closed file >>")
          (if (setq elst (vl-remove-if
                           'null
                           (mapcar 'handent
                                   (mapcar
                                     (function
                                       (lambda (x)
                                         (substr x 2)
                                       )
                                     )
                                     (reverse lst)
                                   )
                           )
                         )
              )
            (foreach Obj (mapcar 'vlax-ename->vla-object elst)
     
              (vla-getBoundingBox Obj 'Minp 'Maxp)
              (setq pts (mapcar 'vlax-safearray->list (list Minp Maxp)))
              (vla-ZoomCenter
                (vlax-get-acad-object)
                (vlax-3D-point
                  (polar (car pts)
                         (apply 'angle pts)
                         (/ (apply 'distance pts) 2.)
                  )
                )
                400.
              )
              (setq ipt (assoc 10 entget (Obj))) 
             (command "-insert" "KEY_MG_RED" ipt 1 1 0)
            )
          )
        )
        (princ "\n<< No File Selected >>")
      )
      (princ)
    )
    (defun StrBrk (str chrc / pos lst)
      (while (setq pos (vl-string-position chrc str))
        (setq lst (cons (substr str 1 pos) lst)
              str (substr str (+ pos 2))
        )
      )
      (reverse (cons str lst))
    )
    Can anyone point me in the right direction?

    Glen
    “Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something." Lazarus Long in Time Enough For Love

  2. #2
    Senior Member
    Using
    AutoCAD 2007
    Join Date
    Jan 2007
    Posts
    159

    Default

    Quote Originally Posted by Glen Smith View Post
    I'm trying to modify a LISP that Lee MAc Wrote for me a couple weeks ago, I'm using it to insert a block at the same insertion point as the existing block. Lee's code uses an excell spread sheet as input for a list of blocks to find in the drawing. Since the code already finds each block, I figure it ought to be able to insert the new block as well. I just can't figure out how to code the insertion point without making the user click it.

    Code:
    
              (setq ipt (assoc 10 entget (Obj))) 
             (command "-insert" "KEY_MG_RED" ipt 1 1 0)
    the above code should be
    Code:
     (setq ipt (cdr(assoc 10 (entget (Obj)))))
             (command "-insert" "KEY_MG_RED" ipt 1 1 0)
    if the Obj entity hasn't came out of a selection set the line would be

    Code:
     (setq ipt (cdr(assoc 10 (entget(car (Obj))))))
              (command "-insert" "KEY_MG_RED" ipt 1 1 0)
    Hope that helps

  3. #3
    Senior Member
    Computer Details
    Glen Smith's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell Studio XPS 1645
    CPU:
    Intel i7 Q720 @ 1.6Ghz
    RAM:
    8 Gig
    Using
    Electrical 2010
    Join Date
    May 2008
    Location
    Cary, NC
    Posts
    418

    Default

    Using the first of the two, I get the error:
    Command: ; error: bad function: #<VLA-OBJECT IAcadBlockReference 0be2eabc>


    Using the second, I get:
    Command: ; error: bad function: #<VLA-OBJECT IAcadBlockReference 0be2eabc>

    I don't think that the obj entity came from a selection set, although I'm not entirely sure.

    Thanks,
    Glen
    “Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something." Lazarus Long in Time Enough For Love

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,707

    Default

    Obj is a VLA-Object represented as a symbol, through the foreach function.

    i.e.

    Code:
    (foreach Obj ...
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,707

    Default

    Quote Originally Posted by Glen Smith View Post
    ...Lee's code uses an excell spread sheet...
    I hope not!... I coded it for a txt file..
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  6. #6
    Senior Member
    Computer Details
    Glen Smith's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell Studio XPS 1645
    CPU:
    Intel i7 Q720 @ 1.6Ghz
    RAM:
    8 Gig
    Using
    Electrical 2010
    Join Date
    May 2008
    Location
    Cary, NC
    Posts
    418

    Default

    Whoops, true, I just use Excel to modify the txt file so much that I forget that they are not the same.

    I know you have posted a source for explaining VLA functions in the past, but my searching has been in vain. Would you be so kind as to repost it? I have also read that you have a LISP FAQ that is "coming soon" is it available yet?

    Thanks,
    Glen
    “Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something." Lazarus Long in Time Enough For Love

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,707

    Default

    Registered forum members do not see this ad.

    Obviously there are a good few sites to explain the VL functions, here are a few to look at:

    http://www.afralisp.net/

    VL method differences

    Attributes in VL

    Paperspace/Modelspace Objects

    As for the LISP FAQ, this needs to be approved by the other members before being opened to the public, and this approval is taking some time it seems.

    Lee
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. Changing block insertion point
    By JBullseye74 in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 27th Oct 2008, 04:21 pm
  2. Block Insertion Point
    By neekcotrack in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 11th Aug 2008, 08:46 pm
  3. Block Insertion Point
    By Thaumaturge in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 15
    Last Post: 30th May 2008, 09:52 am
  4. using insertion point in block attribute
    By aamotox in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 21st Feb 2007, 09:07 pm
  5. Change the Block Insertion Point on the Fly
    By CAD-e-Corner in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 5th Sep 2006, 09:14 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