Running Photo Viewer from lisp

Running Photo Viewer from lisp

Anonymous
Not applicable
2,435 Views
26 Replies
Message 1 of 27

Running Photo Viewer from lisp

Anonymous
Not applicable

I have a lisp routine which enables me to pick a text entity on a drawing upon which the routine then finds a corresponding record, which is either a pdf or tiff file, then opens the file in an appropriate programme. The actual purpose is to open manhole card iinformation when I click on a manhole number within a sewer network.

 

This used to work fine with pdf's opening in Adobe Reader and tiffs opening in MS  Picture Manager but since installing Office 2013 Picture Manager is no more. I am trying to open the tiffs in Photo Viewer but I realise this is run using rundll. I have copied a section of the routine below where you can see the pdf example line (which works OK) but I am struggling with the tiff line. I cant get this bit to run.

 

Any help would be greatly appreciated.

 

Many thanks

 

mh_path and mh_path1 are the text entities returned from picking on a text item in ACAD.)

 

 

 

;;;;;;__________sub to look for pdf and displays file_________________________________
(defun do_pdf ()
(findfile mh_path1) (startapp "C:\\Program Files\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe" mh_path1)
);defun do_pdf

;______sub to look for tif and displays file__________________________________
(defun do_tif ()
(findfile mh_path)(startapp "C:\\Windows\\System32\\rundll32.exe C:\\ProgramFiles\\Windows Photo Viewer\\PhotoViewer.dll", ImageView_Fullscreen mh_path)
);defun do_tif

0 Likes
Accepted solutions (2)
2,436 Views
26 Replies
Replies (26)
Message 2 of 27

paullimapa
Mentor
Mentor

This solution seems to work directly from the Run command in Windows.  You'll have to test it to see if it works from Lisp:

 

http://stackoverflow.com/questions/6190271/how-to-run-photoviewer-dll-in-command-line

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 27

Anonymous
Not applicable

Hi Paul,

 

Thanks for your reply and the link.

The solution does indeed run successfully from the command line so I modified the code to :-

 

 

;______sub to look for tif and displays file__________________________________
(defun do_tif ()
(findfile mh_path) (startapp "rundll32 "%ProgramFiles%\\Windows Photo Viewer\\PhotoViewer.dll", ImageView_Fullscreen" mh_path)
);defun do_tif

 

but unfortunately it does not work. I will continue to have a play sometinme but frankly I don't know what else to try unless there are shell commands available within lisp, but then I think I may be getting out of my depth.

 

Peter

0 Likes
Message 4 of 27

hmsilva
Mentor
Mentor

Hi Peter,

 

If the Photo Viewer is the default program to open .tif files, perhaps something like this will do the trick

 

