PDA

View Full Version : Help With Image Reactor


vferrara
2006-11-13, 02:31 PM
Hello AUGI Members:

I have tried to develop a lisp reactor that would fire-off when the "image" command is given to create and set a specific layer current (s-image) to attach the image file on. The code is giving me an error when I try to create the new "s-image" layer.

Here is the example code:


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;IMAGE REACTOR
;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(vl-load-com)

(Setq Alay (Getvar "clayer"))

(or DimageReactor (setq DimageReactor (VLR-Command-Reactor nil '((:VLR-commandWillStart . VINCEimg::CommandWillStart)))))

(or DimattReactor (setq DimattReactor (VLR-Command-Reactor nil '((:VLR-commandWillStart . VINCEima::CommandWillStart)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;IM COMMAND
;;;;;;
(defun VINCEimg::CommandWillStart (pReactor sCommandName / )
;;; (princ (strcat "\n" (car sCommandName) " has started.\n"))
(if (= (car sCommandName) "IMAGE")

(GetIMlay)

)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;IMAGEATTACH COMMAND
;;;;;;
(defun VINCEima::CommandWillStart (pReactor sCommandName / )
(if (= (car sCommandName) "IMAGEATTACH")

(GetIMlay)

)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;IMAGE LAYER SETUP
;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(DEFUN GetIMlay ()
(SetVar "CMDECHO" 0)

(Setq Alay (Getvar "clayer"))
(if (= Alay "Defpoints")(Dimg1))
(if (/= Alay "Defpoints")(Dimg2))

(SetVar "CMDECHO" 1)
(PRINC)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;LAYER DEFPOINTS CURRENT
;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun Dimg1 ()
(SetVar "CMDECHO" 0)

(Command "-layer" "M" "s-image" "C" "9" "" "")
(Setvar "clayer" "S-Image")
(alert "...Current Layer Is Defpoints...Do Not Attach Image Files in Layer Defpoints...Setting Layer S-image Current... ")

(SetVar "CMDECHO" 1)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;LAYER DEFPOINTS NOT-CURRENT
;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun Dimg2 ()
(SetVar "CMDECHO" 0)

(Command "-layer" "M" "s-image" "C" "9" "" "")
(Setvar "clayer" "S-Image")

(SetVar "CMDECHO" 1)
)


If anyone can provide any assistance, it would be appreciated....!

Regards,
Vince

kpblc2000
2006-11-13, 02:43 PM
I'm not sure, but in reactor functions try do not use (command). And you're trying to attach 2 different functions to one event. I think you have to use something like this:
(vl-load-com)
(or dimagereactor
(setq dimagereactor
(vlr-command-reactor
nil
'((:vlr-commandwillstart . cmdstart)
(:vlr-commandended . cmdend)
(:vlr-commandfailed . cmdend)
(:vlr-commandcancelled . cmdend)
)
) ;_ end of vlr-command-reactor
) ;_ end of setq
) ;_ end of or

(defun cmdstart (react cmd / lay)
(setq cmd (strcase (car cmd) t))
(cond
((wcmatch cmd "*image*")
(setq *clayer* (vla-get-activelayer
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-ActiveLayer
lay (vla-add
(vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
"S-image"
) ;_ end of vla-add
) ;_ end of setq
(vla-put-color lay 9)
(vla-put-activelayer
(vla-get-activedocument (vlax-get-acad-object))
lay
) ;_ end of vla-put-ActiveLayer
)
) ;_ end of cond
) ;_ end of defun

(defun cmdend (react cmd /)
(setq cmd (strcase (car cmd) t))
(cond
((wcmatch cmd "*image*")
(if *clayer*
(vla-put-activelayer
(vla-get-activedocument (vlax-get-acad-object))
*clayer*
) ;_ end of vla-put-ActiveLayer
) ;_ end of if
(setq *clayer* nil)
)
) ;_ end of cond
) ;_ end of defun
I catched some errors

vferrara
2006-11-13, 10:06 PM
Thank you for your quick reply....!!!....I tried your code and it seems to work fine but I do have a question. If I wanted to Alert the user if they were trying to attach the image in the "defpoints" layer, how would I accomplish that....??....I tried to add the following 2 lines of code and it generated errors.


(Setq Alay (Getvar "clayer"))
(If (= Alay "Defpoints")(alert "...Current Layer Is Defpoints...Do Not Attach Image Files in Layer Defpoints...Setting Layer S-image Current... "))


Thank you for any assistance....!

Regards,
Vince

Opie
2006-11-13, 10:09 PM
Thank you for your quick reply....!!!....I tried your code and it seems to work fine but I do have a question. If I wanted to Alert the user if they were trying to attach the image in the "defpoints" layer, how would I accomplish that....??....I tried to add the following 2 lines of code and it generated errors.


(Setq Alay (Getvar "clayer"))
(If (= Alay "Defpoints")(alert "...Current Layer Is Defpoints...Do Not Attach Image Files in Layer Defpoints...Setting Layer S-image Current... "))


Thank you for any assistance....!

Regards,
Vince
Why alert them. Just change the layer of the image to your desired layer. Leave the environment the way it was prior to your routine running.

vferrara
2006-11-13, 11:24 PM
Opie:

That is a good question.....In our firm many of the engineering personnel do their own drafting and since they are engineers first and CAD operators second they are not 100% up to speed on all CAD standards and procedures. I intend to have the image inserted on the proper layer automatically but I also want to educate them at the same time about the correct CAD procedure so that eventually it will sink in and when we get to that point I can remove the alert message.

I hope my explanation was clear....It is more in the area of teaching them proper CAD standards initially and then the alert can go away.

Regards,
Vince

T.Willey
2006-11-14, 12:39 AM
Maybe change the if test to this

(= (strcase Alay) "DEFPOINTS")

This way it will catch all style names of defpoints.

kpblc2000
2006-11-14, 06:44 AM
Thank you for your quick reply....!!!....I tried your code and it seems to work fine but I do have a question. If I wanted to Alert the user if they were trying to attach the image in the "defpoints" layer, how would I accomplish that....??....I tried to add the following 2 lines of code and it generated errors.
(vl-load-com)
(or dimagereactor
(setq dimagereactor
(vlr-command-reactor
nil
'((:vlr-commandwillstart . cmdstart)
(:vlr-commandended . cmdend)
(:vlr-commandfailed . cmdend)
(:vlr-commandcancelled . cmdend)
)
) ;_ end of vlr-command-reactor
) ;_ end of setq
) ;_ end of or

(defun cmdstart (react cmd / lay)
(setq cmd (strcase (car cmd) t))
(cond
((wcmatch cmd "*image*")
(setq *clayer* (vla-get-activelayer
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-ActiveLayer
lay (vla-add
(vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
"S-image"
) ;_ end of vla-add
) ;_ end of setq
(vla-put-color lay 9)
(if (= (strcase (vla-get-name *clayer*)) "DEFPOINTS")
(alert "Can't use \"DEFPOINTS\" Layer to insert images!")
) ;_ end of if
(vla-put-activelayer
(vla-get-activedocument (vlax-get-acad-object))
lay
) ;_ end of vla-put-ActiveLayer
)
) ;_ end of cond
) ;_ end of defun

(defun cmdend (react cmd /)
(setq cmd (strcase (car cmd) t))
(cond
((wcmatch cmd "*image*")
(if *clayer*
(vla-put-activelayer
(vla-get-activedocument (vlax-get-acad-object))
*clayer*
) ;_ end of vla-put-ActiveLayer
) ;_ end of if
(setq *clayer* nil)
)
) ;_ end of cond
) ;_ end of defun

vferrara
2006-11-14, 01:27 PM
Thank you once again for your expert assistance.....your updated code is working great....!!!!

Regards,
Vince