TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FELIX on August 16, 2019, 11:51:25 AM

Title: Use INSERTOBJ command in Autolisp or equivalent
Post by: FELIX on August 16, 2019, 11:51:25 AM
I want to insert unreferenced images like OLE.
Have an example of INSERTOBJ or an equivalent Autolisp function?
Title: Re: Use INSERTOBJ command in Autolisp or equivalent
Post by: hmspe on August 16, 2019, 02:30:24 PM
I use code like this.  This is to insert in model space, scaled based on DIMSCALE. 

(defun setpower ()
  (if (null (tblsearch "layer" "power"))
    (command "-layer" "make" "power" "color" "cyan" "power" "")
  )
  (setvar "clayer" "power")
)

(defun enco_insert (symbol / ds)
  (setvar "cmdecho" 0)
  (setpower)
  (setq ds (getvar "dimscale"))
  (prompt "\nSelect insertion point...  ")
  (command "_insert" symbol "PS" ds pause ds ds pause)
  (princ)
)
Title: Re: Use INSERTOBJ command in Autolisp or equivalent
Post by: FELIX on August 16, 2019, 02:40:46 PM
I need to insert a JPG image and not a block. OK?
Title: Re: Use INSERTOBJ command in Autolisp or equivalent
Post by: MP on August 16, 2019, 03:40:07 PM
Start with the entmake function if you understand how dictionaries work (e.g. "ACAD_IMAGE_DICT") or the AddRaster method of Paperspace / Modelspace if you prefer the ActiveX route.
Title: Re: Use INSERTOBJ command in Autolisp or equivalent
Post by: MP on August 16, 2019, 05:04:18 PM
Q & D ...

Code: [Select]
(defun _add-raster ( owner image-path point scale rotation / result )
    (if
        (eq 'vla-object
            (type
                (setq result
                    (vl-catch-all-apply
                       'vlax-invoke
                        (list owner 'AddRaster image-path point scale rotation)
                    )
                )
            )
        )                                               
        result
    )
)

Code: [Select]
(setq raster
    (_add-raster
        (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
        "C:\\Users\\MP\\Pictures\\The-Answer-Is-42.png"
        '(0.0 0.0 0.0)
        1.0
        0.0
    )   
)

Cheers.
Title: Re: Use INSERTOBJ command in Autolisp or equivalent
Post by: FELIX on August 16, 2019, 06:48:41 PM
The program worked but as a referenced image. This I already have. What I need is that it is "OLE2FRAME" "so when you have one or more files the DWG file will not be dependent on many external files.
If you can adapt this program optimally if you do not use "ENTMAKE" it should be the solution.