LISP INSERT MASS EXPLODED FILES TO RENAME AND BLOCK IN LINE

LISP INSERT MASS EXPLODED FILES TO RENAME AND BLOCK IN LINE

Anonymous
Not applicable
993 Views
15 Replies
Message 1 of 16

LISP INSERT MASS EXPLODED FILES TO RENAME AND BLOCK IN LINE

Anonymous
Not applicable

(defun c:mti(/ path dwglist n px py dw1 fn pt e i name Bname )
(vl-load-com)
(setq path (getvar "dwgprefix"))
(setq dwglist (vl-directory-files path "*.dwg" ))
(setq n 0)
(setq px 0 py 0)
(repeat (length dwglist)
  (setq dw1 (nth n dwglist))
  (setq fn (strcat "*" path dw1))
  (setq pt (list px py)) 
  (command "insert" fn pt 1 0 )
(if (setq e (entlast)) 
  (progn 
    (setq i 1) 
    (setq name "My Block") 
    (setq Bname (strcat name (itoa i))) 
    (while (tblsearch "BLOCK" Bname) 
      (setq Bname (strcat name (itoa (setq i (1+ i))))) 
    ) 
    (command "_.-rename" "Block" (cdr (assoc 2 (entget e))) Bname )
  (setq px (+ px 215))
  (setq n (1+ n))
)
(princ)
)

0 Likes
994 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable

(defun c:mti(/ path dwglist n px py dw1 fn pt pts )
(vl-load-com)
(setq pts  (getpoint "\nWhere is Start point :") )
(setq px (car pts))
(setq py (cadr pts))
(setq path (getvar "dwgprefix"))
(setq dwglist (vl-directory-files path "*.dwg" ))
(setq n 0)
;(setq px 0 py 0)
(repeat (length dwglist)
(repeat 10
(setq dw1 (nth n dwglist))
(setq fn (strcat "*" path dw1))
(setq pt (list px py))
(command "._insert" fn pt 1 0 "_.purge" "_blocks" "WT_MULTILINE" "_no" )
(setq px (+ px 215))
(setq n (1+ n))
)
(setq py (- py 370))
(setq px (- px 2150))
)
(princ)

0 Likes
Message 3 of 16

Anonymous
Not applicable

2015-04-18 18;28;17.PNG

 

0 Likes
Message 4 of 16

Anonymous
Not applicable

2015-04-18 18;29;51.PNG

0 Likes
Message 5 of 16

Anonymous
Not applicable
I'm gonna make like this,,,,,
0 Likes
Message 6 of 16

Kent1Cooper
Consultant
Consultant

Welcome to these Forums.

 

It's not clear to me what your purpose is.  But I will guess that your code is giving the result in the image in Post 3, but you want it to be like the image in Post 4 instead.

 

If that is true, apart from the difference that Post 4 has white rectangles that are not in Post 3, it looks like the problem is in the positions of some of the pieces that do not align with the others.  Do you have any running Object Snap modes on?  That's always the first question when things happen in a different place than you expect, and it looks to me as though some of the Blocks in Post 3 are in positions that might be from their insertion points Snapping to something in the corner of the previous Block.  You can have the code turn Object Snap off, either with (command "_.osnap" "_off") or (setvar 'osmode 0), but if you do that, you should probably also save its value first and reset it later.  In a situation like this, with only one place in a command that calls for a point that Object Snap could apply to, it's easier just to put "_none" before the insertion point in the Insert command.

Kent Cooper, AIA
Message 7 of 16

Anonymous
Not applicable

thanks i will try

0 Likes
Message 8 of 16

Anonymous
Not applicable

I am deeply grateful to reply

also I try this command align problem has solved

But I found ether problem with block copy as photo.

So i hope when insert RENAME & BLOCK shoud be done bofore align. 

0 Likes
Message 9 of 16

Anonymous
Not applicable

2015-04-20 11;41;14.PNG

0 Likes
Message 10 of 16

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... i hope when insert RENAME & BLOCK shoud be done bofore align. 


If I understand correctly, here is an alternative approach.  It is not necessary to insert the drawing file and then Rename it with a different Block name.  You can Insert it and give it the new Block name as it is Inserted, using the INSERT BLOCKNAME=FILENAME format.  This is an adjustment of your first code [untested]:

 

(defun c:mti (/ path dwglist n px py dw1 fn pt i name Bname)
  (vl-load-com)
  (setq
    path (getvar "dwgprefix")
    dwglist (vl-directory-files path "*.dwg" )
    n 0
    px 0
    py 0
    i 1
    name "My Block"
    Bname (strcat name (itoa i))
  ); setq
  (while (tblsearch "BLOCK" Bname); find first number ending not yet used
    (setq Bname (strcat name (itoa (setq i (1+ i)))))
  ); while
  (repeat (length dwglist)
    (setq dw1 (nth n dwglist))
    (setq fn (strcat path dw1)); without the "*" [not exploded when Inserted]
    (setq pt (list px py))
    (command "insert" (strcat Bname "=" fn) pt 1 0); bring in with new Block name
    (setq
      px (+ px 215)
      n (1+ n)
      i (1+ i)
    ); setq
  ); repeat
  (princ)
); defun

Kent Cooper, AIA
Message 11 of 16

Anonymous
Not applicable
THANKS FOR YOUR REPLY
I TRIED BUT IT DOESN'T FINISH.
I DON'T KNOW WHY AND I SHOULD LEARN MORE.
0 Likes
Message 12 of 16

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
... I TRIED BUT IT DOESN'T FINISH. I DON'T KNOW WHY ....

A Block definition can be made [in newer versions] to allow only uniform scaling, in which case the Insert command will ask for only one scale factor.  I don't know that you can have that kind of restriction on a drawing that's being Inserted.  Do you have answers for enough scale factor prompts in that Insert command?  Try changing:

 

  (command "insert" (strcat Bname "=" fn) pt 1 0); 1 is X scale factor, 0 will be answer for Y scale factor prompt, but not accepted

 

to:

 

  (command "insert" (strcat Bname "=" fn) pt 1 1 0); 1's are X and Y scale factors, 0 is rotation

 

[I didn't change your original in that regard, so if that's the issue, it should have been a problem then, too.]

 

Or, since 1 is always the default for the X scale factor, and the X scale factor given is always the default for the Y scale factor, and 0 is always the default for the rotation, you can just use Enters for all of them:

 

  (command "insert" (strcat Bname "=" fn) pt "" "" "")

Kent Cooper, AIA
0 Likes
Message 13 of 16

Anonymous
Not applicable
In fact, I have seen already tried
and it just stop with out no insert
actuality i have autocad 2007
0 Likes
Message 14 of 16

Anonymous
Not applicable
Appreciate to you
0 Likes
Message 15 of 16

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
.... and it just stop with out no insert ....

One thing you can try is to confirm whether the things that make up the Insert information are working.  Try this version:

(defun c:mti ();;;;;/ path dwglist n px py dw1 fn pt i name Bname);;;;; not localizing variables, so they'll be available to check afterwards
  (vl-load-com)
  (setq
    path (getvar "dwgprefix")
    dwglist (vl-directory-files path "*.dwg" )
    n 0
    px 0
    py 0
    i 1
    name "My Block"
    Bname (strcat name (itoa i))
  ); setq
  (while (tblsearch "BLOCK" Bname); find first number ending not yet used
    (setq Bname (strcat name (itoa (setq i (1+ i)))))
  ); while
  (repeat (length dwglist)
    (setq dw1 (nth n dwglist))
    (setq fn (strcat path dw1)); without the "*" [not exploded when Inserted]
    (setq pt (list px py))
    (command "insert" (strcat Bname "=" fn) pt "" "" ""); bring in with new Block name
    (setq
      px (+ px 215)
      n (1+ n)
      i (1+ i)
    ); setq
  ); repeat
  (princ)
); defun

 

Then see whether it set everything it should, by typing in variable names with exclamation points in front of them:

 

Type !dwglist at the Command: prompt, and see what it returns [it should be the list of drawing names].

 

Type !dw1 [it should return a drawing name].

 

Type !fn [it should return a filepath and drawing name].

 

Finally, type (findfile fn) [it should show you where the drawing is, confirming that it really is there -- if it isn't, it will return nil].

Kent Cooper, AIA
0 Likes
Message 16 of 16

Anonymous
Not applicable

Iong time no see.

here is sample of my hope job.

some body help PLZ

test dwg is base format.

thanks.

0 Likes