Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

image attach lisp

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
m.deleurere
10669 Views, 9 Replies

image attach lisp

i am working on a lisp to attach an image with

 

(command "-image" "attach" path "0,0" "1" "0")  where 'path' is the prefix and image name set from a dialog box.

 

how can i get the program to error if the image does not exist- i.e., the name was incorrectly entered?  i have tried

 

(if  (= str "*Image not found*")
   (alert ":: ERROR :: Image not found")
)

 

and


(if (/= str "*Image not found*")
 (command "-image" "attach" path "0,0" "1" "0")
 (alert ":: ERROR :: Image not found")

)

 

the alert comes up regardless of whether or not the image exists.

9 REPLIES 9
Message 2 of 10
balisteor
in reply to: m.deleurere

 

First, I don't see anywhere that your declaring the value  "str"

 

(= str "*Image not found*");<-- this would be asking if str is equal to the text "*Image not found*" which is not quite what you want.

 

What you want to try is checking your path variable with (findfile path) and if that returns nil there is no image at the specified path.

 

 

Try this.

(if (findfile path)
(command "-image" "attach" path "0,0" "1" "0") ; path exists.
(alert ":: ERROR :: Image not found"); path not found
)

 

 

Message 3 of 10
m.deleurere
in reply to: balisteor

that works perfectly, thanks for your help. 

Message 4 of 10
balisteor
in reply to: m.deleurere

Your very welcome.
Message 5 of 10
bhull1985
in reply to: balisteor

Also known as the "else" in an If-Then-Else

(if (this

(then

(else

);if

 

if (then or (else requires more than one function or test then you have to start the (then or (else with (progn) and close the progn where you want to proceede to the next level of the if statement (then or else)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 6 of 10
BlackBox_
in reply to: m.deleurere

What dialog box are you using?

 

My reason for asking, is that if using a file selection dialog such as GETFILED, filtering for the desired file extensions, then you've already confirmed both the file name, and that it exists:

 

(defun c:ImageInsert (/ image)
  (if
    (setq image
           (getfiled "Select image" (getvar 'dwgprefix) "gif;jpg;png;tif" 8)
    )
     (command "._undo" "_end" "._undo" "_begin" "._-image" "_attach"
              image '(0 0 0) 1.0 0.0 "._undo" "_end"
             )
  )
  (princ)
)

 

HTH

 



"How we think determines what we do, and what we do determines what we get."

Message 7 of 10
BlackBox_
in reply to: BlackBox_

If not wanting to use a Command call, or perhaps performing this action on a Drawing (Document) not opened in the Editor via ObjectDBX, one can employ the AddRaster Method as well.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 8 of 10
m.deleurere
in reply to: BlackBox_

i am not familiar with getfiled, but will look it up.  can this be used in the dcl?

 

the dialog box has a popup list for the user to select the drawing size (1-5) and two edit boxes:  one for the drawing number and one for the number of sheets.

Message 9 of 10
BlackBox_
in reply to: m.deleurere


@Anonymous.deleurere wrote:

i am not familiar with getfiled, but will look it up.  can this be used in the dcl?

 

the dialog box has a popup list for the user to select the drawing size (1-5) and two edit boxes:  one for the drawing number and one for the number of sheets.


... More on GETFILED.

 

Okay, that's what i was missing, that you're using DCL, which is fine. You might consider using a "..."
 (browse) button instead, which employs GETFILED within a sub-function, which returns a valid file name as string to populate your DCL dialog (and to be used on OK for your dialog, etc.):

 

(defun _BrowseForImage (/ image)
  (getfiled "Select image" (getvar 'dwgprefix) "gif;jpg;png;tif" 8)
)

 

... Again, this will return a valid string for a selected image file, or Nil.

 

HTH



"How we think determines what we do, and what we do determines what we get."

Message 10 of 10
paulritter
in reply to: BlackBox_

findfile works too...

(defun c:InsertImage( / imgName bFound)
   (setq imgName "D:\\IMAGE.JPG")
   (setq bFound (findfile imgName))
   (if bFound
      (command "-image" "attach" imgName "0,0" "1" "0")
      (alert (strcat "\nCould not find file " imgName ". " ))
   )
   (princ)

)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost