Jump to content

Help with mouse vl reactor


Dante Sparda

Recommended Posts

Hi everybody, I've been trying to write a routine that draws something when you doubleclick certain objects

 

this is the routine:

 

(vl-load-com)

(vlr-mouse-reactor nil '((:vlr-beginDoubleClick . dbclick)))

 

 

(defun prueba ( )

(progn

(alert "Funcion de prueba" )

(setq b (list '(0 . "CIRCLE") '(8 . "0") '(10 -30.0000 30.0000 0.0) '(40 . 15.0000)))

(entmake b)

 

);progn

)

 

 

(defun dbclick (object-reactor point-reactor )

 

(alert "DoubleClicked")

 

(setq numhandle (cdr (assoc 5 (entget (cadr (reverse (nentselp (car point-reactor) )))))))

(princ numhandle)

(REDRAW (car(nentselp (car point-reactor) )) 4)

 

(if (= numhandle "135" )

(prueba)

)

)

so when you doubleclick a circle with the handle "135" it's supposed to print alerts:"DoubleClicked" and then "funcion de prueba" and then draw a circle with center 30,30 and radius 15.

 

But it does it until print the alert "funcion de prueba" and then the program crashes and says:

 

ERROR: !scandr.cpp@2280: eLockViolation

 

and closes.:(

 

 

I've tried to replace

 

 

(defun prueba ( )

(progn

(alert "Funcion de prueba" )

(setq b (list '(0 . "CIRCLE") '(8 . "0") '(10 -30.0000 30.0000 0.0) '(40 . 15.0000)))

(entmake b)

 

);progn

)

with

 

(defun prueba ( )

(progn

(alert "MyLisp is running" )

(command "_circle" "1,1" "20")

);progn

)

but it doesn't work either it says:

 

"Invalid autocad command: nill":cry:

 

 

Please tell me how can I solve one of the problems (command and entmake) or at least tell me if they can't be solved.

 

I really need this, thanks in advance.:D

Link to comment
Share on other sites

You crashed my acad!

 

I'd be interested to know why those other two ways don't work but I tried using vla to make the circle and it worked:

 

(vla-addCircle
 (vla-get-modelspace
   (vla-get-activedocument (vlax-get-acad-object)))
 (vlax-3d-point (LIST -30. 30. 0.)) 15.)

 

EDIT: You will want to change the space object if you are working in paperspace.

Link to comment
Share on other sites

You crashed my acad!

 

I'd be interested to know why those other two ways don't work but I tried using vla to make the circle and it worked:

 

(vla-addCircle
 (vla-get-modelspace
   (vla-get-activedocument (vlax-get-acad-object)))
 (vlax-3d-point (LIST -30. 30. 0.)) 15.)

EDIT: You will want to change the space object if you are working in paperspace.

Cannot use command in reactor calls.

Link to comment
Share on other sites

Thank you Steve,

but how do I execute it??

sorry I'm new at this..

I tried to run it with visual lisp console and didn't work,

about the other two codes, they usually work, the question is why they don't work inside the whole code I posted, does yours work inside it?

thanks again

Link to comment
Share on other sites

sorry I'm new at this..

Lol, and you're already experimenting with reactors... be wary!

 

Here's your code with slight improvements:

(vl-load-com)
(vlr-mouse-reactor nil '((:vlr-beginDoubleClick . dbclick)))


(defun prueba ()
(alert "Funcion de prueba" )
[color=Blue](vla-addCircle
 (vla-get-modelspace
   (vla-get-activedocument (vlax-get-acad-object)))
 (vlax-3d-point (list -30. 30. 0.)) 15.)[/color]
)


(defun dbclick (object-reactor point-reactor / numhandle)

(alert "DoubleClicked")
 (if (setq numhandle (car (nentselp (car point-reactor))))
   (progn
     (setq numhandle (cdr (assoc [color=Red]5[/color] (entget numhandle))))
     (princ numhandle)
     ;(REDRAW (car(nentselp (car point-reactor) )) 4)
     (if (= numhandle "135" )
   (prueba)
   )
     )(princ "\nNothing found at point"))
)

Btw, what are you trying to do? :? Isn't DXF code 5 an object handle?

 

I'm just thinking maybe there is a better alternative to doing what you're trying to achieve.

Link to comment
Share on other sites

Thanks a lot!!, it worked.:lol:

 

And I'm new, cuz I've been working with autolisp for just around two months, and I'm experimewnting with reactors because it's for a course at college.

 

And well, what I have to do is to expose some VL functions and professor said it would be better if we explain reactors to, so I though that a simple example could be to put some text like "circle" "square" and "triangle" and then, when you double click on one of them, the program draws the shape.

 

so, can you tell me if there's something like vlaxaddCircle, to add polygons, and how to write the parameters.

 

And finally, i was also trying to change the color for drawings when you doubleclick colored circles, but the only way I know to do that is with (command "color" "3") but since command doesn't work with reactors, is there another instructionto do it??

Link to comment
Share on other sites

Hi,

 

Ahh ok, um, I'm not sure about polygons with vl, someone else should know.

 

As for changing colors yeah you'll be able to do that (whether you want to try alisp again I don't know it might crash).

So you've got the entity from (car (nentselp ...)). Set this to a variable then you can change it's color with alisp or vlisp:

AutoLisp:

(entmod (subst (cons 62 [b][i][color=Red]1[/color][/i][/b]) (assoc 63 (entget [i][b][color=Blue]en[/color][/b][/i])) (entget [i][b][color=Blue]en[/color][/b][/i])))

Where 1 is the color you want to change it to and en is the entity name variable.

 

Or with

VL:

(vla-put-color (vlax-ename->vla-object [b][color=Blue]en[/color][/b]) [b][i][color=Red]1[/color][/i][/b])

 

Let me know if you need a hand (afterall, you are doing a course so I don't want to give it to you :wink:).

 

What sort of course is it by the way? Is it based on a lisp language? I've never done one is all and I'd be interested to know where else you can use lisp.

Link to comment
Share on other sites

What sort of course is it by the way? Is it based on a lisp language? I've never done one is all and I'd be interested to know where else you can use lisp.

LISP was originally written for Artificial Intelligence.

Link to comment
Share on other sites

Hmm, it's lists driven, one would think it'd come about by data collation or co-ordinate manipulation.

LISP was originally written for Artificial Intelligence.
Link to comment
Share on other sites

Code:

(vla-put-color (vlax-ename->vla-object en) 1)

Thank you, this works too, though what I wanted to modify wasn't the color of an entity, but the color tht you currently use to draw, so when i change it to green all the stuff that i draw later would be green,

 

but this will help me to, maybe it's even better that what I wanted to do

 

when i finish the program i'll post it so you can see what it does, for now it's going fine and I'm just missing how to draw the triangle and the square with vla-add if anyone knos how to, please tell me.

Link to comment
Share on other sites

Yeah hopefully someone can help you, I'd be interested to know how to set the active color.

 

I think the reason you can't draw polygons and triangles by a function is because they are just a polyline with some maths involved to work out each corner. I've used something like this in the past to make polylines:

(vla-addPolyline (vla-get-modelspace
                     (vla-get-activedocument (vlax-get-acad-object))) 
(safefill [b][i][color=Blue]<put list of points here>[/color][/i][/b]))

(defun safefill (lst )
 (vlax-safearray-fill (vlax-make-safearray
            vlax-vbDouble
            (cons 0 (1- (length (apply 'append lst)))))
   (apply 'append lst)))

Link to comment
Share on other sites

Thanks for sharing. Perhaps this was just a draft, but the parentheses are after the progn functions creating an error when you db-click the circles.

..and there are ways to improve your code if you're getting marked on it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...