Running Photo Viewer from lisp

Running Photo Viewer from lisp

Anonymous
Not applicable
2,482 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,483 Views
26 Replies
Replies (26)
Message 21 of 27

Anonymous
Not applicable
 
0 Likes
Message 22 of 27

Anonymous
Not applicable

Henrique,

 

Sorry but I have tried my best with this and my knowledge of lisp isnt what it was (and the vlax command is out of my depth), but I have tried to paste your working code back into the original routine but obviously have got it wrong. Could you help me out?

 

(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 looks 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 (file / sh)
 (cond ((setq f (findfile file))
        (setq sh (vlax-create-object "Shell.Application"))
        (vlax-invoke sh 'Open file)
        (vlax-release-object sh)
        )
       )
  )

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

;_______________Sub for only tif found___________________
(defun tif_only ()  
(do_tif mhpath)
);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 mh_path)  
);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

 

Thanks once again for your great help.

Peter

0 Likes
Message 23 of 27

hmsilva
Mentor
Mentor

Peter,

I have a deadline to meet today, so I don't have much free time, but attach a sample .dwg, with one or two manholes, and tonight i'll see what I can do.

 

Henrique

 

EESignature

0 Likes
Message 24 of 27

Anonymous
Not applicable

Henrique,

 

Samples attached as requested.

All map references (and manhole card references) are prefixed with SC.

 

So SC3876-4505 is arrived from "SC"(mh_gr"-"mh_1) where

 

mh_gr is the grid the picked text entity resides in and 4505 is the text entity picked.

 

The particular example cards reside in K:\ NE70000 Sewer Network Info\Manhole_cards\SC3876,

but SC3876 could be SCxxxx as SC3876 only applies to a 1km square.

 

I really appreciate your help, and I will have another go as well.

 

Thanks once again,

Peter

 

edit: I get an error on trying to upload the manhole cards "The attachment's SC3876-4503.tif content type (image/eCopy) does not match its file extension and has been removed." But all they are is a tif image file with the name in the format of SC3876-4503 but any tif will do with that name.

 

 

0 Likes
Message 25 of 27

hmsilva
Mentor
Mentor
Accepted solution

Hi Peter,

attached is your code, revised, and a 'demo', using only the 'Shell.Application' object to preview both files types.

 

Hope this helps,
Henrique

 

EESignature

Message 26 of 27

Anonymous
Not applicable

Henrique,

 

Very many thanks for spending the time to produce both the revised original and the recoded demo version. I like the economy of the coding in the demo version which resulted in it being done in almost half the amount of lines. I will study the way you have done it. (It has been a few years since I did lisp at college).

 

But thanks once again. This routine saves so much time when looking up records.

 

I am indepted to you.

 

Best regards

Peter

0 Likes
Message 27 of 27

hmsilva
Mentor
Mentor

You're welcome, Peter!
Glad I could help

Henrique

EESignature

0 Likes