Jump to content

vla-sendCommand messy order


casariana

Recommended Posts

Hello!

 

I'm performing a count in order to create a report from a dwg file.

Counting functioncan be called at any time, but necessarily runs on close - when I also count the edit time. For that I'm using a reactor.

That works fine.

Prior to start the counting I'd like to overkill the whole drawing. That way it will not generate fake data due to duplicated objects.

My code:

(defun finalize ( / total_vector t_time)  
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-sendCommand doc "_.-overkill\r_all\r\r_done\r")
  (arxload "EDITTIME")
  (load "julian")
  (setq total_vector (jtoc (acet-edittime-total)))
  (setq t_time (strcat (LM:rtos (nth 3 total_vector) 2 0) ":" (LM:rtos (nth 4 total_vector) 2 0)))
  (acet-edittime-enable "OFF")

  (report1 t_time)
  (report2 t_time)
  (CloseReactor)
)

As you can see, I'm using a few of (the marvelous) Lee Mac's functions too:

(defun CloseReactor nil
 (vl-load-com)
 ;; Lee Mac  ~  14.04.10
 (  (lambda ( data / react )
      (if (setq react
            (vl-some
              (function
                (lambda ( reactor )
                  (if (eq data (vlr-data reactor)) reactor)
                )
              )
              (cdar
                (vlr-reactors :vlr-editor-reactor)
              )
            )
          )
        (if (vlr-added-p react)
          (vlr-remove react)
          (vlr-add react)
        )
        (setq react
          (vlr-editor-reactor data
            (list
              (cons :vlr-beginclose 'CloseCallBack)
            )
          )
        )
      )
      (princ
        (if (vlr-added-p react)
          "\n** Reactor Activated **"
          "\n** Reactor Deactivated **"
        )
      )
      react
    )
   "Close-Reactor"
 )

 (princ)
)
(defun CloseCallBack (reactor arguments)
 
 (vla-put-ActiveSpace
   (setq doc (vla-get-ActiveDocument
               (setq acad (vlax-get-acad-object))
             )
   )
   acModelSpace
 )
 (vla-ZoomExtents acad)
 (vla-put-ActiveLayer doc
   (vla-item
     (vla-get-layers doc) "0"
   )
 )
 (vla-put-ActiveUCS doc
   (vla-add
     (vla-get-usercoordinatesystems doc)
       (vlax-3D-point '(0. 0. 0.))
         (vlax-3D-point '(1. 0. 0.))
           (vlax-3D-point '(0. 1. 0.)) "TempWord_UCS"
   )
 )
 (if (not (eq "" (vla-get-FullName doc)))
   (vla-saveas doc (vla-get-FullName doc))
 )
 (princ)
 (finalize)
)

;; rtos wrapper  -  Lee Mac
;; A wrapper for the rtos function to negate the effect of DIMZIN
(defun LM:rtos ( real units prec / dimzin result )
    (setq dimzin (getvar 'dimzin))
    (setvar 'dimzin 0)
    (setq result (vl-catch-all-apply 'rtos (list real units prec)))
    (setvar 'dimzin dimzin)
    (if (not (vl-catch-all-error-p result))
        result
    )
)

I'm using vla-sendfile to call the overkill because I can't use command inside a reactor. If I close the reactor in the begining of the finilize funcion, it closes the drawing before running through the whole function.

But I realized that the overkill is being performed AFTER the report1 and report2 functions. That is a problem because report1 and report2 are the functions that generate the report.

 

So, I'm guessing there's some sort of priority of vanilla lisp over vla functions. Is that right? Is there other way of performing this overkill whithout using vla-sendcommand or command?

 

Thanks a lot.

Link to comment
Share on other sites

Not quite sure what you are trying to record but there are a few record what goes on in a dwg out there I have used Productivity_Analysis_Tool.lsp it loggs a very entensive record of what a user has done it can be set up for multi users logging individual files per user.

Link to comment
Share on other sites

17 hours ago, casariana said:

some sort of priority of vanilla lisp over vla functions. Is that right?

No. The vla-sendcommand function sends a string to the CAD program to be processed when the CAD program is ready to receive command line input. In your example this is after the 'finalize' function is finished.

The solution may be to use vla-sendcommand to start the 'finalize' function and in that function then use (command "_.-overkill" ...). Although triggering the Overkill command in a :vlr-beginclose callback is perhaps tricky.

Edited by Roy_043
Link to comment
Share on other sites

8 hours ago, BIGAL said:

Not quite sure what you are trying to record but there are a few record what goes on in a dwg out there I have used Productivity_Analysis_Tool.lsp it loggs a very entensive record of what a user has done it can be set up for multi users logging individual files per user.

 

Thank you for the reply! Your code at Productivity_Analysis_Tool.lsp is great, congrats!

But I need to record the amount of products generated for each user and in certain period of time. So I count it through the types, layers and attributes of the objects and also retrieve the user that made the modification and edittime. This way I know that an individual openned the file at 08:00am, closed it at 10:00am, had an edittime of 70 min, and inserted 2km of cable A, 3km of cable B, etc.

 

Link to comment
Share on other sites

5 hours ago, Roy_043 said:

No. The vla-sendcommand function sends a string to the CAD program to be processed when the CAD program is ready to receive command line input. In your example this is after the 'finalize' function is finished.

The solution may be to use vla-sendcommand to start the 'finalize' function and in that function then use (command "_.-overkill" ...). Although triggering the Overkill command in a :vlr-beginclose callback is perhaps tricky.

 

Yes! You solved it 😁

 

I modified the code, maybe it's not the most elegant solution, but works great!

 

1 - Made 'finalize' a public function and changed its name for a random name that would be unlikely to be typed "accidentaly"

(defun finalize ( / total_vector t_time))     >>     (defun c:zxtw82 ( / total_vector t_time))

 

2 - At other functions, where I called (finalize), I changed to:

 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-sendCommand doc "_.-overkill\r_all\r\r_done\r")
 (vla-sendCommand doc "zxtw82\r")

And that was it! Thank you very much!

Edited by casariana
Link to comment
Share on other sites

Not exactly what I meant. But that does not matter. Note that you can also do this:

(vla-sendCommand doc "(finalize)\r")

 

Link to comment
Share on other sites

On 6/28/2019 at 5:30 AM, Roy_043 said:

Not exactly what I meant. But that does not matter. Note that you can also do this:


(vla-sendCommand doc "(finalize)\r")

 

 

Sorry, I had interpreted that wrong. I actually  thought that the (command "_.-overkill" ...) would be inside the reactor, but now I see what you meant.

Also this solution is far more elegant.

Thank you.

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...