How to insert multiple images from same file location and different file names .

How to insert multiple images from same file location and different file names .

Shanky1999
Enthusiast Enthusiast
2,516 Views
25 Replies
Message 1 of 26

How to insert multiple images from same file location and different file names .

Shanky1999
Enthusiast
Enthusiast

Is there a lisp to insert multiple images from the exact file location but with different names to a dwg.

Like I have to insert approx 100 images into a dwg. I use the Xref command and enter them manually to the pointer location. Is there a way to make it less tedious like a macro or lisp? It would be a huge help.

 

0 Likes
Accepted solutions (3)
2,517 Views
25 Replies
Replies (25)
Message 2 of 26

Kent1Cooper
Consultant
Consultant

I have some routines that do something very similar with Blocks, as drawing files in a specified folder, >here<.  Maybe you can adapt the one that INSERTs to use IMAGEATTACH or XREF instead of INSERT.  It's not clear to me whether you want them all at the same insertion point [which would greatly simplify the code], as opposed to spacing them out to not overlap each other, as the BlockChart routine does.  If spaced apart like that, the width of the LIMITS setting in your drawing will affect how many it puts in a row before moving to another row above, so set that accordingly.

Kent Cooper, AIA
0 Likes
Message 3 of 26

Shanky1999
Enthusiast
Enthusiast

I want them to be spaced. First I would used to spam enter, will give this a try. Which is more suitable Blockimport.lsp or Blockchart.lsp ?

0 Likes
Message 4 of 26

Kent1Cooper
Consultant
Consultant

@Shanky1999 wrote:

.... Which is more suitable Blockimport.lsp or Blockchart.lsp ?


BlockChart.  The other one just brings in the definitions, without Inserting instances of them, so the spacing part is not there.

Kent Cooper, AIA
0 Likes
Message 5 of 26

john.uhden
Mentor
Mentor

@Kent1Cooper 

Couldn't he use getboundingbox on each insertion and position the next one to abut it?

Of course at work we use images a lot to save drafting.  But we're always having to scale and clip them to avoid a plethora of detail sheets.

I remember my draftsman at HMM who wanted to make certain that the underlying title would align perfectly with its neighbors... "Dammit, George!  Just move them around 'til they all fit, and why is that one so big?!  We don't need 0.08 text height when 0.06 is legible enough!!  NTS, NTS!!!"

John F. Uhden

0 Likes
Message 6 of 26

maratovich
Advisor
Advisor

Maybe this will help you -AutoImportCAD 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 7 of 26

Shanky1999
Enthusiast
Enthusiast

The app works on my home computer, but I can't run it on an office pc. That's why I was looking for a Lisp file. Is there a Lisp file available?

0 Likes
Message 8 of 26

Shanky1999
Enthusiast
Enthusiast

Also the name of the images changes when Imported using this application.

0 Likes
Message 9 of 26

Shanky1999
Enthusiast
Enthusiast

What is the command for BlockChart Lisp? @Kent1Cooper. The app @maratovich suggested is working fine, but it changes the name of the images and I can't run an application on a work pc. The application changes names, so it becomes hard if the dwg is to be opened on a different pc, the xrefs don't match. Is there a Lisp file for the AutoImportCAD application?

0 Likes
Message 10 of 26

Shanky1999
Enthusiast
Enthusiast

@Kent1Cooper I used BlockChart lisp command BC, but it only selects .dwg files. How do I modify it so that it selects png or jpeg?

0 Likes
Message 11 of 26

Shanky1999
Enthusiast
Enthusiast

@Kent1CooperI made some modifications, It works but it selects images in these order: 1,10,100,101,102,103,104,105,106,107,108,109,11,110,...

I want the order to be like 1,2,3,4,... and I want them to be arranged horizontally instead of vertically.

 

here is the code I modified.

 

(defun c:BC (/ blkfolder space nextLL rowht rowL blkLL blkUR objwid objht)
(vl-load-com)
(setvar 'osmode 0)
(alert "Pick OK here, then double-click any file in desired folder: ")
(setq
blkfolder (getfiled "Find folder" "" "png" 0)
blkfolder (substr blkfolder 1 (1+ (vl-string-position 92 blkfolder 1 T))); path without dwg name
space 1 ; between blocks and min. from limits <------ set as desired
nextLL (mapcar '+ (getvar 'limmin) (list space space 0)); lower left of next block
rowht 0 ; height of tallest block in row
rowL nextLL; left end of baseline of row
); end setq
(foreach blk (vl-directory-files blkfolder "*.png" 1)
(command "_.imageattach" (strcat blkfolder blk) (getvar 'viewctr) "" "" "")
(vla-getboundingbox (vlax-ename->vla-object (entlast)) 'minpt 'maxpt)
(setq
blkLL (vlax-safearray->list minpt)
blkUR (vlax-safearray->list maxpt)
objwid (- (car blkUR) (car blkLL))
objht (- (cadr blkUR) (cadr blkLL))
)
(if (> (+ (car nextLL) objwid space) (car (getvar 'limmax)))
(setq ; then - start new row above previous row
nextLL (polar rowL (/ pi 2) (+ rowht space))
rowL nextLL
rowht 0
); end setq
); end if - no else [next in current row]
(command "_.move" (entlast) "" blkLL nextLL)
(setq nextLL (polar nextLL 0 (+ objwid space)))
(if (> objht rowht) (setq rowht objht))
); end foreach
); end defun

0 Likes
Message 12 of 26

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.... Couldn't he use getboundingbox on each insertion and position the next one to abut it? ....


That's exactly what BlockChart.lsp does, though with space between [1 unit in the base code, with instruction to set as desired, which can be zero if abutting is wanted].

Kent Cooper, AIA
0 Likes
Message 13 of 26

Kent1Cooper
Consultant
Consultant

@Shanky1999 wrote:

What is the command for BlockChart Lisp?....


If you're hanging around this website for AutoLisp routines, you need to know that the command name in anything defined with (defun C:... is the part immediately following the C:, in this case BC.  [I suggest you change it to something more about Images.]

Kent Cooper, AIA
0 Likes
Message 14 of 26

Kent1Cooper
Consultant
Consultant
Accepted solution

@Shanky1999 wrote:

I made some modifications, It works but it selects images in these order: 1,10,100,101,102,103,104,105,106,107,108,109,11,110,...

I want the order to be like 1,2,3,4,... and I want them to be arranged horizontally instead of vertically.

.....


The order is just how they come out in the (vl-directory-files) function, which I assume must be alphabetical.  You could get them from that, sort them numerically, and use that list.  Are they always names representing integers?

 

For arrangement in the other direction, compare the two attached versions of BlockChart that I made a couple of years ago for a similar request in relation to Blocks.

Kent Cooper, AIA
0 Likes
Message 15 of 26

Shanky1999
Enthusiast
Enthusiast

yeah I found it and also made some modifications I have sent the code previously

0 Likes
Message 16 of 26

Shanky1999
Enthusiast
Enthusiast

Yeah, they are always integers. Also, if I want to stop the command, is there like an emergency stop kind of thing, that I can do to stop it, instead of waiting for it to insert all images or ending AutoCAD from taskmanager.

0 Likes
Message 17 of 26

Kent1Cooper
Consultant
Consultant

@Shanky1999 wrote:

.... if I want to stop the command, is there like an emergency stop kind of thing....


Does hitting ESCape not do that for you?

Kent Cooper, AIA
0 Likes
Message 18 of 26

Shanky1999
Enthusiast
Enthusiast

NO. It continues the image attach command till all the images in the folder are inserted.

0 Likes
Message 19 of 26

Kent1Cooper
Consultant
Consultant

@Shanky1999 wrote:

Yeah, they are always integers. ....


Try this [untested]:
.....
    rowL nextLL; left end of baseline of row
    names (vl-directory-files blkfolder "*.png" 1)
  ); end setq
  (foreach blk (vl-sort names '(lambda (x y) (< (atoi x) (atoi y))))
    (command "_.imageattach" ....

Kent Cooper, AIA
0 Likes
Message 20 of 26

Shanky1999
Enthusiast
Enthusiast
Accepted solution

Yeah, it solves the integers issue, but it still continues to arrange them vertically. Can you look at the code and tell me if I am missing something ? I took your new lsp file.

 

;|BlockChart-Rows.lsp [command name: BC]
Inserts all drawings in a selected folder into the current drawing as Blocks,
in Rows, starting at the lower left corner and placing them horizontally as
many as fit within the width of the drawing limits, and in additional rows
above, as far as needed (which can extend beyond top edge of drawing
limits). Space between extents of Blocks, and minimum from edges of drawing
limits, is in 'space' variable [see EDIT note below].
|;
(defun C:BC (/ blkfolder space nextLL rowht rowL blkLL blkUR objwid objht)
(vl-load-com)
(setvar 'osmode 0)
(alert "Pick OK here, then double-click any file in desired folder: ")
(setq
blkfolder (getfiled "Find folder" "" "png" 0)
blkfolder (substr blkfolder 1 (1+ (vl-string-position 92 blkfolder 1 T))); path without dwg name
space 1 ; dwg units between blocks and min. from limits <------ EDIT: set as desired
nextLL (mapcar '+ (getvar 'limmin) (list space space 0)); lower left of next block
rowht 0 ; height of tallest block in row
rowL nextLL; left end of baseline of row
names (vl-directory-files blkfolder "*.png" 1)
); setq
(foreach blk (vl-sort names '(lambda (x y) (< (atoi x) (atoi y))))
(command "_.imageattach" (strcat blkfolder blk) (getvar 'viewctr) "" "" "")
(vla-getboundingbox (vlax-ename->vla-object (entlast)) 'minpt 'maxpt)
(setq
blkLL (vlax-safearray->list minpt)
blkUR (vlax-safearray->list maxpt)
objwid (- (car blkUR) (car blkLL))
objht (- (cadr blkUR) (cadr blkLL))
); setq
(if (> (+ (car nextLL) objwid space) (car (getvar 'limmax)))
(setq ; then - start new row above previous row
nextLL (polar rowL (/ pi 2) (+ rowht space))
rowL nextLL
rowht 0
); setq
); if - no else [next in current row]
(command "_.move" (entlast) "" blkLL nextLL)
(setq nextLL (polar nextLL 0 (+ objwid space)))
(if (> objht rowht) (setq rowht objht))
); foreach
); defun

0 Likes