TonyBaloni Posted February 19, 2022 Posted February 19, 2022 This nice little subroutine below by Alan Thompson places multiple images on AutoCAD. And it works beautifully. But what I also need to do is to add the name of the file next to each image (see the attached picture). Any ideas where to start? I am very new to AutoLISP. Thank you Tony (defun c:ImageIn (/ lst a b fin) ;; Alan J. Thompson, 05.10.10 ;; DosLib required (vl-load-com) (if (setq lst (dos_getfilem "Select images to insert:" (getvar "dwgprefix") "")) ((lambda (layers) (foreach file (vl-sort (cdr lst) (function >)) (if fin (progn (vla-GetBoundingBox (car fin) 'a 'b) (setq b (vlax-safearray->list b)) (vl-cmdf "_.image" "_attach" (strcat (car lst) file) (list 0. (1+ (cadr b))) "" "") ) (vl-cmdf "_.image" "_attach" (strcat (car lst) file) '(0. 0. 0.) "" "") ) (vla-put-layer (car (setq fin (cons (vlax-ename->vla-object (entlast)) fin))) (vla-get-name (vla-add layers (vl-filename-base file))) ) ) ) (vla-get-layers (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) ) (princ) ) Quote
TonyBaloni Posted February 19, 2022 Author Posted February 19, 2022 I did find this online (see below)....but it returns "error: ADS request error" Maybe I can use this after inserting the images...to put the name of the image next to it. If anyone out there knows how to fix it (?) (defun c:ImageNameLabel (/ s h i e) (if (and (setq s (ssget '((0 . "IMAGE")))) (setq h (getvar 'textsize)) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i)))) (entmake (list (cons 0 "TEXT") (assoc 10 (entget e)) (cons 40 h) (cons 1 (getpropertyvalue e "ImageName")))))) (princ) ) Quote
marko_ribar Posted February 19, 2022 Posted February 19, 2022 Don't have a time to test, but try replacing : (cons 1 (getpropertyvalue e "ImageName")) with : (assoc 1 (entget e)) Quote
TonyBaloni Posted February 19, 2022 Author Posted February 19, 2022 I get error "; error: bad DXF group: nil" Here's the revised code (maybe I didn't edit correctly?): (defun c:ImageNameLabel (/ s h i e) (if (and (setq s (ssget '((0 . "IMAGE")))) (setq h (getvar 'textsize)) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i)))) (entmake (list (cons 0 "TEXT") (assoc 10 (entget e)) (cons 40 h) (assoc 1 (entget e))))))) (princ) ) Quote
Tharwat Posted February 19, 2022 Posted February 19, 2022 You can change the value of the variable 'g' in the following routine to adjust the gap distance between image & text. (defun c:test (/ s h i e g l r) (if (and (setq s (ssget '((0 . "IMAGE")))) (setq h (getvar 'textsize)) (setq g (/ h 2.0)) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i)))) (vla-getboundingbox (vlax-ename->vla-object e) 'l 'r) (setq l (vlax-safearray->list l) r (vlax-safearray->list r) ) (and l r (entmake (list (cons 0 "TEXT") (cons 10 (polar (mapcar '(lambda (j k) (/ (+ j k) 2.0)) l r) 0.0 (+ g (/ (distance l (list (car r) (cadr l) 0.0)))) ) ) (cons 40 h) (cons 1 (getpropertyvalue e "ImageName")) ) ) ) ) ) (princ) ) Quote
TonyBaloni Posted February 19, 2022 Author Posted February 19, 2022 getting "; error: ADS request error" I have AutoCAD 2014 (one of the last perpetual licenses) and running on Windows 10 (and it works just fine). Could that be a factor with all these errors? Just so you know, Autodesk sent me the install files when I moved to Windows 10 (but they also recommended staying with Windows 7) Quote
Tharwat Posted February 19, 2022 Posted February 19, 2022 Add the following to the codes and try again. (vl-load-com) Quote
Tharwat Posted February 19, 2022 Posted February 19, 2022 (defun c:test (/ s h i e g l r) (if (and (setq s (ssget '((0 . "IMAGE")))) (setq h (getvar 'textsize)) (setq g (/ h 2.0)) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i)))) (vla-getboundingbox (vlax-ename->vla-object e) 'l 'r) (setq l (vlax-safearray->list l) r (vlax-safearray->list r) ) (and l r (entmake (list (cons 0 "TEXT") (cons 10 (polar (mapcar '(lambda (j k) (/ (+ j k) 2.0)) l r) 0.0 (+ g (/ (distance l (list (car r) (cadr l) 0.0)) 2.0)) ) ) (cons 40 h) (cons 1 (getpropertyvalue e "ImageName")) ) ) ) ) ) (princ) ) (vl-load-com) 1 Quote
BIGAL Posted February 20, 2022 Posted February 20, 2022 (edited) Back to 1st post if you use Getfiled rather than DOSLIB, you can pick say 1 JPG then you can get the directory where the JPG's are located. (setq DT (getfiled "Specify File Name" "d:" "jpg" 1)) then (setq path (vl-filename-directory DT)) to get path. Then use (setq jpgs (vl-directory-files path "*.JPG")) this will make a list of your jpg names so can feed the insert image and file name in one go. Will add to "to do list". Edited February 20, 2022 by BIGAL Quote
TonyBaloni Posted February 20, 2022 Author Posted February 20, 2022 "test.lsp" works okay with AutoCAD 2021 but not with 2014. Any ideas why 2021 but not 2014? I was hoping to stay with 2014. Otherwise all good to go with "ImageIn" (then label with "test" after sorting images) Quote
Tharwat Posted February 20, 2022 Posted February 20, 2022 That's because the function getpropertyvalue was release a few years back and not up to AutoCAD 2014 , so try the following which should work on any CAD. (defun c:test (/ s h i e g l r) (if (and (setq s (ssget '((0 . "IMAGE")))) (setq h (getvar 'textsize)) (setq g (/ h 2.0)) ) (repeat (setq i (sslength s)) (setq e (vlax-ename->vla-object (ssname s (setq i (1- i))))) (vla-getboundingbox e 'l 'r) (setq l (vlax-safearray->list l) r (vlax-safearray->list r) ) (and l r (entmake (list (cons 0 "TEXT") (cons 10 (polar (mapcar '(lambda (j k) (/ (+ j k) 2.0)) l r) 0.0 (+ g (/ (distance l (list (car r) (cadr l) 0.0)) 2.0)) ) ) (cons 40 h) (cons 1 (vla-get-name e)) ) ) ) ) ) (princ) ) (vl-load-com) Quote
BIGAL Posted February 20, 2022 Posted February 20, 2022 getproperty and setproperty are not supported in Bricscad V20 not sure V22. Quote
TonyBaloni Posted February 20, 2022 Author Posted February 20, 2022 WOW that was awesome! Thank you So now I'll use "ImageIn.lsp" (as was written by Alan Thompson) to load multiple pictures into AutoCAD 2014. Then, after using AutoCAD to sort the pictures, I can label them with "test.lsp". "imageIn.lsp" does create a new layer for each picture loaded, and I don't need that...but I can live with it...unless someone knows how to turn that off easily. Again, thank you. 1 Quote
marko_ribar Posted February 21, 2022 Posted February 21, 2022 (defun c:ImageIn ( / lst a b fin ) ;; Alan J. Thompson, 05.10.10 ;; DosLib required ;; no layers creation while attaching images... mod. by M.R. (vl-load-com) (if (setq lst (dos_getfilem "Select images to insert:" (getvar "dwgprefix") "")) (foreach file (vl-sort (cdr lst) (function >)) (if fin (progn (vla-GetBoundingBox (car fin) 'a 'b) (setq b (vlax-safearray->list b)) (vl-cmdf "_.image" "_attach" (strcat (car lst) file) (list 0. (1+ (cadr b))) "" "") ) (vl-cmdf "_.image" "_attach" (strcat (car lst) file) '(0. 0. 0.) "" "") ) (setq fin (cons (vlax-ename->vla-object (entlast)) fin)) ) ) (princ) ) Quote
BIGAL Posted February 21, 2022 Posted February 21, 2022 Just a comment I threw multiple images of all different sizes at code and the result was interesting with images not stacked nicely. It needs to look at image bounding box and move image to suit so touches last. Where images are all same size works ok. Quote
TonyBaloni Posted February 22, 2022 Author Posted February 22, 2022 When I run the routine by marrko_ribar (see above) I sometimes get the images stacked next to each other, sometimes there's a big gap (it seems to vary with different sessions of AutoCAD). There must be a setting or variable in AutoCAD 2014 that is changing (?). Is there a way to control the gap regardless of what the current settings are in that particular AutoCAD session? Ideally I would want 1/4" gap, always -- the images are always inserted as 1" high. The reason for the gap -- so I can rotate some of the images without overlapping the adjacent images (which is what happening when there's no gap between images). Quote
Tharwat Posted February 22, 2022 Posted February 22, 2022 @TonyBaloni I replied to your message with my suggestion. 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.