changing xrefed images into OLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)""
""