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

0 Members and 1 Guest are viewing this topic.

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: 7527
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: 7527
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: 7527
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: 7527
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.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7527
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.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst