Author Topic: Use INSERTOBJ command in Autolisp or equivalent  (Read 2162 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 241
Use INSERTOBJ command in Autolisp or equivalent
« 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?
OK.

hmspe

  • Bull Frog
  • Posts: 362
Re: Use INSERTOBJ command in Autolisp or equivalent
« Reply #1 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)
)
"Science is the belief in the ignorance of experts." - Richard Feynman

FELIX

  • Bull Frog
  • Posts: 241
Re: Use INSERTOBJ command in Autolisp or equivalent
« Reply #2 on: August 16, 2019, 02:40:46 PM »
I need to insert a JPG image and not a block. OK?
OK.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Use INSERTOBJ command in Autolisp or equivalent
« Reply #3 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Use INSERTOBJ command in Autolisp or equivalent
« Reply #4 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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

FELIX

  • Bull Frog
  • Posts: 241
Re: Use INSERTOBJ command in Autolisp or equivalent
« Reply #5 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.
OK.