Glen Smith Posted August 10, 2009 Posted August 10, 2009 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 Quote
ollie Posted August 10, 2009 Posted August 10, 2009 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 Quote
Glen Smith Posted August 10, 2009 Author Posted August 10, 2009 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 Quote
Lee Mac Posted August 10, 2009 Posted August 10, 2009 Obj is a VLA-Object represented as a symbol, through the foreach function. i.e. (foreach [b]Obj[/b] ... Quote
Lee Mac Posted August 10, 2009 Posted August 10, 2009 ...Lee's code uses an excell spread sheet... I hope not!... I coded it for a txt file.. Quote
Glen Smith Posted August 11, 2009 Author Posted August 11, 2009 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 Quote
Lee Mac Posted August 11, 2009 Posted August 11, 2009 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 Quote
Recommended Posts
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.