Jump to content

Recommended Posts

Posted

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.

 

(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.
         )
         [color=red](setq ipt (assoc 10 entget (Obj))) [/color]
[color=red]         (command "-insert" "KEY_MG_RED" ipt 1 1 0)[/color]
       )
     )
   )
   (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

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

 



         [color=red](setq ipt (assoc 10 entget (Obj))) [/color]
[color=red]         (command "-insert" "KEY_MG_RED" ipt 1 1 0)[/color]
       

 

the above code should be

[color=red](setq ipt (cdr(assoc 10 (entget (Obj))))[/color])
[color=red]         (command "-insert" "KEY_MG_RED" ipt 1 1 0)[/color]

if the Obj entity hasn't came out of a selection set the line would be

 

[color=red](setq ipt (cdr(assoc 10 (entget(car (Obj))))[/color]))
[color=red]         (command "-insert" "KEY_MG_RED" ipt 1 1 0)[/color]

 

Hope that helps

Posted

Using the first of the two, I get the error:

Command: ; error: bad function: #

 

 

Using the second, I get:

Command: ; error: bad function: #

 

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

 

Thanks,

Glen

Posted

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

 

i.e.

 

(foreach [b]Obj[/b] ...

Posted
...Lee's code uses an excell spread sheet...

 

I hope not!... I coded it for a txt file.. :unsure:

Posted

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

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