TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Treddin 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
-
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 ).
(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
)
)
-
Thank you for responding :-)
I tried running it and got an error at this point:
(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
-
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.
-
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!
-
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.
-
;;modify ratio
(setq width_ratio
(/ width width_image
)) tempEnt
))
(setq height_ratio
(/ height height_image
)) ImageEnt
))
EDIT (John): Added code tags.