Author Topic: Xref Image thru Lisp  (Read 4486 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Xref Image thru Lisp
« 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.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #1 on: May 02, 2018, 09:43:44 AM »
Set FILEDIA to 0 then use IMAGEATTACH.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #2 on: May 02, 2018, 09:48:34 AM »
Thanks

I tried that and get this message...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #3 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))

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

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #4 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))

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref Image thru Lisp
« Reply #5 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.  
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Xref Image thru Lisp
« Reply #6 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)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #7 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. )
« Last Edit: May 03, 2018, 09:03:00 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #8 on: May 02, 2018, 01:40:26 PM »
Thanks
As soon as I get home I’ll try them out
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #9 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.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #10 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #11 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #12 on: May 02, 2018, 06:33:24 PM »
Slapping my face now...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #13 on: May 02, 2018, 07:03:37 PM »
Ron, what is spc

(vlax-invoke (vla-get-paperspace spc) 'addraster f p 1. 0.)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #14 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #15 on: May 02, 2018, 07:20:54 PM »
 :smitten:
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #16 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)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #17 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)
« Last Edit: May 03, 2018, 09:34:31 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #18 on: May 03, 2018, 09:21:15 AM »
Thanks again RON

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

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #19 on: May 03, 2018, 09:21:46 AM »
Yes the name in the xref manager.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #20 on: May 03, 2018, 09:34:51 AM »
Thanks again RON
You're welcome Gary :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #21 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Image thru Lisp
« Reply #22 on: May 03, 2018, 09:46:39 AM »
SWEET...works perfectly

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

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #23 on: May 03, 2018, 10:38:08 AM »
SWEET...works perfectly

Thanks again
Anytime Gary :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Xref Image thru Lisp
« Reply #24 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).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xref Image thru Lisp
« Reply #25 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! :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Xref Image thru Lisp
« Reply #26 on: May 03, 2018, 12:43:05 PM »
My pleasure, I do it all the time.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst