Author Topic: hatch reactor  (Read 12865 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
hatch reactor
« on: November 05, 2003, 11:59:13 AM »
hey i've asked this question before i believe but don't recall finding a solution. i would like a reactor that would set my layer to hatch when i start the hatch command and if the layer does not exist create it and make current. any help would be great thanks

dan

nivuahc

  • Guest
hatch reactor
« Reply #1 on: November 05, 2003, 12:34:08 PM »
Check out http://www.dsxcad.com/.

Download the tools while you can beacuase they have exactly what you're looking for in them.

ELOQUINTET

  • Guest
hatch reactor
« Reply #2 on: November 05, 2003, 12:59:31 PM »
okay nivuahc i downloaded it and it looks like it has some interesting stuff but i can't find a readme. what do i need to do to load everything?

dan

nivuahc

  • Guest
hatch reactor
« Reply #3 on: November 05, 2003, 01:09:37 PM »
Read the command line carefully when you open Autocad... the answer should be right there.

ELOQUINTET

  • Guest
hatch reactor
« Reply #4 on: November 05, 2003, 01:15:58 PM »
hmmm i hadn't closed autocad but did and don't see anything pertaining to dsx. all i did was unzip it and it created a dsx folder in my program files. do i need to put the folder in the acad folder perhaps? by the way is autolay the part you're refering to that will do what i want? thanks

dan

nivuahc

  • Guest
hatch reactor
« Reply #5 on: November 05, 2003, 01:28:40 PM »
You have to install the DSX tools first.

When you do, you should see something like this

Quote
DSX Tools 2002.12.22.00 - (C)2002 David M. Stein, http://www.dsxcad.com
It may suck, but at least it's free..
VLR-Manager loaded.
DSX AutoLayer Services are Disabled.  Type AUTOLAY to Enable.
AutoCAD menu utilities loaded.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
hatch reactor
« Reply #6 on: November 05, 2003, 01:34:12 PM »
didnt i create this application for you already?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ELOQUINTET

  • Guest
hatch reactor
« Reply #7 on: November 05, 2003, 01:46:49 PM »
se7en you have a very good memory. yes we worked on something similar with dimstyles on cadalog. i have tried and tried to incorporate it for hatch too but never seems to work. could you take a look at this again and see if you can incorporate the hatch part in. i thought i was simple but it's just me who's simple i suppose. thank you thank you thank you...

dan
Code: [Select]

(vl-load-com)
(vl-load-reactors)
(defun ax:MakeLayer (lName / oLayer)
  (if
    (vl-catch-all-error-p
      (setq oLayer
          (vl-catch-all-apply
            'vla-add
              (list
                (vla-get-layers
                  (vla-get-activedocument
                    (vlax-get-acad-object)
                    )
                  )
                lName
                )
             )
          )
        )
    nil
    oLayer
    )
  )
(vlr-command-reactor
  nil
  '((:vlr-CommandWillStart . StartCommand))
  )
(vlr-command-reactor
  nil
  '((:vlr-commandEnded . EndCommand))
  )
(vlr-command-reactor
  nil
  '((:vlr-commandCancelled . EndCommand))
  )
(defun StartCommand (calling-reactor startcommandinfo / thecommandstart)
  (setq thecommandstart (nth 0 startcommandInfo))
  (cond
    ((= thecommandstart "DIMLINEAR")
     ; If the dimlinear command is called then
      (match:layer)
      ; go do the Match:layer function
     )
    ((= thecommandstart "DIMALIGNED")
      (match:layer)
     )
    ((= thecommandstart "QDIM")
      (match:layer)
     )
    ((= thecommandstart "DIMBASELINE")
      (match:layer)
     )
    ((= thecommandstart "QLEADER")
      (match:layer)
     )
    ((= thecommandstart "DIMCONTINUE")
      (match:layer)
     )
    ((= thecommandstart "DIMANGULAR")
      (match:layer)
     )
    ((= thecommandstart "DIMRADIUS")
      (match:layer)
     )
    ((= thecommandstart "DIMDIAMETER")
      (match:layer)
     )
    ((= thecommandstart "DIMORDINATE")
      (match:layer)
     )
    )
  )
(defun EndCommand (calling-reactor endcommandInfo / thecommandend)
  (setq thecommandend (nth 0 endcommandInfo))
  (cond
    ((= thecommandend "DIMLINEAR")
     ; If the dimlinear command has ended then
      (EC:MatchLayer)
      ; go do the EC:MatchLayer function
     )
    ((= thecommandend "DIMALIGNED")
      (EC:MatchLayer)
     )
    ((= thecommandend "QDIM")
      (EC:MatchLayer)
     )
    ((= thecommandend "DIMBASELINE")
      (EC:MatchLayer)
     )
    )
  )
(defun match:layer (/ LayerName ex:dimstyle)
  (setq ex:layer (getvar 'clayer))
  (setq ex:dimstyle (getvar 'dimstyle))
  (if (/= ex:layer ex:dimstyle)
    (progn
      (setq LayerName (ax:MakeLayer ex:dimstyle))
      (vla-put-ActiveLayer
        (vla-get-activedocument
          (vlax-get-acad-object)
          )
        LayerName
        )
      (if (not (vlax-object-released-p LayerName))
        (vlax-release-object LayerName)
        )
      (princ)
      )
    )
  )
(defun EC:MatchLayer (/ LayerName)
  (progn
    (setq LayerName (ax:MakeLayer ex:layer))
    (vla-put-ActiveLayer
      (vla-get-activedocument
        (vlax-get-acad-object)
        )
      LayerName
      )
    (if
      (not
        (vlax-object-released-p LayerName)
        )
      (vlax-release-object LayerName)
      )
    (setq ex:layer nil)
    (princ)
    )
  )



7Edit: Added the code tags

SMadsen

  • Guest
hatch reactor
« Reply #8 on: November 06, 2003, 06:07:48 AM »
Remember to consider the DROPGEOM command in A2K4 as a way to do hatches :)

SMadsen

  • Guest
hatch reactor
« Reply #9 on: November 06, 2003, 07:11:57 AM »
Ok, here's one that does not consider DROPGEOM. Instead of setting a global variable to keep track of previously active layers it simply utilizes the reactor's data field in order to keep track.

Code: [Select]
;; Creates a command reactor for the given events and puts the
;; active layer into it data field in order to restore the active
;; layer after setting another layer active temporarily
(defun newCmdReactor ()
  (if (not *vlr-hatch*)
    (setq *vlr-hatch* (vlr-command-reactor (getvar "CLAYER")
                         '((:vlr-CommandWillStart . StartCommand)
                           (:vlr-commandCancelled . EndCommand)
                           (:vlr-commandEnded . EndCommand))
                      )))
)

;; If command is for creating hatches, then put the currently
;; active layer into the reactors data field and set layer "HATCH"
(defun startCommand (rct cmds)
  (cond
    ((apply 'or (mapcar (function (lambda (n)
                  (member n '("HATCH" "BHATCH" "-BHATCH")))) cmds))
     (vlr-data-set *vlr-hatch* (getvar "CLAYER"))
     (make-layer "HATCH")
    )
    (T (vlr-data-set *vlr-hatch* nil))
  )
)

;; If command is for creating hatches, then look for previously
;; active layer in the reactors data field and set it active
(defun endCommand (rct cmds / layerData)
  (cond
    ((apply 'or (mapcar (function (lambda (n)
                  (member n '("HATCH" "BHATCH" "-BHATCH")))) cmds))
     (if (and (setq layerData (vlr-data *vlr-hatch*))
              (= (type layerData) 'STR)
         )(make-layer layerData))
  ))
)

;; Rewritten version of ax:makeLayer that sets the layer active
;; if, 1. it is present or 2. if it is successfully created
(defun make-Layer (lName / oLayer doc layers)
  (setq layers (vla-get-layers
                 (setq doc (vla-get-activeDocument
                            (vlax-get-acad-object))))
  )
  (cond ((or (not (vl-catch-all-error-p
                    (setq oLayer (vl-catch-all-apply 'vla-item
                                       (list layers lName)))))
             (not (vl-catch-all-error-p
                    (setq oLayer (vl-catch-all-apply
                                   'vla-add
                                   (list
                                     (vla-get-layers
                                       (vla-get-activedocument
                                         (vlax-get-acad-object)))
                                     lName
                                   ))))
             )
         )
         (vla-put-activeLayer doc oLayer)
  ))
)

ELOQUINTET

  • Guest
hatch reactor
« Reply #10 on: November 06, 2003, 08:15:06 AM »
smadsen i tried but doesn't seem to work. i first added it to the end of my acad2000 doc lisp file where the toher reactor is. that didn't work so icreate a lisp called hatch reactor but that didn't work either. i'm not sure what you are saying when you say:

;; If command is for creating hatches, then put the currently
;; active layer into the reactors data field and set layer "HATCH"


could you elaborate on this for my ignorant ass  :lol:
thanks dan


 Command: BHATCH
; error: bad argument type: VLReactor: nil
; error: bad argument type: VLReactor: nil
; error: bad argument type: VLReactor: nil
Select internal point: Selecting everything...
Selecting everything visible...
Analyzing the selected data...
Analyzing internal islands...
Select internal point:
; error: bad argument type: VLReactor: nil
; error: bad argument type: VLReactor: nil
; error: bad argument type: VLReactor: nil

SMadsen

  • Guest
hatch reactor
« Reply #11 on: November 06, 2003, 10:00:17 AM »
eloquintet, have you installed your own reactors from the code you posted earlier? If they run at the same time as the one above  then they will screw things up (they use the same callback function names, and vice versa)

SMadsen

  • Guest
hatch reactor
« Reply #12 on: November 06, 2003, 10:07:31 AM »
Kill your own reactors by calling (vlr-remove-all), then install the one above by calling (newcmdreactor). Alternatively, you can rename the callback functions above to have them work separately (it's best not to have more command reactors running, though).

As for elaboration: Reactors can work with utility data of any kind. It's simply a variable that is associated with a reactor and you can use it for whatever you wish (it's the argument to the vlr-xxx-reactor functions that you normally set to nil).

Here it is used to keep a layer name - namely that of the currently active layer when a command starts. It then sets your specified layer to be currently active. The previous layer name is dragged along until a commandEnded/commandCancelled event is detected, where the callback queries the layer name in the data and, if found, sets it currently active.

ELOQUINTET

  • Guest
hatch reactor
« Reply #13 on: November 06, 2003, 10:27:32 AM »
hmmm i see what you're saying kind of. i guess i was hoping that i could just add hatch to that reactor somehow and it would react when i invoke the hatch just like it does for dimlinear and all the rest of my dim functions. if i've interpretted what you wrote correctly then i have to turn one on and the other off everytime i want to use it. well that would take just as much time as going and setting the layer current which defeats the purpose. while i'm on the subject of this reactor i've noticed recently that when the dimension reactor is invoked it sets the color of the new layer to the color of the previous layer and sometimes it does wacky stuff like putting the text as green and the dim lines as red when i want everything blue. it didn't used to do this until i came to my new job a couple month ago. how doi resolve this? well thanks for your help...

dan

SMadsen

  • Guest
hatch reactor
« Reply #14 on: November 06, 2003, 12:12:45 PM »
I wasn't suggesting anything about your particular use of the code. I was simply airing an idea of how to take advantage of a feature that is built into reactors.

If you want suggestions of how this can replace your existing reactors and at the same time handle both hatches and dimensions, then here is a suggestion of how to do that:

Code: [Select]
;; Creates a command reactor for the given events and puts the
;; active layer into it data field in order to restore the active
;; layer after setting another layer active temporarily
(defun newCmdReactor ()
  (if (not *vlr-hatch*)
    (setq *vlr-hatch* (vlr-command-reactor (getvar "CLAYER")
                         '((:vlr-CommandWillStart . StartCommand)
                           (:vlr-commandCancelled . EndCommand)
                           (:vlr-commandEnded . EndCommand))
                      )))
)

;; If command is for creating hatches or dims, then put the currently
;; active layer into the reactors data field and set appropriate layer
(defun startCommand (rct cmds)
  (cond
    ((apply 'or (mapcar (function (lambda (n)
                  (member n '("HATCH" "BHATCH" "-BHATCH")))) cmds))
     (vlr-data-set *vlr-hatch* (getvar "CLAYER"))
     (make-layer "HATCH")
    )
    ((and (apply 'or (mapcar (function (lambda (n)
                  (wcmatch n "DIM*"))) cmds))
          (not (apply 'and (mapcar 'getvar cmds))))
     (princ "THIS IS A DIM COMMAND")
     (vlr-data-set *vlr-hatch* (getvar "CLAYER"))
     (make-layer (getvar 'dimstyle))
    )
    (T (vlr-data-set *vlr-hatch* nil))
  )
)

;; If command is for creating hatches or dims, then look for previously
;; active layer in the reactors data field and set it active
(defun endCommand (rct cmds / layerData)
  (if (and (setq layerData (vlr-data *vlr-hatch*))
           (= (type layerData) 'STR)
      )
    (cond
      ((apply 'or (mapcar (function (lambda (n)
                    (member n '("HATCH" "BHATCH" "-BHATCH"))))
                    cmds))
       (make-layer layerData)
      )
      ((and (apply 'or (mapcar (function (lambda (n)
                  (wcmatch n "DIM*"))) cmds))
          (not (apply 'and (mapcar 'getvar cmds))))
       (make-layer layerData)
      )
    )
  )
)

;; Rewritten version of ax:makeLayer that sets the layer active
;; if, 1. it is present or 2. if it is successfully created
(defun make-Layer (lName / oLayer doc layers)
  (setq layers (vla-get-layers
                 (setq doc (vla-get-activeDocument
                            (vlax-get-acad-object))))
  )
  (cond ((or (not (vl-catch-all-error-p
                    (setq oLayer (vl-catch-all-apply 'vla-item
                                       (list layers lName)))))
             (not (vl-catch-all-error-p
                    (setq oLayer (vl-catch-all-apply
                                   'vla-add
                                   (list layers lName))))
             )
         )
         (vla-put-activeLayer doc oLayer)
  )
  (vlax-release-object layers)
)
)