Author Topic: Xref Image thru Lisp  (Read 4666 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: 7529
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: 7529
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: 7529
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: 7529
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: 7529
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