Author Topic: Get_File_Properties  (Read 7386 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17300
Get_File_Properties
« on: April 26, 2011, 04:27:34 PM »
Reader's Digest Version: I needed a function to grab the extended properties for a file (specifically Title, Subject, Category ... for LISP files). I wrote this quick and dirty and it appears to work:

Code: [Select]
(defun [color=red]_Get_File_Properties_Ex[/color] ( file / result shell name_space items item )

    [color=green];;  Get a file's extended properties (Title, Subject, Category ...)
    ;;  returning the result as a list of cons pairs:
    ;;
    ;;      (   ("Name" . "Drawing.dwg")
    ;;          ("Size" . "42 KB")
    ;;          ("Type" . "DWG File")
    ;;          ("Date Modified" . "2011/03/21 10:57 AM")
    ;;          ...
    ;;      )[/color]

    (vl-catch-all-apply
        (function
            (lambda ( / folder_name file_name i count )    
                (setq
                    folder_name (vl-filename-directory file)
                    file_name   (strcat (vl-filename-base file) (vl-filename-extension file))
                    shell       (vlax-create-object "Shell.Application")
                    name_space  (vlax-invoke shell 'NameSpace folder_name)
                    items       (vlax-invoke name_space 'Items)
                    item        (vlax-invoke name_space 'ParseName file_name)
                    i           (setq count 300)
                )
                (if item
                    (repeat count
                        (setq result
                            (cons
                                (cons
                                    (vlax-invoke
                                        name_space
                                       'GetDetailsOf
                                        items
                                        (setq i (1- i))
                                    )
                                    (vlax-invoke
                                        name_space
                                       'GetDetailsOf
                                        item
                                        i
                                    )
                                )    
                                result
                            )
                        )
                    )
                )    
            )                
        )        
    )
    
    (vl-catch-all-apply 'vlax-release-object (list item))
    (vl-catch-all-apply 'vlax-release-object (list items))
    (vl-catch-all-apply 'vlax-release-object (list name_space))
    (vl-catch-all-apply 'vlax-release-object (list shell))
    
    (vl-remove-if
        (function (lambda (item) (eq "" (car item))))
        result
    )    
    
)

Test run (under XP):

(_Get_File_Properties_Ex "c:\\tests\\SampleDrawing.dwg")

(
    ("Name" . "SampleDrawing.dwg")
    ("Size" . "42 KB")
    ("Type" . "DWG File")
    ("Date Modified" . "2011/03/21 10:57 AM")
    ("Date Created" . "2011/03/10 3:03 PM")
    ("Date Accessed" . "2011/04/26 1:32 PM")
    ("Attributes" . "A")
    ("Status" . "Online")
    ("Owner" . "COMPANY\\USERNAME")
    ("Author" . "")
    ("Title" . "")
    ("Subject" . "")
    ("Category" . "")
    ("Pages" . "")
    ("Comments" . "")
    ("Copyright" . "")
    ("Artist" . "")
    ("Album Title" . "")
    ("Year" . "")
    ("Track Number" . "")
    ("Genre" . "")
    ("Duration" . "")
    ("Bit Rate" . "")
    ("Protected" . "")
    ("Camera Model" . "")
    ("Date Picture Taken" . "")
    ("Dimensions" . "")
    ("Episode Name" . "")
    ("Program Description" . "")
    ("Audio sample size" . "")
    ("Audio sample rate" . "")
    ("Channels" . "")
    ("Company" . "")
    ("Description" . "")
    ("File Version" . "")
    ("Product Name" . "")
    ("Product Version" . "")
    ("DWG Creator Name" . "")
    ("DWG Creator Version" . "")
    ("Keywords" . "")
)


I could use the black board for the shell object >> next version will, no time right now. PS: Let me know if it works / doesn't work for you. Thanks and cheers, MP.

PS: For use with any file, not just drawings. I'm using it to categorize LISP files regardless of their folder parentage.

Edit: Revised number items the function interrogates for from 34 to 300.
« Last Edit: April 27, 2011, 10:59:47 AM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

alanjt

  • Needs a day job
  • Posts: 5324
  • Standby for witty remark...
Re: Get_File_Properties
« Reply #1 on: April 26, 2011, 04:43:03 PM »
Very nice! Works well on my end. Tried it on a DWG and an MP3.

eg.
Code: [Select]
Command: (mapcar 'print (_get_file_properties (getfiled "" "" "" 2)))

("Name" . "01 - Going up.mp3")
("Size" . "6.13 MB")
("Item type" . "MP3 Format Sound")
("Date modified" . "1/24/2011 11:36 AM")
("Date created" . "11/29/2010 2:35 PM")
("Date accessed" . "11/29/2010 2:51 PM")
("Attributes" . "A")
("Offline status" . "")
("Offline availability" . "")
("Perceived type" . "Audio")
("Owner" . "ENGINEER\\athompson")
("Kind" . "Music")
("Date taken" . "")
("Contributing artists" . "Echo & the Bunnymen")
("Album" . "Crocodiles")
("Year" . "1980")
("Genre" . "New Wave")
("Conductors" . "")
("Tags" . "")
("Rating" . "Unrated")
("Authors" . "Echo & the Bunnymen")
("Title" . "Going up")
("Subject" . "")
("Categories" . "")
("Comments" . " 0000067C 000005A3 00001F33 0000144A 00021AF3 0001838F 00006562
00006A2F 0000E2FD 0000E2FD")
("Copyright" . "")
("#" . "1")
("Length" . "00:03:59")
("Bit rate" . "?214kbps")
("Protected" . "No")
("Camera model" . "")
("Dimensions" . "")
("Camera maker" . "")
("Company" . "")
("File description" . "")
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #2 on: April 26, 2011, 04:44:58 PM »
Thanks for checking Alan. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

ronjonp

  • Needs a day job
  • Posts: 6864
Re: Get_File_Properties
« Reply #3 on: April 26, 2011, 04:45:00 PM »
Works here too ... Nice work as usual Michael :)

Windows 10 x64 - AutoCAD /C3D 2019

Custom Build PC

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #4 on: April 26, 2011, 04:46:55 PM »
Thanks Ron. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 12170
  • London, England
Re: Get_File_Properties
« Reply #5 on: April 26, 2011, 06:42:34 PM »
Nice Michael!  8-)

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #6 on: April 27, 2011, 12:02:22 AM »
Thank you Lee. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

gskelly

  • Newt
  • Posts: 185
Re: Get_File_Properties
« Reply #7 on: April 27, 2011, 08:08:03 AM »
PS: Let me know if it works / doesn't work for you. Thanks and cheers, MP.

Tested successfully with Bricsad v11 on WinXP Pro SP3.

Code: [Select]
(
    ("Name" . "myra.dwg")
    ("Size" . "48 KB")
    ("Type" . "AcadDocument Class")
    ("Date Modified" . "27/04/2011 9:01 AM")
    ("Date Created" . "16/03/2011 9:18 AM")
    ("Date Accessed" . "22/03/2011 5:55 PM")
    ("Attributes" . "A")
    ("Status" . "Online")
    ("Owner" . "GREG-WS\\greg")
    ("Author" . "You")
    ("Title" . "This is the title.")
    ("Subject" . "Everything about this.")
    ("Category" . "A bunch of bits.")
    ("Pages" . "")
    ("Comments" . "Some unrelated info...")
    ("Copyright" . "")
    ("Artist" . "")
    ("Album Title" . "")
    ("Year" . "")
    ("Track Number" . "")
    ("Genre" . "")
    ("Duration" . "")
    ("Bit Rate" . "")
    ("Protected" . "")
    ("Camera Model" . "")
    ("Date Picture Taken" . "")
    ("Dimensions" . "")
    ("Episode Name" . "")
    ("Program Description" . "")
    ("Audio sample size" . "")
    ("Audio sample rate" . "")
    ("Channels" . "")
)
Bricscad v12

Lee Mac

  • Seagull
  • Posts: 12170
  • London, England
Re: Get_File_Properties
« Reply #8 on: April 27, 2011, 08:12:16 AM »
I think I might be inclined to change:

Code: [Select]
(vl-remove-if
    (function (lambda (item) (eq "" (car item))))
    result
)

to:

Code: [Select]
(vl-remove-if
    (function (lambda ( item ) (or (eq "" (cdr item)) (eq "" (car item)))))
    result
)

 :-)

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #9 on: April 27, 2011, 08:17:48 AM »
I think I might be inclined to change: ...

I understand the rationale but to me a field value of "" is legit, whereas a field name of "" is not. But that's merely my mileage ... thanks for your thoughts Lee. :)

Tested successfully with Bricsad v11 on WinXP Pro SP3.

Awesome, thanks for testing under Bricscad. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 12170
  • London, England
Re: Get_File_Properties
« Reply #10 on: April 27, 2011, 08:23:35 AM »
I think I might be inclined to change: ...

I understand the rationale but to me a field value of "" is legit, whereas a field name of "" is not. But that's merely my mileage ... thanks for your thoughts Lee. :)

Good point. It would return results of consistent length - I'm converted.  :-)

Lee Mac

  • Seagull
  • Posts: 12170
  • London, England
Re: Get_File_Properties
« Reply #11 on: April 27, 2011, 08:28:11 AM »
By the way, I was meaning to ask - how did you ascertain there were 35 properties to be had? Looking over the reference for the 'GetDetailsOf' method for the Folder Object I notice there are only 5 or 6 properties listed.

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #12 on: April 27, 2011, 08:31:34 AM »
To write the function I had to use several sources, none of which on their own yielded code that when converted to LISP worked. This one listed the properties.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 12170
  • London, England
Re: Get_File_Properties
« Reply #13 on: April 27, 2011, 08:36:19 AM »
Thanks for the link MP, appreciated.

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #14 on: April 27, 2011, 08:39:48 AM »
HA!!

Turns out some experimentation reveals that list is incomplete. See revision to first post. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 12170
  • London, England
Re: Get_File_Properties
« Reply #15 on: April 27, 2011, 08:46:18 AM »
Turns out some experimentation reveals that list is incomplete. See revision to first post. :)

Even more so in Windows7...

Using:

Code: [Select]
(setq ...
                    i           0
                )
                (if item
                    (while
                        (not
                            (eq ""
                                (caar
                                    (setq result
                                        (cons
                                            (cons
                                                (vlax-invoke
                                                    folder
                                                   'GetDetailsOf
                                                    items
                                                    (setq i (1+ i))
                                                )
                                                (vlax-invoke
                                                    folder
                                                   'GetDetailsOf
                                                    item
                                                    i
                                                )
                                            )   
                                            result
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
...

Gives me 292 properties..  !   :lol:

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #16 on: April 27, 2011, 08:50:08 AM »
holy sh*t

I should have tried that code at home (Win7 Pro), I'm running Windows XP here (insert laughter as appropriate).  :-D
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

alanjt

  • Needs a day job
  • Posts: 5324
  • Standby for witty remark...
Re: Get_File_Properties
« Reply #17 on: April 27, 2011, 08:50:43 AM »
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #18 on: April 27, 2011, 08:52:51 AM »
Changed original post to check items 0 ... 299. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Andrea

  • Water Moccasin
  • Posts: 2358
Re: Get_File_Properties
« Reply #19 on: April 27, 2011, 08:54:19 AM »
This is nice !

Question..
is there any way to check if a file have digital signature ?
Keep smile...

andrew_nao

  • Swamp Rat
  • Posts: 566
Re: Get_File_Properties
« Reply #20 on: April 27, 2011, 09:43:33 AM »
thanks for the share MP ill add this nice little function to my library for future use

pBe

  • Bull Frog
  • Posts: 372
Re: Get_File_Properties
« Reply #21 on: April 30, 2011, 08:47:59 AM »
Very Nice MP

Would it be too much trouble if you write this code in Python?

Thanks


MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #22 on: May 02, 2011, 09:44:01 AM »
Very Nice MP

Would it be too much trouble if you write this code in Python?

Thanks

You're welcome pBe. No trouble other than time commitments, I'll try later this week. It's pretty trivial, all one has to do is import the Dispatch function from win32com (e.g. from win32com.client.dynamic import Dispatch) and use it to create the top level objects (e.g. shell_app=Dispatch("Shell.Application")). There after just using standard dot notation to access methods and properties as applicable (e.g. name_space = shell_app.NameSpace('c:\\tests')) in concert with Python's native iteration tools to replicate what has been done via LISP in post #1. :)

thanks for the share MP ill add this nice little function to my library for future use

you're most welcome :)

This is nice !

Question..
is there any way to check if a file have digital signature ?

yes :lol:
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

xiaxiang

  • Guest
Re: Get_File_Properties
« Reply #23 on: May 02, 2011, 08:57:31 PM »
That's cool,Michael!
Coulnd I show it to all my workmates?

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #24 on: May 02, 2011, 09:09:19 PM »
But of course. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

pBe

  • Bull Frog
  • Posts: 372
Re: Get_File_Properties
« Reply #25 on: May 03, 2011, 07:41:16 AM »

You're welcome pBe. No trouble other than time commitments, I'll try later this week. It's pretty trivial, all one has to do is import the Dispatch function from win32com (e.g. from win32com.client.dynamic import Dispatch) and use it to create the top level objects (e.g. shell_app=Dispatch("Shell.Application")). There after just using standard dot notation to access methods and properties as applicable (e.g. name_space = shell_app.NameSpace('c:\\tests')) in concert with Python's native iteration tools to replicate what has been done via LISP in post #1. :)


Thank you for the direction MP
I'll give it a try  :-)

MP

  • Seagull
  • Posts: 17300
Re: Get_File_Properties
« Reply #26 on: May 03, 2011, 08:32:04 AM »
Thank you for the direction MP
I'll give it a try  :-)

You're very welcome pBe. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Andrea

  • Water Moccasin
  • Posts: 2358
Re: Get_File_Properties
« Reply #27 on: July 28, 2011, 04:13:29 PM »
Hi all,

thank you MP providing this noviltie..
reading metadata is now resolved thanks to your ingenuity.

But what about change or add metadata?

 after some research, here is what I found
 tested and working.

but being not a pro in script language I'll trust you LISP guru for the translation of this script in LISP.


Code: [Select]
'To change the comments out of an entire folder's files
   Dim objFSO
   Dim Files
     
   strPath = InputBox("Enter the location of the folder on the network.","Folder Location",1)
   Set objFSO = CreateObject("Scripting.FileSystemObject")
     
   Set objFolder = objFSO.GetFolder(strPath)
   Set tempFiles = objFolder.Files
   For Each File In tempFiles
       ChangeCommentforAllFile(File)
   Next
     
 Function ChangeCommentforAllFile(objFile)
    Dim objDoc : Set objDoc = CreateObject("DSOFile.OleDocumentProperties")
    objDoc.Open(objFile.Path)
    objDoc.SummaryProperties.Comments = "This is a new comment"
    objDoc.Save
 End Function


reference
http://technet.microsoft.com/fr-ca/library/ee692828(en-us).aspx

after that,....maybe all dwgprops can be update directly allowing best search in windows ??? ??

Keep smile...

alanjt

  • Needs a day job
  • Posts: 5324
  • Standby for witty remark...
Re: Get_File_Properties
« Reply #28 on: March 03, 2014, 10:33:16 AM »
Sorry to bring up an old thread, but I'm wondering how to access a set of file properties if you know the property name? Even more interesting, why would it be that, even when having it run through 1000 iterations, it still doesn't return everything displayed if you view the file properties?

To be more specific, I'm trying to retrieve the latitude and longitude from a geotagged image.
« Last Edit: March 03, 2014, 10:36:37 AM by alanjt »
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

kirby

  • Newt
  • Posts: 32
Re: Get_File_Properties
« Reply #29 on: March 03, 2014, 11:22:33 AM »
MS has been changing the numbered extended file properties with each Windows version.

See VB code example and property name / number listed here:
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=160880&page=1

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