TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on May 02, 2018, 09:38:53 AM

Title: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 09:38:53 AM
I'm looking to xref an image thru a lisp routine. Any ideas?

(setvar "filedia" 0)
(setenv "XLOADPATH" (getvar "dwgprefix"))

name of image  "Front Elevation.png"
(command "-xref"...

I have tried XATTACH, IMAGEATTACH...with no luck.
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 02, 2018, 09:43:44 AM
Set FILEDIA to 0 then use IMAGEATTACH.
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 09:48:34 AM
Thanks

I tried that and get this message...
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 09:55:18 AM
Ok, this works...but I'm looking to do it without opening any dialog boxes.

(defun C:TEST ()
  (setvar "ctab" "A0-0 COVER")
  (setvar "filedia" 0)
  (setenv "XLOADPATH" (getvar "dwgprefix"))
  (command "IMAGEATTACH" "Front Elevation.png")
  (princ))

Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 10:09:19 AM
This is the best I can do...


Code: [Select]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Xref Images Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:Images ()
  (setvar "ctab" "A0-0 COVER")
  (setvar "filedia" 0)
  (setenv "XLOADPATH" (getvar "dwgprefix"))
  (initget 1 "V A F")
  (setq tmp (getkword "\n* Xref Images: [V]icinity map   [A]erial image   [F]ront elevation *"))
  (if (not tmp)
    (setq tmp "P"))
  (cond ((= "V" tmp) (command "IMAGEATTACH" "Vicinity Map.png"))
        ((= "A" tmp) (command "IMAGEATTACH" "Aerial Image.png"))
        ((= "F" tmp) (command "IMAGEATTACH" "Front Elevation.png")))
  (setvar "filedia" 1)
  (princ))

Title: Re: Xref Image thru Lisp
Post by: T.Willey on May 02, 2018, 12:15:32 PM
Gary,

Look at the method 'AddRaster'.

