Author Topic: Create image entity using entmake?  (Read 4312 times)

0 Members and 1 Guest are viewing this topic.

Treddin

  • Guest
Create image entity using entmake?
« on: June 30, 2008, 11:07:06 AM »
Hi,

Using autolisp (or ADS), does anyone know how to create an image entity using entmake or any other way to create an image that doesn't use the -IMAGE command, GUI, VL, VLA or VBA? It has to be straight Autolisp (or ADS).

I know how to use entmake, but can't figure out how to use it to create images.

This is for autocad 2000.

Thanks

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Create image entity using entmake?
« Reply #1 on: June 30, 2008, 12:52:40 PM »
Welcome to theSwamp.

We like to teach here, but I thought this was a fun challenge for a Monday, so here is a working solution.  I think I got it all to work the way the image command does ( except for the scaling part ).

Code: [Select]
(defun AttachImage (ImName ImPath ImInsPt / ImDict ImDef Im tempEnt ReactData tempData EndList StartList)
   
    (if
        (and
            (setq ImDict
                (if (setq tempData (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
                    (cdr (assoc -1 tempData))
                    (dictadd
                        (namedobjdict)
                        "ACAD_IMAGE_DICT"
                        (entmakex
                            (list
                                (cons 0 "DICTIONARY")
                                (cons 100 "AcDbDictionary")
                                (cons 280 0)
                                (cons 281 1)
                            )
                        )
                    )
                )
            )
            (setq ImDef
                (dictadd
                    ImDict
                    ImName
                    (entmakex
                        (list
                            (cons 0 "IMAGEDEF")
                            (cons 100 "AcDbRasterImageDef")
                            (cons 1 ImPath)
                            (cons 280 1)
                            (cons
                                281
                                (if (equal (getvar 'Measurement) 0)
                                    5
                                    1
                                )
                            )
                        )
                    )
                )
            )
            (setq Im
                (entmake
                    (list
                        (cons 0 "IMAGE")
                        (cons 100 "AcDbEntity")
                        (cons 100 "AcDbRasterImage")
                        (cons 10 ImInsPt)
                        (cons 340 ImDef)
                        (cons 70 15)
                        (cons 280 0)
                        (cons 281 50)
                        (cons 282 50)
                        (cons 283 0)
                        (cons
                            360
                            (entmakex
                                (list
                                    (cons 0 "IMAGEDEF_REACTOR")
                                    (cons 100 "AcDbRasterImageDefReactor")
                                )
                            )
                        )
                    )
                )
            )
            (setq ReactData (entget (cdr (assoc 360 (entget (setq tempEnt (entlast)))))))
            (entmod
                (subst
                    (cons 330 tempEnt)
                    (assoc 330 ReactData)
                    ReactData
                )
            )
            (setq tempData (entget ImDef))
            (setq EndList (cdr (member (setq tempList (assoc 330 tempData)) tempData)))
            (setq StartList (reverse (cdr (member (car EndList) (reverse tempData)))))
            (entmod
                (append
                    StartList
                    (list (cons 330 (cdr (assoc 360 (entget tempEnt)))))
                    EndList
                )
            )
        )
        tempEnt
    )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Treddin

  • Guest
Re: Create image entity using entmake?
« Reply #2 on: June 30, 2008, 01:19:30 PM »
Thank you for responding  :-)

I tried running it and got an error at this point:

Code: [Select]
(dictadd ImDict
                         ImName
                         (entmakex (list (cons 0 "IMAGEDEF")
                                         (cons 100 "AcDbRasterImageDef")
                                         (cons 1 ImPath)
                                         (cons 280 1)
                                         (cons 281
                                               (if (equal (getvar 'Measurement) 0)
                                                 5
                                                 1
                                               ) ;_ end of if
                                         ) ;_ end of cons
                                   ) ;_ end of list
                         ) ;_ end of entmakex
                )

The error is:  Error: bad argument type: lentityp nil

It seems entmakex is returning nil

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Create image entity using entmake?
« Reply #3 on: June 30, 2008, 01:38:44 PM »
The only thing I can think of to check is to make sure the items are the same in the older version of Acad.  I'm on '06, and it works fine here, so I'm not sure what to take out, but that is what I would do.  I would start taking out what I think it doesn't need and see how that works.  You might only need the first three items in the list, so comment out the rest and rerun and see if that works.

You're welcome.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Treddin

  • Guest
Re: Create image entity using entmake?
« Reply #4 on: June 30, 2008, 02:34:24 PM »
It appears that it doesn't work until you've opened the image manager.  If you open acad and try it, it won't work, however if you have already opened the image manager (even in a different drawing) it does work. strange...

Thanks again for the help!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Create image entity using entmake?
« Reply #5 on: June 30, 2008, 02:49:50 PM »
It appears that it doesn't work until you've opened the image manager.  If you open acad and try it, it won't work, however if you have already opened the image manager (even in a different drawing) it does work. strange...

Thanks again for the help!
That is weird.  It works here in a brand new session, and that as the first thing I do.

As long as you got it working for you, it's all good.

You're welcome.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

jlsec

  • Mosquito
  • Posts: 2
Re: Create image entity using entmake?
« Reply #6 on: February 10, 2023, 08:00:44 AM »
Code - Auto/Visual Lisp: [Select]
  1.     ;;modify ratio
  2.     (setq width_ratio (/ width width_image))
  3.     (setq ImageEnt (entget (entlast)))
  4.     (setq ImageEnt
  5.         (subst
  6.             (cons 11 (list width_ratio 0 0))
  7.             (assoc 11 ImageEnt )
  8.             tempEnt
  9.     ))
  10.    
  11.     (setq height_ratio (/ height height_image))
  12.     (setq ImageEnt
  13.         (subst
  14.             (cons 12 (list 0 height_ratio 0))
  15.             (assoc 12 ImageEnt )
  16.             ImageEnt
  17.     ))
  18.    
  19.     (entmod ImageEnt )


EDIT (John): Added code tags.
« Last Edit: February 10, 2023, 08:34:44 AM by JohnK »