;; usage
;; (do_tif "g:\\test\\test123.tif")
(defun do_tif (path)
  (if (setq file (findfile path))
    (command "_.start" file)
    (princ (strcat "\n \"" path "\" was not found..."))
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 27

Anonymous
Not applicable

Hi Henrique,

 

I have posted the routine in its entirity below so you can see the lines I am having trouble with in context. I think I have incorporated your suggestion as intended. When I run it and click on a manhole number it opens a windows command line above CAD with a title showing the manhole card number :-

 

 

 

 

Capture.JPG

 

 

;to pick a manhole tag and have Autocad return existence of card 

(defun c:mhcard ()
(setq pdf_exists nil)
(setq tif_exists nil)  
  
(setq ed (entget (car (entsel))))
(setq ent1 (assoc 1 ed))
(setq mh_1 (cdr ent1))	;;the text value of the entity
(setq 	ent10 (assoc 10 ed )				;; insertion point list of the entity
	mh_10 (cdr ent10   )				;; insertion point
	mh_x  (substr (rtos (car mh_10  ))  2 2 )	;; the x value
	mh_y  (substr (rtos (cadr mh_10 ))  2 2 )	;; the y value
	mh_gr (strcat "SC" mh_x mh_y)			;; the 1k grid number
	mh_no (strcat mh_gr "-" mh_1) ;;manhole number	;; the manhole number
	mh_path (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\" mh_gr "\\" mh_no 

".tif" "\"");the spec for finding a .tif file
	mh_path1 (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\" mh_gr "\\" mh_no 

".pdf" "\"");the spec for finding a .pdf file
;;;note for above line: Startapp needs the file to open in quotes when a space is used in the 

path.
;;;So the backslash quote attaches a literal quote at the back and the front of the path
;;;note that this path is to be used for the startapp fuction. A new path variable is needed for 

other process that do
;;;not require the quotes.
;;;Delete this:	mh_path1 (strcat "K:\\NE70000 Sewer Network Info\\Manhole_cards\\" mh_gr "\\" 

mh_no ".tif")
)	
;;;;;;_______sub to look for pdf and displays file_________________________________
(defun do_pdf () 
(findfile mh_path1) (startapp "C:\\Program Files\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe" 

mh_path1)
);defun do_pdf

;;;;;;_______sub to look for tif and displays file__________________________________
(defun do_tif ()
  (findfile mh_path) (command "_.start" mh_path)
);defun do_tif

;_______________Sub for only pdf found___________________
(defun pdf_only ()
(do_pdf)
);defun pdf_only

;_______________Sub for only tif found___________________
(defun tif_only ()  
(do_tif)
);defun tif_only

;_______________Sub for no cards found_________________  
(defun no_cards ()
(setq no_card (strcat "There are no cards found for Manhole Number :   " mh_no)) 
(princ no_card)
(princ)  
);defun no_cards

;_______________Sub for both cards found_________________  
(defun both_cards ()
(do_pdf)
(setq both_cards (strcat " ......There is also a tif file found for Manhole Number : " mh_no)) 
(princ both_cards)
(setq a (getstring "  hit enter to display tif"))
(princ) 
(do_tif)  
);defun both_cards
  
;check for exstence of files
(if (findfile mh_path1)(setq pdf_exists T)) ;check if pdf file exists
(if (findfile mh_path)(setq tif_exists  T)) ;check if tif file exists
(if (and pdf_exists tif_exists) (both_cards)) ;if both exist do both_cards
(if (and pdf_exists (not tif_exists)) (pdf_only));if only pdf exists do pdf_only
(if (and (not pdf_exists) tif_exists) (tif_only));if only tif exists do tif only
(if (and (not pdf_exists) (not tif_exists)) (no_cards));if nether exists do no_cards

  
;;;;(getfiled "Open Image File" mh_path "tif" 0);this was to be an option to search the directory - superfluous. . ?
 
(princ)
);overall defun


 

 

0 Likes
Message 6 of 27

hmsilva
Mentor
Mentor

Peter,

 

testing the

;; usage
;; (do_tif "g:\\test\\test123.tif")
(defun do_tif (path)
  (if (setq file (findfile path))
    (command "_.start" file)
    (princ (strcat "\n \"" path "\" was not found..."))
  )
  (princ)
)

with a valid .tif path, It works as expected?

 

Or don't open the viewer?

Sorry but I don't have AutoCAD in this laptop...

 

Henrique

EESignature

0 Likes
Message 7 of 27

Anonymous
Not applicable

Henrique,

 

OK, I will have another play.

 

Thanks.

Peter

0 Likes
Message 8 of 27

hmsilva
Mentor
Mentor

@Anonymous wrote:

Henrique,

 

OK, I will have another play.


Peter,

you have not answered my questions...

 

Only for testing purpose, with a valid .tif path, the code I have posted works as expected, or not?

Opens the viewer or not?

 

Henrique

 

EESignature

0 Likes
Message 9 of 27

Anonymous
Not applicable

Sorry Henrique, I realised that I had not ansewerd your question as soon as I posted my last reply.

Just trying now...

 

I am just getting

 

Command: do_tif
Unknown command "DO_TIF".  Press F1 for help.

I must be doing something wrong here. 

0 Likes
Message 10 of 27

Anonymous
Not applicable

...or did you intend for this to be posted into the original routine? If so, do_tif is already defined elsewhere.

0 Likes
Message 11 of 27

Anonymous
Not applicable

I am having a bad day... do_tif is NOT defined elsewhere.

 

 

0 Likes
Message 12 of 27

hmsilva
Mentor
Mentor

Peter

change the mh_gr and mh_no to a valid ones, and test

(if (setq file (findfile (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\" mh_gr "\\" mh_no ".tif" "\"")))
    (command "_.start" file))

 

Henrique

EESignature

0 Likes
Message 13 of 27

Anonymous
Not applicable

Henrique,

 

;; usage
;; (do_tif "c:\\test\\test123.tif")
(defun do_tif (path)
  (if (setq file (findfile (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\SC3876\\SC3876-4508.tif" "\"")))
    (command "_.start" file))
  )
  (princ)
)

 

Results with

 

 

Command: do_tif
; error: too few arguments

 

Thanks,

Peter

0 Likes
Message 14 of 27

hmsilva
Mentor
Mentor

Peter,

 

just copy/paste this code in the command line, and press enter

(if (setq file (findfile (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\SC3876\\SC3876-4508.tif" "\"")))(command "_.start" file))

Did work?

 

 

Henrique

EESignature

0 Likes
Message 15 of 27

Anonymous
Not applicable

Henrique,

 

Pasting the code in gives :-

 

Thanks,

Peter

 

 

 

Capture2.JPG

0 Likes
Message 16 of 27

hmsilva
Mentor
Mentor

And with

(if (findfile (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\SC3876\\SC3876-4508.tif" "\""))
  (command "_.start" (strcat "\"" "K:\\NE70000 Sewer Network Info\\Manhole_cards\\SC3876\\SC3876-4508.tif" "\"")))

Open the viewer?

 

 

Henrique

EESignature

0 Likes
Message 17 of 27

Anonymous
Not applicable

Unfortunately no. I get a 'nil' reponse at the command line.

 

I thought your last suggestion had a good chance of working.

0 Likes
Message 18 of 27

hmsilva
Mentor
Mentor

@Anonymous wrote:

Unfortunately no. I get a 'nil' reponse at the command line.

 

I thought your last suggestion had a good chance of working.


Peter,

the 'start' command, does not deal well with spaces in file name, if the file don't have spaces, it works as expected...

Something like this should work

 

(defun do_tif (file / sh)
 (cond ((setq f (findfile file))
        (setq sh (vlax-create-object "Shell.Application"))
        (vlax-invoke sh 'Open file)
        (vlax-release-object sh)
        )
       )
  )

;; usage
(do_tif "K:\\NE70000 Sewer Network Info\\Manhole_cards\\SC3876\\SC3876-4508.tif")

 

Hope this helps,
Henrique

EESignature

Message 19 of 27

Anonymous
Not applicable
Accepted solution

Hi Henrique,

 

Yes, that works exactly as it should. Thank you very much.

 

Al I have to do now is to put your code snippet back into the original lisp routine.

 

Thanks again,

Peter

0 Likes
Message 20 of 27

hmsilva
Mentor
Mentor

You're welcome, Peter!
Glad I could help

Henrique

EESignature

0 Likes