Author Topic: Get_File_Properties  (Read 7388 times)

0 Members and 1 Guest are viewing this topic.

cwake

  • Mosquito
  • Posts: 10
Re: Get_File_Properties
« Reply #30 on: March 04, 2014, 01:37:06 AM »
I don't have answers, sorry, but your question has intrigued me enough to do some research. It would appear that the GPS data is stored in a different manner to the typical windows properties? It would appear that it is "EXIF" data that you need to look into.
I found the following links including a way to access it using common LISP. I don't have time to look at it closer right now, but I am intrigued to find out if this is possible?

http://www.media.mit.edu/pia/Research/deepview/exif.html
http://www.theswamp.org/index.php?topic=41358.0
http://www.xach.com/lisp/zpb-exif/
Clint

ymg

  • Swamp Rat
  • Posts: 725
Re: Get_File_Properties
« Reply #31 on: March 04, 2014, 03:39:27 AM »
Here's alink to what I use to get to the exif data.

ExifToolGUI v. 5.15

ymg

cwake

  • Mosquito
  • Posts: 10
Re: Get_File_Properties
« Reply #32 on: March 04, 2014, 04:39:00 PM »
This could be a start... There are more things that you can do with the properties object eg. "IsVector" "Type".

Code - Auto/Visual Lisp: [Select]
  1. (defun exifdata ( file / err idata iprop oimg )
  2.  (if (and (setq file (findfile file))
  3.           (setq oimg (vlax-create-object "WIA.Imagefile"))
  4.           )
  5.    (progn
  6.      (setq err (vl-catch-all-apply
  7.                  (function
  8.                    (lambda nil
  9.                      (vlax-invoke-method oimg 'loadfile file)
  10.                      (setq iprop (vlax-get-property oimg 'properties))
  11.                      (vlax-for x iprop
  12.                        (setq idata (cons (cons (vlax-get-property x 'name) (vlax-variant-value (vlax-get-property x 'value))) idata))
  13.                        )
  14.                      )
  15.                    )
  16.                  )
  17.            )
  18.      (foreach obj (list iprop oimg)
  19.        (if (= 'vla-object (type obj))
  20.          (vlax-release-object obj)
  21.          )
  22.        )
  23.      (if (null (vl-catch-all-error-p err)) (reverse idata))
  24.      )
  25.    )
  26.  )
  27.  
Clint

Gemini

  • Mosquito
  • Posts: 5
Re: Get_File_Properties
« Reply #33 on: January 10, 2019, 04:04:21 PM »
This works perfectly cwake in my images with GPS information.
But I get something like this:
("GpsLatitudeRef" . "N") ("GpsLatitude" . #<VLA-OBJECT IVector 00000235c7ec2540>)
("GpsLongitudeRef" . "W") ("GpsLongitude" . #<VLA-OBJECT IVector 00000235c7ec1a50>)
How can I put the "GpsLatitude" and "GpsLongitude" with logical values, that I can understand.
Example: "41.352056°" and "8.180461°" or UTM coordinates.
Thank you.

Rod

  • Newt
  • Posts: 106
Re: Get_File_Properties
« Reply #34 on: January 10, 2019, 04:17:24 PM »
I have started on this. Here is my progress. Rough but working for me.
I looked up -windows image acquition-
If you develop it further please post your lsp.
Thanks, Rod.

[EDIT Should have cleaned this up and commented more. Sorry flat out at the moment, hope it's helpful]

Code - Auto/Visual Lisp: [Select]
  1. (defun exifdata (file / idata)
  2.  ;;/ err idata iprop imgObj )
  3.  (if (and (setq file (findfile file))
  4.   (setq imgObj (vlax-create-object "WIA.Imagefile"))
  5.      ) ;_ end of and
  6.    (progn
  7.      (setq
  8. err (vl-catch-all-apply
  9.      (function
  10. (lambda nil
  11.  (vlax-invoke-method imgObj 'loadfile file)
  12.  (setq iprop (vlax-get-property imgObj 'properties))
  13.  (princ "\nProperties")
  14. ) ;_ end of lambda
  15.      ) ;_ end of function
  16.    ) ;_ end of vl-catch-all-apply
  17.      ) ;_ end of setq
  18.      (if (null (vl-catch-all-error-p err))
  19.  ;;(dumpall iprop)
  20.  (setq idata (getall iprop))
  21.  (princ "\nData")
  22.  ;;(dumpall idata)
  23. ) ;_ end of progn
  24.      ) ;_ end of if
  25. ;_ end of if
  26.    ) ;_ end of progn
  27.  ) ;_ end of if
  28.  iprop
  29. ) ;_ end of defun
  30.  
  31. ;;take a list of files return a list of dotted pairs eg ("Filename" . "C:temp")("Latitude" -35.4576)(Longtitude "149.1234)
  32.  
  33. ;;;(defun C:test (/ idata)
  34. ;;;  (setq file (getfiled "" "" "" 0))
  35. ;;;  (setq iprop (exifdata file))
  36. ;;;  (setq lat (getgpslat valuelist))
  37. ;;;  (setq long (getgpslong valuelist))
  38. ;;;  (rel)
  39. ;;;  (setq pt (list long lat))
  40. ;;;  (setq actpt (lltoact pt))
  41. ;;;  (princ)
  42. ;;;) ;_ end of defun
  43.  
  44. (defun c:test (/ pathAndFiles path files file imageFiles locationsList)
  45.  (setq pathAndFiles (dos_getfilem "Select images to insert into drawing" "Y:\\" "*.JPG;*.JPEG;*.PNG;*.TIFF"))
  46.  (setq path (car pathAndFiles))
  47.  (setq files (cdr pathAndFiles))
  48.  (foreach file files
  49.    (setq imageFiles (cons (strcat path file) imageFiles))
  50.  ) ;_ end of foreach
  51.  (setq imageFiles (reverse imageFiles))
  52.  (setq locationsList (getImageLocations imagefiles))
  53.  (insertPhotoLocationBlocks locationsList)
  54. ) ;_ end of defun
  55.  
  56. (defun insertPhotoLocationBlocks (locationsList)
  57.  (foreach lst locationsList
  58.    (setq file (car lst))
  59.    (setq pt (cadr lst))
  60.    (setq rot (caddr lst))
  61.    (if rot
  62.      (command "insert" "PHOTO LOCATION" pt 1 1 rot)
  63.      (command "insert" "PHOTO LOCATION" pt 1 1 0)
  64.    ) ;_ end of if
  65.    (command "-hyperlink" "insert" "object" "last" "" file "" file)
  66.  ) ;_ end of foreach
  67. ) ;_ end of defun
  68.  
  69. (defun rel ()
  70.  (foreach obj (list iprop imgObj)
  71.    (if (= 'vla-object (type obj))
  72.      (vlax-release-object obj)
  73.    ) ;_ end of if
  74.  ) ;_ end of foreach
  75. ) ;_ end of defun
  76.  
  77. (defun getImageLocations (imageList)
  78.  (setq imgObj (vlax-create-object "WIA.Imagefile"))
  79.  (foreach image imageList
  80.    (if (setq imageFile (findfile image))
  81.      (progn
  82. (setq locationlist (getImageLocation imgObj imageFile))
  83. (if locationlist
  84.  (setq locationsList (cons locationlist locationsList))
  85.  (princ (strcat "\nCouldn't find location for " imageFile))
  86. ) ;_ end of if
  87.      ) ;_ end of progn
  88.      (princ (strcat "\nCouldn't find file for " image))
  89.    ) ;_ end of if
  90.  ) ;_ end of foreach
  91.  (if (listp locationsList)
  92.    (reverse locationsList)
  93.    nil
  94.  ) ;_ end of if
  95. ) ;_ end of defun
  96.  
  97. (defun getImageLocation (imgObj imageFile)
  98.  (setq
  99.    err (vl-catch-all-apply
  100.    (lambda nil
  101.      (vlax-invoke-method imgObj 'loadfile imageFile)
  102.      (setq iprop (vlax-get-property imgObj 'properties))
  103.    ) ;_ end of lambda
  104.  ) ;_ end of function
  105. ) ;_ end of vl-catch-all-apply
  106.  ) ;_ end of setq
  107.    (progn
  108.      (setq idata (getall iprop))
  109.      (setq lat (getgpslat idata))
  110.      (setq long (getgpslong idata))
  111.      (setq dir (getGpsDir idata))
  112.      (setq pt (list long lat))
  113.      (setq actpt (lltoact pt))
  114.    ) ;_ end of progn
  115.  ) ;_ end of if
  116. ;;;  (if (= 'vla-object (type iprop))
  117. ;;;    (vlax-release-object iprop)
  118. ;;;  ) ;_ end of if
  119.  (list imageFile actpt dir)
  120. ) ;_ end of defun
  121.  
  122.  
  123.  
  124. ;;;(defun getall (collection / err x valuelist)
  125. ;;;  ;;
  126. ;;;  (setq
  127. ;;;    err (vl-catch-all-apply
  128. ;;;  (function
  129. ;;;    (lambda nil
  130. ;;;      (vlax-for x collection
  131. ;;; ;;(vlax-dump-object x T)
  132. ;;; (setq
  133. ;;;  valuelist
  134. ;;;   (cons (cons (vlax-get-property x 'name)
  135. ;;;       (vlax-variant-value
  136. ;;; (vlax-get-property x 'value)
  137. ;;;       ) ;_ end of vlax-variant-value
  138. ;;; ) ;_ end of cons
  139. ;;; valuelist
  140. ;;;   ) ;_ end of cons
  141. ;;; ) ;_ end of setq
  142. ;;;      ) ;_ end of vlax-for
  143. ;;;    ) ;_ end of lambda
  144. ;;;  ) ;_ end of function
  145. ;;; ) ;_ end of vl-catch-all-apply
  146. ;;;  ) ;_ end of setq
  147. ;;;
  148. ;;;  (if (listp valuelist);;(null (vl-catch-all-error-p err))
  149. ;;;    (reverse valuelist)
  150. ;;;  ) ;_ end of if
  151. ;;;) ;_ end of defun
  152.  
  153. (defun getall (collection / err x valuelist name prop)
  154.  (vlax-for x collection
  155.    (setq name (vl-catch-all-apply '(lambda nil (vlax-get-property x 'name))))
  156.    (setq prop (vl-catch-all-apply '(lambda nil (vlax-variant-value (vlax-get-property x 'value)))))
  157.      (setq valuelist (cons (cons name prop) valuelist))
  158.    ) ;_ end of if
  159.    ;;(vlax-dump-object x T)
  160. ;_ end of setq
  161.  ) ;_ end of vlax-for
  162.  (if (listp valuelist)
  163.    ;;(null (vl-catch-all-error-p err))
  164.    (reverse valuelist)
  165.  ) ;_ end of if
  166. ;;;  (foreach x (reverse valuelist)
  167. ;;;    (princ (strcat "\n" (vl-princ-to-string x)))
  168. ;;;  ) ;_ end of foreach
  169. ) ;_ end of defun
  170.  
  171.  
  172. (defun dumpall (collection)
  173.  (setq
  174.    err (vl-catch-all-apply
  175.    (lambda nil
  176.      (vlax-for x collection
  177.  
  178.      ) ;_ end of vlax-for
  179.    ) ;_ end of lambda
  180.  ) ;_ end of function
  181. ) ;_ end of vl-catch-all-apply
  182.  ) ;_ end of setq
  183.  
  184.    (reverse valuelist)
  185.  ) ;_ end of if
  186. ) ;_ end of defun
  187.  
  188. (defun getitemfromcollection (collection itemname / valuelist)
  189.  (setq
  190.    err (vl-catch-all-apply
  191.    (lambda nil
  192.      (vlax-for x collection
  193.  valuelist
  194.   (cons (vlax-get-property x itemname)
  195. valuelist
  196.   ) ;_ end of cons
  197. ) ;_ end of setq
  198.      ) ;_ end of vlax-for
  199.    ) ;_ end of lambda
  200.  ) ;_ end of function
  201. ) ;_ end of vl-catch-all-apply
  202.  ) ;_ end of setq
  203.    (reverse valuelist)
  204.    nil
  205.  ) ;_ end of if
  206. ) ;_ end of defun
  207.  
  208.  
  209. (defun getGpsLatref (idata / dottedpair ref)
  210.  (if (setq dottedpair (assoc "GpsLatitudeRef" idata))
  211.    (setq ref (cdr dottedpair))
  212.  ) ;_ end of if
  213.  (if (equal ref "S")
  214.    (setq ref -1)
  215.    (setq ref 1)
  216.  ) ;_ end of if
  217. ) ;_ end of defun
  218.  
  219. (defun getGpsLongref (idata / dottedpair ref)
  220.  (if (setq dottedpair (assoc "GpsLongitudeRef" idata))
  221.    (setq ref (cdr dottedpair))
  222.  ) ;_ end of if
  223.  (if (equal ref "W")
  224.    (setq ref -1)
  225.    (setq ref 1)
  226.  ) ;_ end of if
  227. ) ;_ end of defun
  228.  
  229. (defun getimagewidth (idata)
  230.  (if (setq dottedpair (assoc "ImageWidth" idata))
  231.    (cdr dottedpair)
  232.    nil
  233.  ) ;_ end of if
  234. ) ;_ end of defun
  235.  
  236. (defun getimageheight (idata / dottedpair)
  237.  (if (setq dottedpair (assoc "ImageHeight" idata))
  238.    (cdr dottedpair)
  239.    nil
  240.  ) ;_ end of if
  241. ) ;_ end of defun
  242.  
  243. (defun getGpsLat (idata / gpsLatobj)
  244.  (if (and (setq pair (assoc "GpsLatitude" idata))
  245.   (setq gpsLatobj (cdr pair))
  246.   (setq lat (getgpsvalue gpsLatobj))
  247.   (setq ref (getGpsLatref idata))
  248.      ) ;_ end of and
  249.    (* lat ref)
  250.    nil
  251.  ) ;_ end of if
  252. ) ;_ end of defun
  253.  
  254. (defun getGpsDir (idata)
  255.  (if (and (setq pair (assoc "GpsImgDir" idata))
  256.   (setq GpsImgDirObj (cdr pair))
  257.   (setq imgDir (vlax-get-property GpsImgDirObj 'value))
  258.      ) ;_ end of and
  259.    (setq imgDir (- imgDir 12.9))
  260.  ) ;_ end of if
  261. ) ;_ end of defun
  262.  
  263.  
  264.  
  265.  
  266. (defun getGpsLong (idata / gpslongobj)
  267.  (if (and (setq pair (assoc "GpsLongitude" idata))
  268.   (setq gpslongobj (cdr pair))
  269.   (setq long (getgpsvalue gpslongobj))
  270.   (setq ref (getGpsLongref idata))
  271.      ) ;_ end of and
  272.    (* long ref)
  273.    nil
  274.  ) ;_ end of if
  275. ) ;_ end of defun
  276.  
  277. (defun getgpsvalue (vectorObj / Numlist Denomlist i numerator denominator dms dd)
  278.  (setq Numlist (getitemfromcollection vectorobj "Numerator"))
  279.  (setq Denomlist (getitemfromcollection vectorobj "Denominator"))
  280.  (setq i 0)
  281.  (repeat 3
  282.    (if (and (setq numerator (nth i Numlist))
  283.     (setq denominator (nth i Denomlist))
  284.     (not (zerop denominator))
  285. ) ;_ end of and
  286.      (setq dms (cons (/ (float numerator) denominator) dms))
  287.      (setq dms (cons 0 dms))
  288.    ) ;_ end of if
  289.    (setq i (1+ i))
  290.  ) ;_ end of repeat
  291.  (setq dms (reverse dms))
  292.  (setq dd (getdecimaldegrees dms))
  293. ) ;_ end of defun
  294.  
  295. (defun getdecimaldegrees (dms)
  296.  (+ (car dms) (/ (cadr dms) 60) (/ (caddr dms) 3600))
  297. ) ;_ end of defun
  298.  
  299. (defun ACTtoLL (pt)
  300.  (ade_projptbackward pt)
  301. ) ;_ end of defun
  302.  
  303. (defun LLtoACT (pt)
  304.  ;;pt must be a list in the form of long lat
  305.  (ade_projptforward pt)
  306. ) ;_ end of defun
  307.  
  308. (ade_projsetsrc "LL84")
  309. (ade_projsetdest "SGC")
  310. (princ "\nGeo.lsp loaded")
  311. (princ "\nGPS.lsp loaded")
  312. ;|«Visual LISP© Format Options»
  313. (200 2 40 2 T "end of " 100 20 0 0 0 T T nil T)
  314. ;*** DO NOT add text below the comment! ***|;
  315.  
  316.  
« Last Edit: January 10, 2019, 04:21:13 PM by Rod »
Standing on the toes of giants.

Gemini

  • Mosquito
  • Posts: 5
Re: Get_File_Properties
« Reply #35 on: January 10, 2019, 04:44:30 PM »
Sorry to bother you, but some functions are missing:
"dos_getfilem", "ade_projsetsrc" and "ade_projsetdest".
Thank you.

Rod

  • Newt
  • Posts: 106
Re: Get_File_Properties
« Reply #36 on: January 10, 2019, 05:17:24 PM »
Hi Gemini,

dos_getfilem is part of doslib (free download arx that extends lisp with additional functions, been around for along time really useful)
"ade_projsetsrc" and "ade_projsetdest" are lisp functions that included with autocad map

You will have to hack into my code but it should help you unravel the ivector object.

I might have some time next week to help if you are stuck. Otherwise and hopefully someone else with better programming skills will jump in!
Standing on the toes of giants.

Gemini

  • Mosquito
  • Posts: 5
Re: Get_File_Properties
« Reply #37 on: January 11, 2019, 02:36:54 PM »
I had installed the "doslib" and the "dos_getfilem" seems to work perfectly. Thank you.
I will try to with your code, get the real values off "ivector object". But I don't have AutoCAD Map, to resolve "ade_projptbackward", "ade_projsetsrc" and "ade_projsetdest" Map functions :(

Rod

  • Newt
  • Posts: 106
Re: Get_File_Properties
« Reply #38 on: January 13, 2019, 05:08:24 PM »
Rather than reproject them if your drawing has a coordinate system attached (geographiclocation https://help.autodesk.com/view/CIV3D/2019/ENU/index.html?guid=GUID-10A3B776-A0FA-4438-B29B-EA22C070A27E) you could use
(COMMAND "GEOMARKLATLONG" latitude longitude filename)
Standing on the toes of giants.

Gemini

  • Mosquito
  • Posts: 5
Re: Get_File_Properties
« Reply #39 on: January 14, 2019, 08:03:56 AM »
Hi Rod, many thanks for your suggestion.
But I want to insert hundreds of pictures in lots of drawings. And for that, I'm trying to use lisp. With "geo..." locations commands, I need to use a program to extract lat an log, coordinates from the pictures(exif), and after that to make a script(that's an idea). With lisp is more easy and simple.

GDF

  • Water Moccasin
  • Posts: 1961
Re: Get_File_Properties
« Reply #40 on: January 14, 2019, 04:13:37 PM »
Awesome MP

I also tested it in BricsCAD 18.2
How do you print the return list in a column format?

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 1961
Re: Get_File_Properties
« Reply #41 on: January 16, 2019, 01:43:42 PM »
Awesome MP

I also tested it in BricsCAD 18.2
How do you print the return list in a column format?

I added this to the end of your code, to print out the results to a text file:

    (setq fh (open "f:/Propertiy Result.txt" "w"))   
    (foreach x result (write-line (vl-prin1-to-string x) fh))
    (close fh)


I assume this is the best way?
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 1961
Re: Get_File_Properties
« Reply #42 on: January 16, 2019, 02:02:01 PM »
Edit to last post:

    (setq fh (open (strcat (getvar "Dwgprefix")(vl-filename-base (getvar "dwgname")) "-FilePropertyResults.txt") "w"))
    (foreach x result (write-line (vl-prin1-to-string x) fh))
    (close fh)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #43 on: January 16, 2019, 04:51:24 PM »
I assume this is the best way?

Of all the ways it could be done it's definitely one of them. :)

Another way might [be] to ensure the output name is write-able — bailing if not — or creating a new output name that is [write-able].

Edit: Fixed typos.
« Last Edit: January 16, 2019, 08:45:53 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About