Author Topic: dictionaries question  (Read 4813 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
dictionaries question
« on: June 16, 2014, 02:25:52 PM »
What is the Visual Lisp version of this?
Code: [Select]
(mapcar 'print (entget (namedobjdict)))

I have figured out that using this will get me the image dictionary object "IAcadObject", but I need to get to the raster image how do I get to the raster "IAcadRasterImage"

Code: [Select]
  (setq Dic (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))))

  (setq imDic (vla-item Dic "ACAD_IMAGE_DICT"))

Thanks...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: dictionaries question
« Reply #1 on: June 16, 2014, 05:41:58 PM »
What is the Visual Lisp version of this?
Code: [Select]
(mapcar 'print (entget (namedobjdict)))
Code: [Select]
(vlax-for dic (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-dump-object dic)
)

cadman6735

  • Guest
Re: dictionaries question
« Reply #2 on: June 16, 2014, 05:56:53 PM »
Thanks Lee,

cadman6735

  • Guest
Re: dictionaries question
« Reply #3 on: June 18, 2014, 09:57:24 AM »
Ok, I am struggling here...  I have been at this for a few days now, inching my way along.  I managed to piece this together but it only works by selecting the image.

Code: [Select]
(defun c:test ( / )(vl-load-com)
 
  (setq ActiveDocument (vla-get-activedocument (vlax-get-acad-object))) 

;-----------------------------------------------------------------------------------------

    (vla-StartUndoMark ActiveDocument) ;Start of UNDO

;-----------------------------------------------------------------------------------------
 
  (setq *imageObj (vlax-ename->vla-object (cdr (car (entget (car (entsel))))))
*imagePath (strcase (vla-get-imageFile *imageObj))
*imageString (strcase "*tpf*")
*imageName "CorpLogo"
  )

  ;(setq *imageObj (dictsearch

  (if (wcmatch *imagePATH *imageString)
    (progn
      (vla-put-imagefile *imageObj "C:\\AutoDesk\\CAE_Custom\\AutoCAD\\Support\\Icons\\CorpLogo.png")
      (vla-put-name *imageObj *imageName)
      (command "-image" "reload" *imageName)
    )
  )
 
  (vla-regen ActiveDocument acAllViewports)

;-----------------------------------------------------------------------------------------

    (vla-EndUndoMark ActiveDocument) ;End of UNDO

;-----------------------------------------------------------------------------------------

(princ)
)

I want to run it in a macro, so I went the direction of (ssget)

This is not 100% my code, I found something close on line and manipulated to do what I need but it does not access images in blocks.

Code: [Select]
(defun c:test ( / );Activedocument ImageString ImageName cnt ss ImageObj)(vl-load-com)
 
  (setq ActiveDocument (vla-get-activedocument (vlax-get-acad-object))) 

;-----------------------------------------------------------------------------------------

    (vla-StartUndoMark ActiveDocument) ;Start of UNDO

;-----------------------------------------------------------------------------------------
 
  (setq ImageString (strcase "*tpf*")
ImageName "CorpLogo"
ImagePath "C:\\AutoDesk\\CAE_Custom\\AutoCAD\\Support\\Icons\\CorpLogo.png"
  )

  (setq cnt 0)

  (if (setq ss (ssget "x" '(( 0 . "IMAGE"))))
    (repeat (sslength ss)
      (setq ImageObj (vlax-ename->vla-object (ssname ss cnt)))
      (if (wcmatch (strcase (vlax-get ImageObj 'Name)) ImageString)
(progn
  (vla-put-imagefile ImageObj ImagePath)
  (vla-put-name ImageObj ImageName)
  (command "-image" "reload" ImageName)
  (vla-regen ActiveDocument acAllViewports)
)  
      )
      (setq cnt (1+ cnt))
    )
  )

;-----------------------------------------------------------------------------------------

    (vla-EndUndoMark ActiveDocument) ;End of UNDO

;-----------------------------------------------------------------------------------------

(princ)
)

I am really curious about this:
Code: [Select]
(vlax-get ImageObj 'Name)
I can't find vlax-get in the help menu and I am not sure where 'Name comes from so if I can get some insight on this, that would be great.

Then I found or came up with this:

Code: [Select]
(defun c:test  ( / )

  (setq Image (dictsearch (namedobjdict) "acad_image_dict"))

  (mapcar 'print Image)

(princ)
)

Which gives me the dotted pair, great I though, all I need to do is using dictnext to access the 3 . "image", there is more than one image in some file and thought this would be easy, I can't figure out how to use "dictnext"

I am so frustrated at this point.

Can I please have an example of how to use dictnext to access a dotted pair that has more than one 3 . "image"

I seem to get stronger with my lisp each time I come back to it but freak, I keep hitting these wall and get so confused it is frustrating.

Thanks

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dictionaries question
« Reply #4 on: June 18, 2014, 11:00:23 AM »
See if this helps you:
Code: [Select]
(defun c:foo (/ el newpath oldpath)
  (setq newpath "C:\\AutoDesk\\CAE_Custom\\AutoCAD\\Support\\Icons\\CorpLogo.png")
  (foreach imagedef (mapcar 'cdr
    (vl-remove-if-not
      '(lambda (x) (= (car x) 350))
      (dictsearch (namedobjdict) "acad_image_dict")
    )
    )
    (and (setq el (entget imagedef))
(setq oldpath (cdr (assoc 1 el)))
(wcmatch (strcase oldpath) "*TPF*")
;; Change path
(entmod (setq el (subst (cons 1 newpath) (assoc 1 el) el)))
;; Get dictionary
(setq el (entget (cdr (assoc 330 el))))
;; Change name
(entmod (subst '(3 . "CorpLogo") (assoc 3 el) el))
;; Everything worked so print path to command line
(print path)
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dictionaries question
« Reply #5 on: June 19, 2014, 09:15:39 AM »
Did this fix your problem ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadman6735

  • Guest
Re: dictionaries question
« Reply #6 on: June 19, 2014, 09:45:48 AM »
ronjon

Thank you sir, you are a kind man, this does exactly what I need, but you gave me the fish, which I appreciate

I still want to learn and I am stubborn, so, in the code I posted - "(vlax-get ImageObj 'Name)"  What is this vlax-get and 'Name?  They just seem to come from no where.

In the list below, I have a list of dotted pairs, say I wanted the second or third image, When really I want the (350 . <Entity Name>) of the second or third image.  So for example, image named "General2" and I need to access "General2" (350 . <Entity Name>)

Code: [Select]
(-1 . <Entity name: 7ffffb16ab0>)
(0 . "DICTIONARY")
(5 . "1F83")
(102 . "{ACAD_REACTORS")
(330 . <Entity name: 7ffffb9a8c0>)
(102 . "}")
(330 . <Entity name: 7ffffb9a8c0>)
(100 . "AcDbDictionary")
(280 . 0)
(281 . 1)
(3 . "CorpLogo")
(350 . <Entity name: 7ffffb16ac0>)
(3 . "General2")
(350 . <Entity name: 7ffffb6f6b0>)
(3 . "Geotechnical")
(350 . <Entity name: 7ffffb6f680>)

I am having trouble navigating a list of dotted pairs...

Thanks for all your help,

cadman6735

  • Guest
Re: dictionaries question
« Reply #7 on: June 19, 2014, 09:49:27 AM »
Sorry ronjon,

I was responding to your post as you posted your last post, I took the rest of the day off yesterday from trying to figure out LISP.  This comes easy to you guys, not to me.   :embarrassed:

ronjonp

  • Needs a day job
  • Posts: 7529
Re: dictionaries question
« Reply #8 on: June 19, 2014, 10:45:16 AM »
ronjon

Thank you sir, you are a kind man, this does exactly what I need, but you gave me the fish, which I appreciate

I still want to learn and I am stubborn, so, in the code I posted - "(vlax-get ImageObj 'Name)"  What is this vlax-get and 'Name?  They just seem to come from no where.

In the list below, I have a list of dotted pairs, say I wanted the second or third image, When really I want the (350 . <Entity Name>) of the second or third image.  So for example, image named "General2" and I need to access "General2" (350 . <Entity Name>)

Code: [Select]
(-1 . <Entity name: 7ffffb16ab0>)
(0 . "DICTIONARY")
(5 . "1F83")
(102 . "{ACAD_REACTORS")
(330 . <Entity name: 7ffffb9a8c0>)
(102 . "}")
(330 . <Entity name: 7ffffb9a8c0>)
(100 . "AcDbDictionary")
(280 . 0)
(281 . 1)
(3 . "CorpLogo")
(350 . <Entity name: 7ffffb16ac0>)
(3 . "General2")
(350 . <Entity name: 7ffffb6f6b0>)
(3 . "Geotechnical")
(350 . <Entity name: 7ffffb6f680>)

I am having trouble navigating a list of dotted pairs...

Thanks for all your help,


vlax-get is documented as vlax-get-property in the AutoCAD HELP file. Be aware that vlax-get will sometimes return a different data type than vla-get-<property>. A good example is (vla-get-insertionpoint obj)  vs. (vlax-get obj 'insertionpoint). The first returns a safearray and the latter a list.


As for getting items from a dotted pair list, take a look at the code below.
Code: [Select]
;; This removes all items in your list except the 350 entries (car x) which are your image definitions
(setq l (vl-remove-if-not '(lambda (x) (= (car x) 350)) (dictsearch (namedobjdict) "acad_image_dict")))
;; CAR Returns '(350 350 350 ..)
(alert (vl-princ-to-string (mapcar 'car l)))
;; CDR Returns '(<ename1> <ename1> <ename1>)
(alert (vl-princ-to-string (mapcar 'cdr l)))
;; If you wanted to get a list of image names, you'd grab the 3 entries like so
(setq l (vl-remove-if-not '(lambda (x) (= (car x) 3)) (dictsearch (namedobjdict) "acad_image_dict")))
;; CAR Returns '(3 3 3 ..)
(alert (vl-princ-to-string (mapcar 'car l)))
;; CDR Returns '(<name1> <name2> <name3>)
(alert (vl-princ-to-string (mapcar 'cdr l)))


;; Clear as mud? :)


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

owenwengerd

  • Bull Frog
  • Posts: 451
Re: dictionaries question
« Reply #9 on: June 19, 2014, 11:12:08 AM »
I am having trouble navigating a list of dotted pairs...

I would retrieve it like this (untested):

Code: [Select]
(defun getimg (name elist)
  (cdr (cadr (member (cons 3 name) elist)))
)

cadman6735

  • Guest
Re: dictionaries question
« Reply #10 on: June 19, 2014, 03:57:54 PM »
member

I tried this but obviously didn't do it right...  But your code worked, thanks

cadman6735

  • Guest
Re: dictionaries question
« Reply #11 on: June 23, 2014, 08:33:12 AM »
ronjon, thanks again for your help, your code saved me a ton of time and the breakdown is great, thanks for helping me understand, I was a little frustrated last week.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: dictionaries question
« Reply #12 on: June 23, 2014, 09:04:45 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun f (l)
  2.   (cond ((not l) l)
  3.         ((= (caar l) 3) (cons (cons (cdar l) (cdadr l)) (f (cddr l))))
  4.         ((f (cdr l)))
  5.   )
  6. )
  7. (f (dictsearch (namedobjdict) "acad_image_dict"))

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: dictionaries question
« Reply #13 on: June 23, 2014, 09:07:06 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun f1 (l)
  2.   (vl-remove nil(mapcar(function(lambda(a b)(if (= (car a)3)(cons (cdr a)(cdr b)))))l(cdr l)))
  3. )
  4. (f1 (dictsearch (namedobjdict) "acad_image_dict"))

cadman6735

  • Guest
Re: dictionaries question
« Reply #14 on: June 23, 2014, 09:19:15 AM »
you guys must be wired differently, I am looking at code with my head in my hand, rubbing my forehead with a dumbfounded blank stare on my face.

For what you guys can do, you rock...