Jump to content

Catch Any Change in a Layer


danie7LT
 Share

Recommended Posts

Hi everyone,

I'm making quantity tables from entities in a drawing and I need to add "flagging system" which will alert the user when any kind of modification has been made in a specific layer (I'm talking about the content of the layer = entities, not layer definitions like color and so).

I've already looked for many solutions, but it seems that the way to go is to add a reactor to a layer (or to each layer ???)

I just started AutoLisp and I'm not feeling ready to dive into reactors w/o being crushed :P

Theoretically I need something like ("myreactor" "catchanychangetocontent" "LayerName") -> return T if there's been a change (like a new entity etc etc) 8)

 

I really need help on this one,

 

Tks !

Edited by danie7LT
Link to comment
Share on other sites

What type of drawings are you dealing with metal, electrical,wood?

To my knowledge you can’t add a reactor to a layer.

A reactor will only tell you that an object has changed duringthat session.

If someone changes something then closes the drawing andthen you open the drawing it will not tell you that something has changes.

That being said there are many ways to get object data.

What type of drawings are you dealing with metal, electrical,wood?

Can you give a detailed description of what objects andwhat exactly you are trying to achieve

Link to comment
Share on other sites

Hi JohnM,

 

I'm dealing with "roads/highways/groundworks etc" ... not really objects, what we need is to extract from the layout all the surfaces and lengths of entities by layer - which we already do. Each layer contains surfaces and lines that defines specific types of "processes" to apply to a road for example. For each process a different price => for each layer a different price.

For now we get everything on tables filled by acad fields so any modifications in the layout (like stretching an existing surface) is reflected automatically in the table.

 

What it doesn't do is alerting the user that new objects has been added in a specific layer meaning that the table for this layer isn't relevant anymore and should be rebuild/updated.

 

*edit*

re-reading your post:

"If someone changes something then closes the drawing andthen you open the drawing it will not tell you that something has changes"

What I need is something like "when someone changes something" autocad throw an alert/set the table title to red / whatever and then the user closes the drawing. so no need for "session management" everything is handled in the current session

*EOE*

 

I hope it's a bit clearer

 

Thank you

Daniel

Link to comment
Share on other sites

Something like this you will have to get really specificand analytical

Note: in AutoCAD everything you see on your screen is anobject. Lines/ circles/ Points/ text/blocks/tables/ ect………

You will have to figure out all the possible changes thatwould affect you and break those down to determine how to create a reactor todo what you want.

If using an object reactor, you have to figure out whenthe reactor fires. Before the object changes or after an object has changed. Orif a new object has been created.

Think about it. When I draw a line on layer 0 AutoCADregisters that new line and all of its properties as an object in its database.If I now change the layer of that line the properties has changes but theobject has not. If I stretch the line the properties change. If I convert theline to a pollyline the object and properties change meaning the line object isnow deleted and a new pline is entered into the database.

Have you ever opened a drawing a looked around and didnot change anything but when you go to close it AutoCAD ask if you want to saveany changes?

That is because even though you didn’t add any objectsyou might have zoomed in or out or panned around. All these actions are noticedby AutoCAD and when you close the view might be different and that is why isask.

That is why it is best to define exactly when,where,howand what. Then you will be closer to define a reactor or lisp to help you out.

Link to comment
Share on other sites

Hi everyone,

I'm making quantity tables from entities in a drawing and I need to add "flagging system" which will alert the user when any kind of modification has been made in a specific layer (I'm talking about the content of the layer = entities, not layer definitions like color and so).

I've already looked for many solutions, but it seems that the way to go is to add a reactor to a layer (or to each layer ???)

I just started AutoLisp and I'm not feeling ready to dive into reactors w/o being crushed :P

Theoretically I need something like ("myreactor" "catchanychangetocontent" "LayerName") -> return T if there's been a change (like a new entity etc etc) 8)

 

I really need help on this one,

 

Tks !

 

This should get you started in the right direction:

 

(vl-load-com)
;;;--------------------------------------------------------------------;
;;; set your target layers here as a list of strings
(setq *Reactor_Layers* '("0" "DEFPOINTS"))
;;;--------------------------------------------------------------------;
(defun Reactor:Start ()

 ;; database reactor
 (or *AcDbReactor*
     (setq *AcDbReactor*
            (vlr-acdb-reactor
              nil
              '(
                (:vlr-objectappended . Callback:ObjectAppended)
                (:vlr-objectmodified . Callback:ObjectAppended)
               )
            )
     )
 )

 ;; command reactor
 (or *CommandReactor*
     (setq *CommandReactor*
            (vlr-command-reactor
              nil
              '(
                (:vlr-commandended . Callback:CommandEnded)
               )
            )
     )
 )
 (prompt "\n AcDb reactor loaded. ")
 (princ)
)
;;;--------------------------------------------------------------------;
(defun Callback:CommandEnded (rea cmd)
 (if *ObjectsAddedToLayers*
   (progn
     (alert
       (strcat "\n** Objects added to  layer(s) \""
               (vl-string-right-trim
                 ","
                 (apply 'strcat
                        (mapcar (function (lambda (x) (strcat x ",")))
                                (vl-sort *ObjectsAddedToLayers* '<)
                        )
                 )
               )
               "\" ** "
       )
     )
     (setq *ObjectsAddedToLayers* nil)
   )
 )
)
;;;--------------------------------------------------------------------;
(defun Callback:ObjectAppended (rea obj / layerName)
 (if
   (and
     *Reactor_Layers*
     (vl-position
       (setq layerName (strcase (cdr (assoc 8 (entget (cadr obj))))))
       *Reactor_Layers*
     )
     (not (vl-position layerName *ObjectsAddedToLayers*))
   )
    (setq *ObjectsAddedToLayers*
           (cons layerName *ObjectsAddedToLayers*)
    )
 )
)
;;;--------------------------------------------------------------------;
(Reactor:Start)
(princ)

 

** NOTE - The call to ALERT is only used here as a demonstration, and is intended to be replaced with PROMPT, etc. so as to not annoy the carp out of users. :thumbsup:

Edited by BlackBox
Link to comment
Share on other sites

@BlackBox Thank You SO MUCH ! I'll study your code and get back to you in a few days !

 

@JohnM I see what you mean, I'll sharpen my "flagging system" requirements while digging in BlackBox code.

 

Nice week end to every one!

 

Tks

Daniel

Edited by danie7LT
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
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.

 Share

×
×
  • Create New...