changing xrefed images into OLE

changing xrefed images into OLE

alaa.farhat
Contributor Contributor
6,420 Views
5 Replies
Message 1 of 6

changing xrefed images into OLE

alaa.farhat
Contributor
Contributor

Greetings! I have a CAD drawing that contains images that are xrefed to this DWG. I also have a lot of drawings with the same issue, and I need to convert all the images from xrefed to OLE images. I'm not familiar with coding, so I've been working on a ChatGPT script to run automatically and convert all these images from xref to OLE. This would bind all the images in the same drawing. If someone could check the code below and see what I'm missing, since the script is only removing the images without replacing them with an OLE version.

 

""

(defun c:ReplaceImagesWithOLE ()
(setq imagePath (getfiled "Select an image file" "" "bmp;jpg;jpeg;png;gif;tif;tiff" 4))
(if imagePath
(progn
(setq scale (getreal "\nEnter scale factor (1.0 for original size): "))
(setq linkOption (strcase (getstring "\nLink the OLE object? (Yes/No): ")))

;; Ensure the linkOption is valid
(if (or (equal linkOption "YES") (equal linkOption "NO"))
(progn
(setq linkOption (if (equal linkOption "YES") 1 0))
(setq selectedImages (ssget "_X" '((0 . "IMAGE"))))

;; Check if any images are selected
(if selectedImages
(progn
(setq numImages (sslength selectedImages))
(setq count 0)

;; Loop through selected images
(while (< count numImages)
(setq entity (ssname selectedImages count))

;; Get the image's insertion point for later OLE insertion
(setq imageInsertionPoint (cdr (assoc 10 (entget entity))))

;; Get the image's path for later OLE insertion
(setq imagePath (cdr (assoc 1 (entget entity))))

;; Delete the selected image
(entdel entity)

;; Insert the OLE object at the image's insertion point
(command "_pasteclip" imagePath imageInsertionPoint scale scale linkOption)

(setq count (1+ count))
)

(princ (strcat "\nReplaced " (itoa numImages) " images with OLE objects."))
)
(princ "\nNo images found in the selection.")
)
)
(princ "\nInvalid option. Please enter 'Yes' or 'No' for linking.")
)
)
(princ "\nNo image file selected.")
)
)

(c:ReplaceImagesWithOLE)""

""

0 Likes
6,421 Views
5 Replies
Replies (5)
Message 2 of 6

TheCADnoob
Mentor
Mentor

If a response isn't floated here, you can try asking your question in the forum that deals with lisp

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130

CADnoob

EESignature

0 Likes
Message 3 of 6

paullimapa
Mentor
Mentor

Pasteclip only works with things previously copied onto windows clipboard. Since you don’t have the attached images opened and copied (Ctrl+v) there then nothing comes into AutoCAD 

Review this thread for alternatives 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/image-file-to-ole-object/td-p/744253...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 6

alaa.farhat
Contributor
Contributor

Thank you for your reply. I am in need of finding a solution to this problem. As soon as I get something, I will share it here.

0 Likes
Message 5 of 6

paullimapa
Mentor
Mentor

You are welcome and check out the possible solution I provided in link


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 6

samayaconstr2
Explorer
Explorer

have you found any solution forthat issue?

0 Likes