View Full Version : insert .bmp
timothyjturner
2006-03-13, 04:50 PM
I am working on a lisp where the user can choose to insert their digital signature into a drawing. We have our digital signatures in .bmp format in separate locations on our computers. I am looking for a line of code that will let the user browse to their .bmp file and insert it. I tried using (command "_imageattach" ...) but i'm having no luck. When the user browses for the .bmp it prompts them for all this other data that I already have preset in my program... i.e. insertion pt, size, rot angle.... I just need something to help the user browse, everythign else is set.
Look into the getfiled function.
timothyjturner
2006-03-13, 05:20 PM
The getfileid function seems helpful, but how do I insert a .bmp without using the command _imageattach? Is there a better method that will not bring up the extra dialog box asking for the details I mentioned above?
The getfileid function seems helpful, but how do I insert a .bmp without using the command _imageattach? Is there a better method that will not bring up the extra dialog box asking for the details I mentioned above?
Have you tried using the command line version of the image command? You would need to supply the filename from the getfiled function.
There is probably some visual lispcode that would do this without even using the command line.
timothyjturner
2006-03-13, 07:11 PM
I messed around with this a little bit and I seem to have the same type of problem... once I execute the command, it pretty much shuts down my program... I insert and it asks me all the questions again via the command line...
Somehow I need to...
Do previous lisp commands ---> Insert Image ---> Modify image properties via lisp ---> finish lisp program
With no interuptions
T.Willey
2006-03-13, 07:29 PM
Do something like
(initdia 0)
(command "_.image")
This will supress the dialog box. Run it once so that you know how to answer all the prompts.
Wouldn't "-image" also work?
T.Willey
2006-03-13, 07:35 PM
Wouldn't "-image" also work?
I tried it before I posted. Didn't work.
Command: (command "-image")
Unknown command "-IMAGE". Press F1 for help.
nil
That's strange; it works for me. What version are you running?
timothyjturner
2006-03-13, 07:44 PM
I'm still having trouble. Maybe I'm just not understanding how to answer the prompts from the routine and continue on with the program? Even if i answer the prompts manually...it does not complete the rest of the program. Also with this method it did not even bring up a dialog box for me select the bmp file....let me post my entire code, maybe this will help...
(defun C:reviewstamp ()
(setq os (getvar "osmode"))
(setq cl (getvar "clayer"))
(setvar "osmode" 0)
(setq test 1)
(setq blockinsert (getstring "Is this block Approved? approved as Noted? to be Revised? <A/N/R>:"))
(cond
((or (= blockinsert "A") (= blockinsert "a"))
(setq insertstring "\\\\Fileman\\MAC\\Engineering\\Drawings\\AutoCAD Designers\\acad2004\\program files\\acadlisp\\reviewstamp\\approved.dwg")
)
((or (= blockinsert "N") (= blockinsert "n"))
(setq insertstring "\\\\Fileman\\MAC\\Engineering\\Drawings\\AutoCAD Designers\\acad2004\\program files\\acadlisp\\reviewstamp\\approvedasnoted.dwg")
)
((or (= blockinsert "R") (= blockinsert "r"))
(setq insertstring "\\\\Fileman\\MAC\\Engineering\\Drawings\\AutoCAD Designers\\acad2004\\program files\\acadlisp\\reviewstamp\\revise.dwg")
)
)
(setq blkscale (getvar "DIMSCALE"))
(setq pt (getpoint "Select insertion point:"))
(command "insert" insertstring pt blkscale "" 0)
(command "explode" "L" "")
(setq sigdatepty (- (nth 1 pt) (* 0.9375 (getvar "DIMSCALE"))))
(setq sigx (- (nth 0 pt) (* 0.5625 (getvar "DIMSCALE"))))
(setq datex (+ (nth 0 pt) (* 1.5 (getvar "DIMSCALE"))))
(setq bmpptx (- (nth 0 pt) (* 1.5 (getvar "DIMSCALE"))))
(setq sigpt (list sigx sigdatepty 0))
(setq datept (list datex sigdatepty 0))
(setq bmppt (list bmpptx sigdatepty 0))
(setq signature (getstring "\nWould you like to Type your signature or insert digital signature .bmp from a File? <T/F>:"))
(cond
((or (= signature "T") (= signature "t"))
(setq printsig (getstring T "Type your signature:"))
(setq txtsize (* 0.1875 (getvar "DIMSCALE")))
(command "clayer" "text")
(command "Text" "j" "bc" sigpt txtsize "0" printsig "")
)
((or (= signature "F") (= signature "f"))
(initdia 0)
(command "_.image" "a" bmppt (getvar "DIMSCALE") 0)
)
)
(setq date (rtos (getvar "CDATE") 2 8))
(setq datetxt (strcat (substr date 5 2) "/" (substr date 7 2) "/" (substr date 1 4)))
(setq txtsize (* 0.125 (getvar "DIMSCALE")))
(command "Text" "j" "bc" datept txtsize "0" datetxt "")
(command "clayer" cl)
(setvar "osmode" os)
)
T.Willey
2006-03-13, 07:45 PM
That's strange; it works for me. What version are you running?
It works from the command line, but not in lisp code. I'm on A2k4.
timothyjturner
2006-03-13, 07:47 PM
I'm running AutoCAD 2005
T.Willey
2006-03-13, 07:54 PM
Try this.
(progn
(initdia 0)
(command "_.image" "_A" (getfiled "" "" "bmp" 4) pause pause pause)
)
timothyjturner
2006-03-13, 08:03 PM
Ciph, This works perfectly except the user still has to input the prompts after the image is inserted...
The first prompt (insertion point) is equal to the variable bmppt
The second prompt (scale) is equal to (getvar "DIMSCALE")
The final prompt (rotation angle) is equal to 0.
I tried putting those inbetween the pauses... I either did not do it correctly or there is another method... any idea?
T.Willey
2006-03-13, 08:04 PM
You would put those values Instead of the pauses.
(progn
(initdia 0)
(command "_.image" "_A" (getfiled "" "" "bmp" 4) bmppt (getvar "dimscale") 0.0)
)
timothyjturner
2006-03-13, 08:09 PM
Thank you so much!! Sorry about my ignorance! I appreciate your help very much. :)
T.Willey
2006-03-13, 08:13 PM
Thank you so much!! Sorry about my ignorance! I appreciate your help very much. :)
You're welcome. And don't worry about that, we all have to learn somehow/someway.
jwanstaett
2006-03-13, 09:09 PM
need to get a way form using the command function to make object. Use entmake or do it using the vla-addxxxxx where xxxxx is the object to add to the drawing see code
use the this vbaaddraster function see code to add an image with out using the command function
by changing (vla-addRaster... you can add just about any object to your drawing with out using the command function.
and by changing the (VLA-GET-MODELSPACE acadDocument) to
(VLA-GET-PAPERSPACE acadDocument) you can put the object in paper space
;;(VbaAddRaster "ImageFileName" (list x y z) 1 0)
;;By John W Anstaett 03/14/06
;;This function add a Raster image object to modelspace
;; myFile = the file name
;; myPoint = list of the point
;; myScale = the Image Scale
;; myRotation = the Image Rotation
;; the function return the Imageobj as a vbaobject
;; so you can make other change to the object
;;Exp:
(vl-load-com)
;;This function loads the extended AutoLISP functions provided
;;with Visual LISP. The Visual LISP extensions implement ActiveX
;;and AutoCAD reactor support through AutoLISP, and also provide
;;ActiveX utility and data conversion functions, dictionary handling
;;functions, and curve measurement functions.
;;If the extensions are already loaded, vl-load-com does nothing
(defun VbaAddRaster (myFile myPoint myScale
myRotation / acadObject
acadDocument)
(setq acadObject (vlax-get-acad-object)) ;get Autocad object
(setq acadDocument (vla-get-ActiveDocument acadObject))
;get the Activedocument object
(setq acadModelSpace (VLA-GET-MODELSPACE acadDocument))
;get the modelspace block
(setq myRasterObj
(vla-addRaster
acadModelSpace
myFile
(vlax-3d-point myPoint)
myScale
myRotation)) ;add Raster image
(setq myRasterObj myRasterobj) ;retrun the text object
)
use this code to test the vbaaddraster function
;; enter Testaddraster at the command line to
;; run this test progarm to test the VBAAddRaster function
(defun C:TestAddRaster ()
(setq testFile (getfiled "" "" "" 0))
(setq testpoint (getpoint "Enter Insettion Point"))
(setq testScale (getdist "Enter Scale"))
(setQ testRotation (getangle testpoint "Enter Rotation"))
(setq myobj (vbaaddraster testfile testpoint testscale testrotation))
)
add Object using
VLA-ADD3DFACE
VLA-ADD3DMESH
VLA-ADD3DPOLY
VLA-ADDARC
VLA-ADDATTRIBUTE
VLA-ADDBOX
VLA-ADDCIRCLE
VLA-ADDCONE
VLA-ADDCUSTOMOBJECT
VLA-ADDCYLINDER
VLA-ADDDIM3POINTANGULAR
VLA-ADDDIMALIGNED
VLA-ADDDIMANGULAR
VLA-ADDDIMDIAMETRIC
VLA-ADDDIMORDINATE
VLA-ADDDIMRADIAL
VLA-ADDDIMROTATED
VLA-ADDELLIPSE
VLA-ADDELLIPTICALCONE
VLA-ADDELLIPTICALCYLINDER
VLA-ADDEXTRUDEDSOLID
VLA-ADDEXTRUDEDSOLIDALONGPATH
VLA-ADDFITPOINT
VLA-ADDHATCH
VLA-ADDITEMS
VLA-ADDLEADER
VLA-ADDLIGHTWEIGHTPOLYLINE
VLA-ADDLINE
VLA-ADDMENUITEM
VLA-ADDMINSERTBLOCK
VLA-ADDMLINE
VLA-ADDMTEXT
VLA-ADDOBJECT
VLA-ADDPOINT
VLA-ADDPOLYFACEMESH
VLA-ADDPOLYLINE
VLA-ADDPVIEWPORT
VLA-ADDRASTER
VLA-ADDRAY
VLA-ADDREGION
VLA-ADDREVOLVEDSOLID
VLA-ADDSEPARATOR
VLA-ADDSHAPE
VLA-ADDSOLID
VLA-ADDSPHERE
VLA-ADDSPLINE
VLA-ADDSUBMENU
VLA-ADDTEXT
VLA-ADDTOLERANCE
VLA-ADDTOOLBARBUTTON
VLA-ADDTORUS
VLA-ADDTRACE
VLA-ADDVERTEX
VLA-ADDWEDGE
VLA-ADDXLINE
VLA-ADDXRECORD
T.Willey
2006-03-13, 09:34 PM
;;(VbaAddRaster "ImageFileName" (list x y z) 1 0)
;;By John W Anstaett 03/14/06
;;This function add a Raster image object to modelspace
;; myFile = the file name
;; myPoint = list of the point
;; myScale = the Image Scale
;; myRotation = the Image Rotation
;; the function return the Imageobj as a vbaobject
;; so you can make other change to the object
;;Exp:
(vl-load-com)
;;This function loads the extended AutoLISP functions provided
;;with Visual LISP. The Visual LISP extensions implement ActiveX
;;and AutoCAD reactor support through AutoLISP, and also provide
;;ActiveX utility and data conversion functions, dictionary handling
;;functions, and curve measurement functions.
;;If the extensions are already loaded, vl-load-com does nothing
(defun VbaAddRaster (myFile myPoint myScale
myRotation / acadObject
acadDocument)
(setq acadObject (vlax-get-acad-object)) ;get Autocad object
(setq acadDocument (vla-get-ActiveDocument acadObject))
;get the Activedocument object
(setq acadModelSpace (VLA-GET-MODELSPACE acadDocument))
;get the modelspace block
; SHOULD CHECK WHICH SPACE YOU ARE IN
(setq myRasterObj
(vla-addRaster
acadModelSpace
myFile
(vlax-3d-point myPoint)
myScale
myRotation)) ;add Raster image
; (setq myRasterObj myRasterobj) ;retrun the text object NOT NEEDED
)
If you are going to paste a tool box type function, I would have it so you can add the object (in this case) to whatever space you want. I would check to see what space I'm in, and then place the image there. Or you should change the name so that people who don't know a lot of coding, will know that it only works for model space. Also you do not need the setq at the end, as in this case the object will be returned as it is the last statement in the function. It will return the object, or a nil.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.