Insert image

Insert image

Anonymous
Not applicable
4,522 Views
16 Replies
Message 1 of 17

Insert image

Anonymous
Not applicable

Hi,

 

Can anyone help me create a lisp to insert a jpg from a file location on my computer. It would basically be the attach command but will just insert the specific file from the location needed at 0,0 - 

 

-attach (attach jpg from location: Libraries\Pictures\IMAGE.JPG)

 insertion point <0,0>

 scale factor <1>

Thanks,

 

Danny

 

0 Likes
Accepted solutions (1)
4,523 Views
16 Replies
Replies (16)
Message 2 of 17

pbejse
Mentor
Mentor

@Anonymous wrote:

Hi,

 

Can anyone help me create a lisp to insert a jpg from a file location on my computer. It would basically be the attach command but will just insert the specific file from the location needed at 0,0 - 

 


Thanks,

 

Danny

 


 

(defun c:demo (/ imagefile inimage)
  (if (findfile (Setq imagefile "C:\\Downloads\\IMAGE.JPG"))
    (progn
	  (setq	inimage	(vlax-invoke
			  (vlax-get
			    (vla-get-ActiveLayout
			      (vla-get-activedocument
				(vlax-get-acad-object)
			      )
			    )
			    'Block
			  )
			  'AddRaster
			  imagefile	
			  '(0.0 0.0 0.0)
			  44.5			;<-width
			  0.0
			)
	  )
	  (vla-put-name inimage "MyInsertedPicture") ;<-- Name 
	  (vla-update inimage)
      )
    )
  (princ)
)

HTH

 

0 Likes
Message 3 of 17

Anonymous
Not applicable

Im not sure if im doing something wrong but nothing is happening when i run the demo command. I have saved a JPG file in C:\\Downloads and I've named it "IMAGE" . I've saved the lsp file then loaded it into cad, i run the demo command. But nothing happens?

0 Likes
Message 4 of 17

pbejse
Mentor
Mentor

@Anonymous wrote:

. But nothing happens?


The only time it would do nothing when the file is not found:

 

(defun c:found (/ imagefile)
  (princ
    (if	(findfile (Setq imagefile "C:\\Downloads\\IMAGEs.JPG"))
      (strcat "\nImage found at " imagefile)
      "\nImage not found"
    )
  )(princ)
)

What do you see when you load and run this?

 

OR

The image is too small to see. When you type image do you see "MyInsertedPicture" listed on the File REferences dialog?

 

0 Likes
Message 5 of 17

Anonymous
Not applicable

Just noticed what was wrong, the image wasn't saved in c:\\downloads. I changed it and it works now, thanks.

 

How would i change the insertion fro 0,0 to insert on the tool tip?

0 Likes
Message 6 of 17

pbejse
Mentor
Mentor

@Anonymous wrote:

 

How would i change the insertion fro 0,0 to insert on the tool tip?


Not sure what you mean by that chewdanny12. Is that prompting for insertion point on screen? 

 

 

0 Likes
Message 7 of 17

Anonymous
Not applicable

Yes, just like when you insert from a tool palette.

0 Likes
Message 8 of 17

pbejse
Mentor
Mentor

@Anonymous wrote:

Yes, just like when you insert from a tool palette.


Are you aware you can use a dwg or dwt file with all your images attached to it and use that file as a source from tool palette?

image tool palette.png

 

 

 

 

 

 

 

 

Otherwise :

Use a lisp code

 

(defun _insertImage ( imagefile / imagefile inimage p)
  (if (and
	 (findfile imagefile)
	 (setq p (Getpoint "\nInsertion point"))
	 	)
    (progn
	  (setq	inimage	(vlax-invoke
			  (vlax-get
			    (vla-get-ActiveLayout
			      (vla-get-activedocument
				(vlax-get-acad-object)
			      )
			    )
			    'Block
			  )
			  'AddRaster
			  imagefile	
			  p
			  44.5			;<-width
			  0.0
			)
	  )
	  (vla-put-name inimage (vl-filename-base imagefile)) ;<-- Name 
	  (vla-update inimage)
      )
    (princ (Strcat  "\nImage file \"" (vl-filename-base imagefile) "\" not found!"))
    )
  (princ)
)
(_insertImage "C:/Downloads/IMAGE.JPG")
(_insertImage "C:/Downloads/Another_IMAGE.JPG")

 

as lisp code.png

 

 

 

 

 

 

 

command string.PNG

 

HTH

 

0 Likes
Message 9 of 17

Kent1Cooper
Consultant
Consultant

This is all you need:

 

(command "_.-attach" "C:\\Libraries\\Pictures\\IMAGE.JPG" "0,0" "" "")

 

Replace the C with the appropriate drive letter if needed.

Kent Cooper, AIA
0 Likes
Message 10 of 17

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

 

(command "_.-attach" "C:\\Libraries\\Pictures\\IMAGE.JPG" "0,0" "" "")

 


Yes, that too. Smiley Happy

 

0 Likes
Message 11 of 17

Anonymous
Not applicable

This works too, but how do you insert the image on screen at the tool tip?

 

I have created a custom button on the ribbon that runs the lisp and inserts the image at 0,0. This works fine, but it would be nice to chose the location point for the insertion. 

0 Likes
Message 12 of 17

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

I have created a custom button on the ribbon that runs the lisp and inserts the image at 0,0. This works fine, but it would be nice to chose the location point for the insertion. 


You don't say whose Post you're Replying to.  If it's my little code string, just replace the "0,0" with a pause for User input:

 

(command "_.-attach" "C:\\Libraries\\Pictures\\IMAGE.JPG" pause "" "")

Kent Cooper, AIA
0 Likes
Message 13 of 17

Anonymous
Not applicable

That's great thank you. One final thing... i tried entering the scale factor and rotation angles to the lisp, but it still prompts me for each when i run the lisp

 

(defun c:spo (/ imagefile)
(command "_.-attach" "C:\\Downloads\\IMAGE.jpg" "pause" "2" "45")
)

 

Is there something i'm not doing right?

0 Likes
Message 14 of 17

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....
(command "_.-attach" "C:\\Downloads\\IMAGE.jpg" "pause" "2" "45")

....


Don't put quotation marks around the word pause.

Kent Cooper, AIA
0 Likes
Message 15 of 17

Anonymous
Not applicable

Brilliant, thanks.

0 Likes
Message 16 of 17

Sea-Haven
Mentor
Mentor

Just a side comment had a staff layout plan with each staff members image auto placed based on their telephone extension which was a block with a attribute so phno=image name, would do around 100 images in like 2 seconds.

0 Likes
Message 17 of 17

kishanbG8MQ5
Explorer
Explorer

This code works to find and display an image in a CAD file on the local system after saving the file. However, if the saved file is emailed to another person, the image cannot be displayed on their system.

0 Likes