Code - Text: [Select]
  1. (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  2. (setq spc (vla-get-ModelSpace doc))
  3. (vlax-invoke spc 'AddRaster <path> (getpoint) 1. 0.)
  4.  
Title: Re: Xref Image thru Lisp
Post by: MP on May 02, 2018, 12:15:36 PM
No time to play but here's a little snip ...

Code: [Select]
(setq
    owner           (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    imageName       "c:\\legit_path\\legit_file_name.cal"
    insertionPoint '(0.0 0.0 0.0)
    scalefactor     1.0
    rotationAngle   0.0
)

(vlax-invoke owner 'AddRaster imageName insertionPoint scalefactor rotationAngle)
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 02, 2018, 12:55:57 PM
And some more food for thought :)
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:images (/ d f i p)
  3.   (cond
  4.     ((vl-position "A0-0 COVER" (mapcar 'strcase (layoutlist)))
  5.      (setvar 'ctab "A0-0 COVER")
  6.      (setvar 'filedia 0)
  7.      (initget 0 "V A F")
  8.      (setq i (cond ((getkword "\nXref Images[Vicinity Map/Aerial image/Front elevation] <V>: "))
  9.                    ("V")
  10.              )
  11.      )
  12.      (if
  13.        (and
  14.          (findfile (setq f (strcat (getvar 'dwgprefix)
  15.                                    (car (vl-remove-if-not
  16.                                           '(lambda (x) (wcmatch x (strcat i "*")))
  17.                                           '("Vicinity Map.png" "Aerial Image.png" "Front Elevation.png")
  18.                                         )
  19.                                    )
  20.                            )
  21.                    )
  22.          )
  23.          (setq p (getpoint "\nPick a point to place image: "))
  24.        )
  25.         (vlax-invoke (vla-get-paperspace d) 'addraster f p 1. 0.)
  26.         (print (strcat f " NOT FOUND!!!"))
  27.      )
  28.      (setvar 'filedia 1)
  29.     )
  30.     (alert "Tab 'A0-0 COVER' DOES NOT EXIST!")
  31.   )
  32.   (princ)
  33. )
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 01:40:26 PM
Thanks
As soon as I get home I’ll try them out
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 02:44:44 PM
Ron, your routine works like mine. I would like to set the image without the dialog box...Setting the insertion point, scale etc thru lisp.

Tim and MP, your routine works, but the image is not displaying.
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 02, 2018, 05:43:22 PM
I think Tim and MP's code is not working for you because you're inserting on a paperspace tab and their examples are using modelspace.
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 02, 2018, 05:48:43 PM
Ron, your routine works like mine. I would like to set the image without the dialog box...Setting the insertion point, scale etc thru lisp.
...
Updated above to use addraster.
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 06:33:24 PM
Slapping my face now...
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 07:03:37 PM
Ron, what is spc

(vlax-invoke (vla-get-paperspace spc) 'addraster f p 1. 0.)
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 02, 2018, 07:16:00 PM
Ron, what is spc

(vlax-invoke (vla-get-paperspace spc) 'addraster f p 1. 0.)
Oops. .. updated above.
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 07:20:54 PM
 :smitten:
Title: Re: Xref Image thru Lisp
Post by: GDF on May 02, 2018, 09:16:52 PM
Just playing around with the enclosed routine, and was wondering how to rename the raster images to their ".png" file name?
I'm getting names like: "OAImg-4702128" in lieu of "Vicinity Map"

The code works great as is.

Code: [Select]
(defun C:IMG-vicinity   (/ d pvicinity i p)
  (setq d (vla-get-activedocument (vlax-get-acad-object)))
  (setvar "ctab" "A0-0 COVER")
  (setvar 'filedia 0) 
  (setq i "V") 
  (if
    (and (findfile (setq f (strcat (getvar 'dwgprefix)
               (car   (vl-remove-if-not
                 '(lambda (x) (wcmatch x (strcat i "*")))
                 '("Vicinity Map.png")
               )
               )
            )
         )
    )
    (setq pvicinity '(3.85156 14.0 0.0))
    )
    (vlax-invoke (vla-get-paperspace d) 'addraster f pvicinity 10.0 0.0)
    (print (strcat f " NOT FOUND!!!"))
  )
  (setvar 'filedia 1)
  (princ)
)
(defun C:IMG-aerial   (/ d paerial i p)
  (setq d (vla-get-activedocument (vlax-get-acad-object)))
  (setvar "ctab" "A0-0 COVER")
  (setvar 'filedia 0) 
  (setq i "A")
  (if
    (and (findfile (setq f (strcat (getvar 'dwgprefix)
               (car   (vl-remove-if-not
                 '(lambda (x) (wcmatch x (strcat i "*")))
                 '("Aerial Image.png")
               )
               )
            )
         )
    )   
    (setq paerial '(3.85156 2.39844 0.0))   
    )
    (vlax-invoke (vla-get-paperspace d) 'addraster f paerial 10.0 0.0)
    (print (strcat f " NOT FOUND!!!"))
  )
  (setvar 'filedia 1)
  (princ)
)
(defun C:IMG-front   (/ d pfront i p)
  (setq d (vla-get-activedocument (vlax-get-acad-object)))
  (setvar "ctab" "A0-0 COVER")
  (setvar 'filedia 0) 
  (setq i "F")
  (if
    (and (findfile (setq f (strcat (getvar 'dwgprefix)
               (car   (vl-remove-if-not
                 '(lambda (x) (wcmatch x (strcat i "*")))
                 '("Front Elevation.png")
               )
               )
            )
         )
    )   
    (setq pfront '(19.4766 2.39844 0.0))
    )
    (vlax-invoke (vla-get-paperspace d) 'addraster f pfront 10.0 0.0)
    (print (strcat f " NOT FOUND!!!"))
  )
  (setvar 'filedia 1)
  (princ)
)
(C:IMG-FRONT)
(C:IMG-AERIAL)
(C:IMG-VICINITY)
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 03, 2018, 08:58:25 AM
Are you talking about the name in the xref manager?

Something like this should consolidate those 3 routines:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:images (/ d i o)
  2.   (cond
  3.     ((vl-position "A0-0 COVER" (mapcar 'strcase (layoutlist)))
  4.      (setvar 'ctab "A0-0 COVER")
  5.      (setvar 'filedia 0)
  6.      (initget 0 "V A F")
  7.      (setq i (cond ((getkword "\nXref Images[Vicinity Map/Aerial image/Front elevation] <V>: "))
  8.                    ("V")
  9.              )
  10.      )
  11.      (cond ((and (setq i (assoc i
  12.                                 '(("V" "Vicinity Map.png" (3.85156 14. 0.))
  13.                                   ("A" "Aerial Image.png" (3.85156 2.39844 0.))
  14.                                   ("F" "Front Elevation.png" (19.4766 2.39844 0.))
  15.                                  )
  16.                          )
  17.                  )
  18.                  (findfile (cadr i))
  19.                  (setq o (vlax-invoke (vla-get-paperspace d) 'addraster (cadr i) (last i) 10. 0.))
  20.             )
  21.             (vl-catch-all-apply 'vla-put-name (list o (vl-filename-base (cadr i))))
  22.            )
  23.            ((print (strcat (cadr i) " NOT FOUND!!!")))
  24.      )
  25.      (setvar 'filedia 1)
  26.     )
  27.     ((alert "TAB 'A0-0 COVER' DOES NOT EXIST!"))
  28.   )
  29.   (princ)
Title: Re: Xref Image thru Lisp
Post by: GDF on May 03, 2018, 09:21:15 AM
Thanks again RON

Title: Re: Xref Image thru Lisp
Post by: GDF on May 03, 2018, 09:21:46 AM
Yes the name in the xref manager.
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 03, 2018, 09:34:51 AM
Thanks again RON
You're welcome Gary :)
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 03, 2018, 09:39:41 AM
Yes the name in the xref manager.
Code updated above to rename in the xref manager. Be aware that that sometimes the name does not update in the xref manager palette, but it should be renamed.
Title: Re: Xref Image thru Lisp
Post by: GDF on May 03, 2018, 09:46:39 AM
SWEET...works perfectly

Thanks again
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 03, 2018, 10:38:08 AM
SWEET...works perfectly

Thanks again
Anytime Gary :)
Title: Re: Xref Image thru Lisp
Post by: MP on May 03, 2018, 12:25:25 PM
Be aware that that sometimes the name does not update in the xref manager palette, but it should be renamed.

If you rename an xref / image def thru code you can force it to update in the xref palette by forcing a reload (vla-reload block_or_image_def).
Title: Re: Xref Image thru Lisp
Post by: ronjonp on May 03, 2018, 12:34:48 PM
Be aware that that sometimes the name does not update in the xref manager palette, but it should be renamed.

If you rename an xref / image def thru code you can force it to update in the xref palette by forcing a reload (vla-reload block_or_image_def).
Good to know .. thanks! :)
Title: Re: Xref Image thru Lisp
Post by: MP on May 03, 2018, 12:43:05 PM
My pleasure, I do it all the time (http://youtu.be/d2QNuDUTocE).