Author Topic: DblClk Reactor on block  (Read 2404 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
DblClk Reactor on block
« on: July 26, 2010, 01:33:23 PM »
I am having a heck of a time with this for some reason.  This is the 3rd time I have tried to get this to work.

Here is the scenario:

I have a block (actually it could be many blocks), the names all begin the same.  We'll say "TGS:yaddayadda".

What I am trying to do is create a double click reactor that when i double click on one of these blocks it fires a certain program. (the program that created them).  I can get the program dialog to open, and I can make changes to the program (which deletes that block and replaces it with another), that is when all h3ll breaks loose.  I know that it has to do with the owner object.  Does some one have a good example of this type of code.

Maybe I am just not doing it correctly, or there is a better way to get this to work.  Also when I try differant things such as just using an alert when I hit OK then the block editor dialog opens.

This thing is driving me crazy.  What my ultimate goal is to create a function that I can pass the block to and the function and it goes from there.

Thanks everybody.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

LE3

  • Guest
Re: DblClk Reactor on block
« Reply #1 on: July 26, 2010, 01:36:04 PM »
Let me have a look in my old code here, Tim... did something similar in the past... now to find it...

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: DblClk Reactor on block
« Reply #2 on: July 26, 2010, 01:37:29 PM »
Thanks Luis,

I have many samples that I have downloaded over the past year (some from you, jb and others)  I just can't seem to piece it together to come up with something that works.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

LE3

  • Guest
Re: DblClk Reactor on block
« Reply #3 on: July 26, 2010, 01:40:59 PM »
Here is something, you might have this already, see if helps, can't find the one I did that shows a dialog... still looking here.
Code: [Select]
;; LE
;; blkautocopy 1.0 15 sep 2005
;; routine to copy a block when selected
;; 11:11 AM 9/19/2005

;; at loading time turn on the ability
(setq blkautocopy_on t)

;; local error
(defun blkautocopy-error  (g)
  (if (not (member g '("console break" "Function cancelled")))
    (princ (strcat "\nError: " g)))
  (if (and
;; is the ability on?
blkautocopy_on
;; the new block exist?
new_obj
;; has not been erased?
(not (vlax-erased-p new_obj))
;; can we do something to it?
(vlax-write-enabled-p new_obj))
    ;; erase it
    (vla-delete new_obj))
  ;; turn it nil
  (setq new_obj nil)
  ;; un-highlight our selection
  (sssetfirst nil)
  (setq *error* olderr)
  (princ))

;; block drag move
(defun blk-drag-move  (msg obj / take code5 p3)
  (prompt (strcat "\n"
  (cond (msg)
("Move"))
  "\n"))
  (while (and (setq take (grread 't 15)) (/= 3 (car take)))
    (setq code5 (car take)
  p3 (cadr take))
    (if (and p3 (= 5 code5))
      (vla-move
obj
(vla-get-insertionpoint obj)
(vlax-3d-point p3)))))

;; make a copy of a block
;; and move it to a new location
(defun blkautocopy  (reactor params / olderr ss obj new_obj)
  (setq olderr *error*
*error* blkautocopy-error)
  (if (and
;; ability is on?
blkautocopy_on
;; no command is in use?
(= (getvar "cmdnames") "")
;; the pickfirst value in on?
(eq 1 (logand 1 (getvar "pickfirst")))
;; are we selecting a block?
(setq ss (ssget "_i" '((0 . "INSERT"))))
;; did we got just one?
(eq 1 (sslength ss))
;; get the ename and convert it into a vla-object
(setq obj (vlax-ename->vla-object (ssname ss 0))))
    (progn
      (prompt "\nMaking a copy of the block... \n")
      ;; make a copy of the block
      (setq new_obj (vla-copy obj))
      ;; move the new block to another place
      (blk-drag-move "Specify second point of displacement: " new_obj)
      ;; un-highlight our selection
      (sssetfirst nil)))
  (setq *error* olderr))

;; a way to turn on our reactor by a mouse double-click
;;;(defun on-blkautocopy  (reactor params)
;;;  (setq blkautocopy_on t)
;;;  (sssetfirst nil)
;;;  (prompt "\n(blkautocopy Block=ON - Rightclick to turn OFF) \n"))

;; a way to turn off our reactor by a mouse right-click
;;;(defun off-blkautocopy (reactor params)
;;;  (setq blkautocopy_on nil)
;;;  (prompt "\n(blkautocopy Block=OFF - Doubleclick to turn ON) \n"))

;; main reactor
(if (not blkautocopy_reactor)
  (setq blkautocopy_reactor
(vlr-miscellaneous-reactor
   "blkautocopy block = miscellaneous reactor"
   '((:vlr-pickfirstmodified . blkautocopy)))))

;; auxiliar reactor for turn on or off the ability
;;;(if (not mouse_blkautocopy_reactor)
;;;  (setq mouse_blkautocopy_reactor
;;; (vlr-mouse-reactor
;;;    "blkautocopy block = mouse reactor"
;;;    '((:vlr-begindoubleclick . on-blkautocopy)
;;;      (:vlr-beginrightclick . off-blkautocopy)))))

(princ)

kpblc

  • Bull Frog
  • Posts: 396
Re: DblClk Reactor on block
« Reply #4 on: July 26, 2010, 03:01:38 PM »
<off>Double-click reactors won't works correctly on vertical products (like AutoCAD Architecture)...</off>
Sorry for my English.

LE3

  • Guest
Re: DblClk Reactor on block
« Reply #5 on: July 26, 2010, 10:35:56 PM »
Tim,

(did not find any of my mouse reactor routines) I end up adapting my old code (posted previously) to be use in a system similar to the one you describe (I think so),
have a look and see if can work, the comments are between the code lines.
HTH.

Code: [Select]
(vl-load-com)

;; test to set an existing block used for replacement
(defun C:USETHIS (/ ent)
(setq ent (car (entsel "\nSelect a block to be use for replace: ")))
(setq obj1 (vlax-ename->vla-object ent)))

;; at loading time turn on the ability
;; this two values flag can be set inside of a toogle command?
(setq blkautoreplace_on t) ;; on
;;(setq blkautoreplace_on nil) ;; off

(defun blkautoreplace  (reactor params / ss obj)
  (if (and
;; ability is on?
blkautoreplace_on
;; no command is in use?
(= (getvar "cmdnames") "")
;; the pickfirst value in on?
(eq 1 (logand 1 (getvar "pickfirst")))
;; are we selecting a block?
(setq ss (ssget "_i" '((0 . "INSERT"))))
;; did we got just one?
(eq 1 (sslength ss))
;; get the ename and convert it into a vla-object
(setq obj (vlax-ename->vla-object (ssname ss 0)))

(vlax-write-enabled-p obj))
    (progn
      (alert "\nReplace object with... \n")
      ;; here display the dialog to select any block
      ;; to be use for a replacement and do not show in
      ;; the list the name of the one being selected
      
      ;; here extract any data from the 'obj' selected
      ;; for test it simple uses the selected insertion point
      ;; deletes the selected object when is not needed anymore
      ;; and moves the 'usethis' object selected via that command
      ;; once it is accessible via the name from the dialog
      ;; it can be inserted via vlisp
      ;; guess this is much better than using an object reactor
      ;; of relly on a double click mouse reactor that has
      ;; to be turn off before it is set
      ;;
      ;; here it is using a flag t or nil to enable.disable
      ;; the reactor
      
      (setq insPt (vla-get-insertionpoint obj))
      (vla-delete obj)
      (vla-move
obj1
(vla-get-insertionpoint obj1)
insPt)

      )))

;; main reactor
(if (not blkautoreplace_reactor)
  (setq blkautoreplace_reactor
(vlr-miscellaneous-reactor
  "blkautoreplace = miscellaneous reactor"
  '((:vlr-pickfirstmodified . blkautoreplace)))))

(princ)

GDF

  • Water Moccasin
  • Posts: 2081
Re: DblClk Reactor on block
« Reply #6 on: July 27, 2010, 02:26:07 PM »
Tim

Have you tried:
;;;
;;; James Buzbee's Double Click Reactor
;;;

http://www.theswamp.org/index.php?topic=8304.0
« Last Edit: July 27, 2010, 02:29:52 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: DblClk Reactor on block
« Reply #7 on: July 27, 2010, 03:54:31 PM »
Yeah I looked at that one.  However that is object specific, not block specific.  I want to create one that reacts based on the block name.

I have everything working, except, once I make my selections in the dialog to change the block it crashes and I get and elock violation.

Not sure what is happening.  I get this far and mess with new ideas for about a week and then I just give up.  I am running out of ideas.  Problem is that I do not know anything about reactors.  :|

ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: DblClk Reactor on block
« Reply #8 on: July 27, 2010, 04:02:54 PM »
Just create the function (specific to the block and use ssget "_I"), then add a Double-click Action in the CUI.

EDIT: Actually, I don't think you'd need to use ssget "_I".
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: DblClk Reactor on block
« Reply #9 on: July 27, 2010, 07:14:15 PM »
Will that work?  How do I go about doing this?  Can it be done through programming  :ugly:
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

psuchewinner

  • Guest
Re: DblClk Reactor on block
« Reply #10 on: July 28, 2010, 07:23:08 AM »
I have seen it work by reading the XData attached to an entity.  I dont have the code but I know it can be done.