TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cadmoogle on January 09, 2009, 12:03:45 PM

Title: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 12:03:45 PM
; error: string too long on input

A script can be too long?  :cry:
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 12:09:33 PM
This is what's stopping the code  :evil:
(setq blk (ssget "x" '((0 . "insert") (2 .
 "4FM_45BEND,
  4X4FM_TEE,
  4X2FM_TEE,
  4FM_45BEND_TOP,
  4X2.75FM_REDUCER,
  4X2.5FM_REDUCER,
  ..........Just imagine a lot more here
  0.625X0.75RE_METER")
  )
 )
)
Title: Re: Error is there a solution?
Post by: JohnK on January 09, 2009, 12:24:24 PM
Can you filter better then what your currently doing?
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 12:33:23 PM
I tried thinking of different ways, but I need to find these blocks (exact names).
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 12:52:54 PM
Would foreach work on this?
Title: Re: Error is there a solution?
Post by: ronjonp on January 09, 2009, 12:59:30 PM
Try this:

Code: [Select]
(defun manyblocknames2ss (blocklist / n out ss)
  (setq out (ssadd))
  (foreach name blocklist
    (setq n -1)
    (if (setq ss (ssget "_x" (list (cons 0 "INSERT") (cons 2 name))))
      (repeat (sslength ss)
(ssadd (ssname ss (setq n (1+ n))) out)
      )
    )
  )
  (if (zerop (sslength out))
    nil
    out
  )
)
(manyblocknames2ss '("4FM_45BEND" "4X4FM_TEE"))
Title: Re: Error is there a solution?
Post by: dustinthiesse on January 09, 2009, 01:14:16 PM
(setq blk (ssget "x" '((0 . "insert") (2 .
 "4FM_45BEND,
  4X4FM_TEE,
  4X2FM_TEE,
  4FM_45BEND_TOP,
  4X2.75FM_REDUCER,
  4X2.5FM_REDUCER,
  ..........Just imagine a lot more here
  0.625X0.75RE_METER")
  )
 )
)

Does this even work with those spaces in your long string?
Title: Re: Error is there a solution?
Post by: JohnK on January 09, 2009, 01:38:21 PM
(setq blk (ssget "x" '((0 . "insert") (2 .
 "4FM_45BEND,
  4X4FM_TEE,
  4X2FM_TEE,
  4FM_45BEND_TOP,
  4X2.75FM_REDUCER,
  4X2.5FM_REDUCER,
  ..........Just imagine a lot more here
  0.625X0.75RE_METER")
  )
 )
)

Does this even work with those spaces in your long string?


*blink*
Holly cow, your right! I didnt even notice that. Awesome eye d-unit.

The format is something like:
Code: [Select]
(setq blk
  (ssget
     "x"
     '((0 . "insert")
     (2 . "4FM_45BEND,4X4FM_TEE,4X2FM_TEE,4FM_45BEND_TOP 4X2.75FM_REDUCER,4X2.5FM_REDUCER,..."))) )
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 02:25:08 PM
The shorter version works fine with the spaces, but the second I place all of the names in it prompts the error.
Title: Re: Error is there a solution?
Post by: T.Willey on January 09, 2009, 02:27:12 PM
I don't think the name string can be longer than 255 characters.

This wasn't the case.
Title: Re: Error is there a solution?
Post by: ronjonp on January 09, 2009, 02:29:58 PM
The shorter version works fine with the spaces, but the second I place all of the names in it prompts the error.


Use my solution then  :-P
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 02:35:34 PM
I did  :-D, but I'm still trying to figure out why I can format long ways in yours but not mine...
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 02:45:24 PM
Ron when I ron the code you provided it's trigger the prompt alert with out finding the blocks even if the drawing is blank. Did I do something wrong?

Code: [Select]
;;NewClose command based off existing blocks
::Cadmoogle - 2009
(defun c:NewClose (/)
(command "-purge" "all" "" "N")
(defun manyblocknames2ss (blocklist / n out ss)
  (setq out (ssadd))
  (foreach name blocklist
    (setq n -1)
    (if (setq ss (ssget "_x" (list (cons 0 "INSERT") (cons 2 name))))
      (repeat (sslength ss)
        (ssadd (ssname ss (setq n (1+ n))) out)
      )
    )
  )
  out
)
(manyblocknames2ss
   '("4FM_45BEND");
(progn
  (alert "** Warning ** Non-standard blocks found in drawing. Rename the blocks to the appropriate names and try again. This includes adding the numbers to fire hydrants and/or adding the as-built number to the prefix of the block(s) name. If this is a design drawing rename, the blocks to reflect a design not an as-built.")
 (exit)
);end 1st progn
 (if
  (setq blk (ssget "x" '((0 . "insert") (2 .
  "*WM_FIREHYD_,
   *WM_FIREHYD_1,
   *WM_FIREHYD_2,
   *WM_FIREHYD_3,
   *WM_FIREHYD_4,
   *WM_FIREHYD_5")
  )
 )
)
   (progn
    (alert "Fire hydrants were located into the drawing that were not properly named, please correct and try again.")
  (exit)
);end 2nd progn
 (progn
  (alert "All standard blocks found in drawing.... Now closing")
  (vla-sendcommand
  (vla-get-activedocument (vlax-get-acad-object))".close ")
 (princ))
 )
)
)

Title: Re: Error is there a solution?
Post by: dustinthiesse on January 09, 2009, 02:50:08 PM
Ronjon's is the way to go.  The block names there are in list form rather than trying to filter them all out with '((2 . "aaa,bbb,ccc,ddd,eee,...etc.))

Cadmoogle, are you sure your way actually worked with a shorter list?
Try checking the selection set length with (sslength blk) after running and see if you get the correct results.

Here is what I did [with 6 inserts of "testblk1" and 4 inserts of "testblk2"]:

(sslength(setq blk(ssget "x" '((0 . "INSERT")(2 .
"testblk1,testblk2"))))) ;;;returns 10

(sslength(setq blk(ssget "x" '((0 . "INSERT")(2 .
"testblk1,
testblk2")))));;;returns 6...it only counts the first block...maybe because it is looking for " testblk2" or "\ntestblk2"...neither of which exist

Either way, you don't get an error, but the selection set is not what you were expecting.

Or maybe it doesn't even check for those.  I'm not sure if those are valid block names.  Very interesting though.
Might explain that error you were getting though.  Not sure.
Title: Re: Error is there a solution?
Post by: ronjonp on January 09, 2009, 03:01:16 PM
I updated the function above to return nil if the ss count = 0.
Title: Re: Error is there a solution?
Post by: ronjonp on January 09, 2009, 03:05:23 PM
Ron when I ron the code you provided it's trigger the prompt alert with out finding the blocks even if the drawing is blank. Did I do something wrong?

Code: [Select]
;;NewClose command based off existing blocks
::Cadmoogle - 2009
(defun c:NewClose (/)
(command "-purge" "all" "" "N")
(defun manyblocknames2ss (blocklist / n out ss)
  (setq out (ssadd))
  (foreach name blocklist
    (setq n -1)
    (if (setq ss (ssget "_x" (list (cons 0 "INSERT") (cons 2 name))))
      (repeat (sslength ss)
        (ssadd (ssname ss (setq n (1+ n))) out)
      )
    )
  )
  out
)
(manyblocknames2ss
   '("4FM_45BEND");
(progn
  (alert "** Warning ** Non-standard blocks found in drawing. Rename the blocks to the appropriate names and try again. This includes adding the numbers to fire hydrants and/or adding the as-built number to the prefix of the block(s) name. If this is a design drawing rename, the blocks to reflect a design not an as-built.")
 (exit)
);end 1st progn
 (if
  (setq blk (ssget "x" '((0 . "insert") (2 .
  "*WM_FIREHYD_,
   *WM_FIREHYD_1,
   *WM_FIREHYD_2,
   *WM_FIREHYD_3,
   *WM_FIREHYD_4,
   *WM_FIREHYD_5")
  )
 )
)
   (progn
    (alert "Fire hydrants were located into the drawing that were not properly named, please correct and try again.")
  (exit)
);end 2nd progn
 (progn
  (alert "All standard blocks found in drawing.... Now closing")
  (vla-sendcommand
  (vla-get-activedocument (vlax-get-acad-object))".close ")
 (princ))
 )
)
)


You need to use the function like so if you're just checking the existence of any of the blocks.

Code: [Select]
(if (manyblocknames2ss '("4FM_45BEND"))
  (alert "\nYour computer are belong to us.")
  (alert "\nLooks good :)")
)
Title: Re: Error is there a solution?
Post by: dustinthiesse on January 09, 2009, 03:20:06 PM

  (setq blk (ssget "x" '((0 . "insert") (2 .
  "*WM_FIREHYD_,
   *WM_FIREHYD_1,
   *WM_FIREHYD_2,
   *WM_FIREHYD_3,
   *WM_FIREHYD_4,
   *WM_FIREHYD_5")


I think you need to use a strcat here...that long string is going to count new lines, tabs, and spaces...Try this
Code: [Select]
(setq blk(ssget "x" '((0 . "INSERT")(2 . (strcat
  "*WM_FIREHYD_,"
  "*WM_FIREHYD_1,"
  "*WM_FIREHYD_2,"
  "*WM_FIREHYD_3,"
  "*WM_FIREHYD_4,"
  "*WM_FIREHYD_5"))
)))

Either that or use ronjon's function again!
Code: [Select]
(setq blk(manyblocknames2ss (setq hydr_blks(list "*WM_FIREHYD_"
  "*WM_FIREHYD_1"
  "*WM_FIREHYD_2"
  "*WM_FIREHYD_3"
  "*WM_FIREHYD_4"
  "*WM_FIREHYD_5"))))  ;;don't forget to take out the commas
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 03:59:38 PM
Command: ; error: bad SSGET list value

This is the result.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 04:08:19 PM
Here's the file could some please look at it for me I'm about to bang my head on the wall.

Thank you

I'm getting the error listed above



Code: [Select]
;;NewClose command based off existing blocks
::Cadmoogle - 2009
(defun c:NewClose (/)
(command "-purge" "all" "" "N")
(if
(setq blk(ssget "x" '((0 . "INSERT")(2 . (strcat
   "4FM_45BEND,"   
   "18X2RE_TAP_SADDLE,"
   "20X2RE_TAP_SADDLE,"
   "RE_FLUSHHYD,"))
   )
  )
 )
(progn
  (alert "** Warning ** Non-standard blocks found in drawing. Rename the blocks to the appropriate names and try again. This includes adding the numbers to fire hydrants and/or adding the as-built number to the prefix of the block(s) name. If this is a design drawing rename, the blocks to reflect a design not an as-built.")
 (exit)
);end 1st progn
 (if
  (setq blk(ssget "x" '((0 . "INSERT")(2 . (strcat
  "*WM_FIREHYD_,"
  "*WM_FIREHYD_1,"
  "*WM_FIREHYD_2,"
  "*WM_FIREHYD_3,"
  "*WM_FIREHYD_4,"
  "*WM_FIREHYD_5,"))
  )
 )
)
   (progn
    (alert "Fire hydrants were located into the drawing that were not properly named, please correct and try again.")
  (exit)
);end 2nd progn
 (progn
  (alert "All standard blocks found in drawing.... Now closing")
  (vla-sendcommand
  (vla-get-activedocument (vlax-get-acad-object))".close ")
 (princ))
 )
)
)

Title: Re: Error is there a solution?
Post by: dustinthiesse on January 09, 2009, 04:36:59 PM
I think you need to use a strcat here...that long string is going to count new lines, tabs, and spaces...Try this
(setq blk(ssget "x" '((0 . "INSERT")(2 . (strcat
  "*WM_FIREHYD_,"
  "*WM_FIREHYD_1,"
  "*WM_FIREHYD_2,"
  "*WM_FIREHYD_3,"
  "*WM_FIREHYD_4,"
  "*WM_FIREHYD_5"))
)))

Sorry about that.  This seemed to work.

Code: [Select]
(setq blklist(strcat "4FM_45BEND,"
                     "18X2RE_TAP_SADDLE,"
                     "20X2RE_TAP_SADDLE,"
                     "RE_FLUSHHYD,"
                   )
)
(setq blk(ssget "x" (list(cons 0 "INSERT")(cons 2 blklist))))
Code: [Select]
(setq blklist2(strcat "*WM_FIREHYD_,"
                       "*WM_FIREHYD_1,"
                       "*WM_FIREHYD_2,"
                       "*WM_FIREHYD_3,"
                       "*WM_FIREHYD_4,"
                       "*WM_FIREHYD_5,"
                     )
)
(if
  (setq blk(ssget "x" (list(cons 0 "INSERT")(cons 2 blklist2))))
  (progn ;;;etc....
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 05:14:31 PM
Okay I don't know what I've done.... it was working a one point and time but I've screwed something up.

Could someone please help me organize this?  :angel:


Code: [Select]
;;NewClose command based off existing blocks
::Cadmoogle - 2009
(defun c:NewClose (/)
(command "-purge" "all" "" "N")
(if
(setq blklist(strcat "4FM_45BEND,"
                     "18X2RE_TAP_SADDLE,"
                     "20X2RE_TAP_SADDLE,"
                     "RE_FLUSHHYD,"
                   )
)
(setq blk(ssget "x" (list(cons 0 "INSERT")(cons 2 blklist))))
 (progn
  (alert "** Warning ** Non-standard blocks found in drawing. Rename the blocks to the appropriate names and try again. This includes adding the numbers to fire hydrants and/or adding the as-built number to the prefix of the block(s) name. If this is a design drawing rename, the blocks to reflect a design not an as-built.")
 (exit)
);end 1st progn
 (and
(setq blklist2(strcat "*WM_FIREHYD_,"
                       "*WM_FIREHYD_1,"
                       "*WM_FIREHYD_2,"
                       "*WM_FIREHYD_3,"
                       "*WM_FIREHYD_4,"
                       "*WM_FIREHYD_5,"
                     )
)
(if
  (setq blk(ssget "x" (list(cons 0 "INSERT")(cons 2 blklist2))))
   (progn
    (alert "Fire hydrants were located into the drawing that were not properly named, please correct and try again.")
  (exit)
);end 2nd progn
 (progn
  (alert "All standard blocks found in drawing.... Now closing")
  (vla-sendcommand
  (vla-get-activedocument (vlax-get-acad-object))".close ")
 (princ))
 )
)
)



There is an extra right ) somewhere... and when I think I get it the command runs and does not find the blocks I'm going crazy I tell you.. 9 hours of this code and I'm ready to bang my head on the wall.

Title: Re: Error is there a solution?
Post by: ronjonp on January 09, 2009, 05:23:18 PM
Try this one...I used my subroutine  :-P

BTW...Are you using notepad to edit your code? If so, type vlide in the command line and paste your code into a new doc...it will help out tremendously with troubleshooting.

Code: [Select]
(defun c:NewClose (/)
  (repeat 2
    (vla-purgeall
      (vla-get-activedocument (vlax-get-acad-object))
    )
  )
  (if
    (manyblocknames2ss
      '("4FM_45BEND"
"18X2RE_TAP_SADDLE"
"20X2RE_TAP_SADDLE"
"RE_FLUSHHYD"
       )
    )
     (progn
       (alert
"** Warning ** Non-standard blocks found in drawing. Rename the blocks to the appropriate names and try again.
This includes adding the numbers to fire hydrants and/or adding the as-built number to the prefix of the block(s) name.
If this is a design drawing rename, the blocks to reflect a design not an as-built.
         If you have any questions please see <EDIT>"
       )
       (exit)
     )
  ) ;end 1st progn
  (if (manyblocknames2ss
'("*WM_FIREHYD_" "*WM_FIREHYD_1"
  "*WM_FIREHYD_2" "*WM_FIREHYD_3"
  "*WM_FIREHYD_4" "*WM_FIREHYD_5"
)
      )
    (progn
      (alert
"Fire hydrants were located into the drawing that were not properly named, please correct and try again."
      )
      (exit)
    ) ;end 2nd progn
    (progn
      (alert
"All standard blocks found in drawing.... Now closing"
      )
      (vla-sendcommand
(vla-get-activedocument (vlax-get-acad-object))
".close "
      )
      (princ)
    )
  )
)


(defun manyblocknames2ss (blocklist / n out ss)
  (setq out (ssadd))
  (foreach name blocklist
    (setq n -1)
    (if (setq ss (ssget "_x" (list (cons 0 "INSERT") (cons 2 name))))
      (repeat (sslength ss)
(ssadd (ssname ss (setq n (1+ n))) out)
      )
    )
  )
  (if (zerop (sslength out))
    nil
    out
  )
)
Title: Re: Error is there a solution?
Post by: CAB on January 09, 2009, 07:22:58 PM
Here is the revised roitine, see notes. The last paren was missing.
Code: [Select]
;;NewClose command based off existing blocks
;;  ::Cadmoogle - 2009  ; CAB error in this line, used colons & not semi-colons
(defun c:NewClose (/ blklist blklist2 blk)
  (command "-purge" "all" "" "N")
  (setq blklist (strcat "4FM_45BEND,"
                        "18X2RE_TAP_SADDLE,"
                        "20X2RE_TAP_SADDLE,"
                        "RE_FLUSHHYD,"
                )
  )
  ;;  LOGIC:
  ;;  If test1 succeeds the alert and exit
  ;;  else If test2 succeeds alert & exit
  ;;  else send the CLOSE command
  (if (setq blk (ssget "x" (list (cons 0 "INSERT") (cons 2 blklist)))) ; test1
     (progn
       (alert
         (strcat
           "** Warning ** Non-standard blocks found in drawing. "
           "Rename the blocks to the appropriate names and try again. "
           "This includes adding the numbers to fire hydrants and/or "
           "adding the as-built number to the prefix of the block(s) name. "
           "If this is a design drawing rename, the blocks to reflect a design not an as-built."
           "\nIf you have any questions please see <edit>"
          )
       )
       ; (exit) no need as this will exit
     )    ; end 1st progn
    ;;  no blklist so try another list of blocks
     (progn
       (setq blklist2 (strcat "*WM_FIREHYD_," "*WM_FIREHYD_1," "*WM_FIREHYD_2," "*WM_FIREHYD_3,"
                              "*WM_FIREHYD_4," "*WM_FIREHYD_5,"
                             )
       )
       (if (setq blk (ssget "x" (list (cons 0 "INSERT") (cons 2 blklist2)))) ; test2
          (progn
            (alert
              "Fire hydrants were located into the drawing that were not properly named, please correct and try again."
            )
            ; (exit) no need as this will exit
          )
          (progn
            (alert "All standard blocks found in drawing.... Now closing")
            (vla-sendcommand
              (vla-get-activedocument (vlax-get-acad-object))
              ".close "
            )
          )
       ) ; endif blklist2
     ) ; end 2nd progn
  )
  (princ) ; moved to here
) ; CAB - this was missing
Title: Re: Error is there a solution?
Post by: CAB on January 09, 2009, 07:33:45 PM
This is my variation. Not tested.  8-)
Code: [Select]
;; NewClose command based off existing blocks
;; Cadmoogle - 2009  ; CAB modified
(defun c:NewClose (/ blklist blk)
  (repeat 2
    (vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
  )
  ;;  LOGIC:
  ;;  If test1 succeeds the alert and exit
  ;;  else If test2 succeeds alert & exit
  ;;  else send the CLOSE command
  (cond
    ((progn
       (setq blklist "4FM_45BEND,18X2RE_TAP_SADDLE,20X2RE_TAP_SADDLE,RE_FLUSHHYD")
       (setq blk (ssget "x" (list (cons 0 "INSERT") (cons 2 blklist))))
     )
     (alert
       (strcat
         "** Warning ** Non-standard blocks found in drawing. "
         "Rename the blocks to the appropriate names and try again. "
         "This includes adding the numbers to fire hydrants and/or "
         "adding the as-built number to the prefix of the block(s) name. "
         "If this is a design drawing rename, the blocks to reflect a design not an as-built."
         "\nIf you have any questions please see <EDIT>"
        )
     )
    )
    ((progn
       (setq blklist "*WM_FIREHYD_,*WM_FIREHYD_[1-5]")
       (setq blk (ssget "x" (list (cons 0 "INSERT") (cons 2 blklist))))
     )
     (alert
       "Fire hydrants were located into the drawing that were not properly named, please correct and try again."
     )
    )
    (t
     (alert "All standard blocks found in drawing.... Now closing")
     (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) ".close ")
    )
  )
  (princ)
)
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 09:35:56 PM
Thank you for the revisions and the new versions of the code. I was going crazy. I really should start using vlide. I'm so use to the notepad :P for quick edits. I was working really hard on this code today... I even isolated myself in my office :realmad:.

I can't wait for Monday!

Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 10:07:15 PM
Now, once it's working what's the best way to make it run on close even if the 'X' is clicked, also is it possible to make it run only in drawings that existing in certain folders and any sub folders in the location?
X:\Eng\Gen\Asbuilts\*.dwg
but not select subfolders
X:\Eng\Gen\Asbuilts\Temp\*.dwg

I know you mentioned a reactor...but I have the slightest idea what I'm doing with those.

I followed your link from before and found some code posted here on the forums that I think could be modified. I would still like for the users to save their work, just not close without renaming the blocks. It would be nice if they 'End process' their AutoCAD it would generate an error email/text log save in a location without them knowing with the drawing data, but now I'm probably dreaming  :lmao: ...Can you send email through CAD?


Edit* The only thing I could find as now is a old command from CAB himself :P. It's got some writing to text file code in there.
http://www.theswamp.org/index.php?topic=3251.0

I also took out the email part. I found some code, but I do not wish to be that obvious with the command. I'm still not finding an existing code for trigger a text file with information. I could of swore I've seen one some time ago.... might had been just another request form a different member.

Looks like I need to do some more searching around.  8-)

Code: [Select]
(defun Save_Reactor_Create()
  (vl-load-com)
  (if
    (not clr:CloseReactor)
    (setq clr:CloseReactor
   (vlr-Editor-Reactor nil
     '((:vlr-beginSave  . PurgeBeforeClose))))
    ); end if
  (princ)
  ); end of Save_Reactor_Create

(Save_Reactor_Create)

(defun PurgeBeforeSave(reac args)
  (setq actDoc
(vla-get-ActiveDocument
   (vlax-get-acad-object)))
  (repeat 3(vla-Purgeall actDoc))
  (princ)
  ); end of PurgeBeforeSave

Thank you again for the help,
Daniel
Title: Re: Error is there a solution?
Post by: cadmoogle on January 09, 2009, 11:29:59 PM
CAB, could you remove Priscilla's name for that post. I didn't mean to post that part. Also could you delete this post? It's just yours and ron's reply.

Thanks
Title: Re: Error is there a solution?
Post by: alanjt on January 10, 2009, 01:13:39 AM
Now, once it's working what's the best way to make it run on close even if the 'X' is clicked, also is it possible to make it run only in drawings that existing in certain folders and any sub folders in the location?
X:\Eng\Gen\Asbuilts\*.dwg
but not select subfolders
X:\Eng\Gen\Asbuilts\Temp\*.dwg

I know you mentioned a reactor...but I have the slightest idea what I'm doing with those.

I followed your link from before and found some code posted here on the forums that I think could be modified. I would still like for the users to save their work, just not close without renaming the blocks. It would be nice if they 'End process' their AutoCAD it would generate an error email/text log save in a location without them knowing with the drawing data, but now I'm probably dreaming  :lmao: ...Can you send email through CAD?


Edit* The only thing I could find as now is a old command from CAB himself :P. It's got some writing to text file code in there.
http://www.theswamp.org/index.php?topic=3251.0

I also took out the email part. I found some code, but I do not wish to be that obvious with the command. I'm still not finding an existing code for trigger a text file with information. I could of swore I've seen one some time ago.... might had been just another request form a different member.

Looks like I need to do some more searching around.  8-)

Code: [Select]
(defun Save_Reactor_Create()
  (vl-load-com)
  (if
    (not clr:CloseReactor)
    (setq clr:CloseReactor
   (vlr-Editor-Reactor nil
     '((:vlr-beginSave  . PurgeBeforeClose))))
    ); end if
  (princ)
  ); end of Save_Reactor_Create

(Save_Reactor_Create)

(defun PurgeBeforeSave(reac args)
  (setq actDoc
(vla-get-ActiveDocument
   (vlax-get-acad-object)))
  (repeat 3(vla-Purgeall actDoc))
  (princ)
  ); end of PurgeBeforeSave

Thank you again for the help,
Daniel

this should work for your reactor needs:

Code: [Select]
(if (/= 'VLR-Command-Reactor (type ReactorCommandWillStart))
    (setq ReactorCommandWillStart
        (vlr-command-reactor nil
           '((:vlr-commandWillStart . CallbackCommandWillStart))
        )
    )
)

(defun CallbackCommandWillStart ( reactor cmdInfo / cmdName )
    (cond
        (   (eq "QUIT" (setq cmdName (car cmdInfo)))
(c:NewClose)
        )
    )
)
Title: Re: Error is there a solution?
Post by: cadmoogle on January 10, 2009, 02:04:38 AM
Thanks Alan, where do I place it? I've actually never worked with the reactors myself.
Title: Re: Error is there a solution?
Post by: CAB on January 10, 2009, 09:12:06 AM
CAB, could you remove Priscilla's name for that post. I didn't mean to post that part. Also could you delete this post? It's just yours and ron's reply.

Thanks

Done....
Title: Re: Error is there a solution?
Post by: CAB on January 10, 2009, 09:14:53 AM
The reactor code must be loaded in each DWG so ACADDOC.lsp or any other lisp that is loaded at the start of each DWG.
Title: Re: Error is there a solution?
Post by: CAB on January 10, 2009, 09:33:58 AM
Alan, You must consider these in your reactor:
http://www.theswamp.org/index.php?topic=12986.msg157991#msg157991
http://www.theswamp.org/index.php?topic=12986.msg158077#msg158077
Title: Re: Error is there a solution?
Post by: CAB on January 10, 2009, 03:11:18 PM
The problem with a reactor is that it cannot STOP the CLOSE COMMAND.

As I see it your options are:
Redefine the CLOSE command and make it the NewClose.lsp with some mods.

Use a reactor to detect the CLOSE command & create a report of the error.

Use a reactor to fix the block names before completing the Close Command.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 11, 2009, 10:08:44 AM
If you redefine the close command how does AutoCAD know to close? Also what if you wanted to bring back the old close command?

Thanks,
Daniel
Title: Re: Error is there a solution?
Post by: CAB on January 11, 2009, 12:27:51 PM
From the Help File
Quote
REDEFINE
Restores AutoCAD internal commands overridden by UNDEFINE

Command line: redefine

Enter command name:  Enter the name of an AutoCAD command turned off by the UNDEFINE command 

If a command has been undefined, you can still use it if you precede the command name with a period.

You can override a redefines command by placing a period in front of the command like this ".CLOSE"
Title: Re: Error is there a solution?
Post by: CAB on January 11, 2009, 12:30:19 PM
To redefine the close command you would just rename your routine  c:NewClose to c:Close
This would override the close command unless the user used .close
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 08:42:21 AM
I tested both versions of the code this, with the first version I get the following message

Quote
; error: bad argument value: does not fit in byte: 1489

I've yet to test CAB's version with my list of blocks.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 09:57:48 AM
Mine errors with the above statement, CABs version says the string is too long on input.

Ron's works but it takes a while to run. Is it possible to speed it up? It takes about 5 more like 10 :cry:seconds for it to pop up with the warning.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 11:33:31 AM
Ron is it possible to speed the command up? If no blocks are in the drawing it's quick, but the second more blocks appear it drags. If it were quicker this would do. It works as intended. Maybe a counter/progress bar would help if it could not be sped up? The second I load this onto the machines they're going to complain about closing time. Thank you.
Title: Re: Error is there a solution?
Post by: ronjonp on January 12, 2009, 12:04:05 PM
Try using this function instead...since you are not doing anything with the selection set, I made it stop looking at the first found occurrence and return T.
Code: [Select]
(defun manyblocknames2ss (blocklist / n ss)
  (setq n -1)
  (while (and (nth (setq n (1+ n)) blocklist)
              (not
                (setq ss (ssget "_x"
                                (list (cons 0 "INSERT") (cons 2 (nth n blocklist)))
                         )
                )
              )
         )
  )
  (and ss)
)
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 12:19:51 PM
Perhaps it would be faster to group the block names & do fewer ssget's.

It may be faster to ssget all INSERTS & compare there name to the list.
Title: Re: Error is there a solution?
Post by: ronjonp on January 12, 2009, 12:21:20 PM
Perhaps it would be faster to group the block names & do fewer ssget's.

It may be faster to ssget all INSERTS & compare there name to the list.

You're probably right.  :-)
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 12:23:36 PM
Ron your routine will lock in the loop if there are no hits, right?


PS just tested it & errors out if no hits.
Just need a test for end of list, but good idea though.
Title: Re: Error is there a solution?
Post by: ronjonp on January 12, 2009, 12:34:38 PM
You are correct senor CAB...I updated the code above to check that the counter is less than list length..then it ends.  :-)

That errors too...I should just quit now :-D
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 01:02:55 PM
I ran the updated copy and the following happens,

first it lags my machine then prompts this

Quote
; error: bad SSGET list value
Title: Re: Error is there a solution?
Post by: ronjonp on January 12, 2009, 01:08:58 PM
I ran the updated copy and the following happens,

first it lags my machine then prompts this

Quote
; error: bad SSGET list value


I updated the code again....give it a whirl.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 01:14:40 PM
It's not prompting errors, but it's only finding the first name in the list now. :)

I just added your update and testing now, so far it's working... be right back  :lol:
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 01:21:04 PM
It's working and if one of the blocks listed is in the drawing exist it prompts fast, but I tested it on a normal as-built that had none of the listed blocks in the drawing, just about 20 other blocks, and it still drags  :cry:

17 seconds is the time it takes to prompt "All standard blocks found in drawing"
Title: Re: Error is there a solution?
Post by: ronjonp on January 12, 2009, 01:35:06 PM
What needs to happen is what CAB said....break up the big list and ssget less times.....no time right now to do it. Sorry.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 02:01:23 PM
I broke it up into three selection sets each has around 500 is that still too much? I could further break it down into; bends, valves, etc. for each layer.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 02:30:15 PM
It seems to be a little quicker, how could I have it stop running the command if it does not find any blocks with WM, SS, FM or RE in the block names? The old blocks in the drawing seem to be slowing it down, so I figured if I could find a way for it to do a quick search before continuing it might deal with the lag when misc blocks are in the drawing.

So in a nutshell, run the command,
Do a quick search, if no blocks in the drawing contain WM, SS, FM or RE in the block names continue forward to close, but if they do have it scan for the listed block names.

Do you think that would help?


Thank you for all of the help guys!

Here is the working copy with all blocks and sets in it.
Title: Re: Error is there a solution?
Post by: dustinthiesse on January 12, 2009, 03:01:01 PM
Code: [Select]
(while
  (and
    (setq data(tblnext"block"(null data)))     ;;;while there are still blocks in the database
    (not(wcmatch(cdr(assoc 2 data))"*WM*,*SS*,*FM*,*RE*"))      ;;;and the current block name does not match the search string options
  )
)
;(if data     ;;;if it finds any matches then data is not nil
;;;continue rest of code here
Title: Re: Error is there a solution?
Post by: T.Willey on January 12, 2009, 03:05:38 PM
Step through the block table, and compare the name of the block to the list.  If it's in the list, then add the block inserts ( which can be gotten from the block table record ) to an ssget variable.  Then do what you want with the ssget.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 03:10:01 PM
Step through the block table, and compare the name of the block to the list.  If it's in the list, then add the block inserts ( which can be gotten from the block table record ) to an ssget variable.  Then do what you want with the ssget.

I'm not that advanced  :-P. Where would I start? The previous command would select it from the drawing, but I could never get the larger list of block names to work.
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 03:12:39 PM
Give this one a go.
<edit: old code removed>
Title: Re: Error is there a solution?
Post by: T.Willey on January 12, 2009, 03:16:36 PM
Here is what I'm talking about.

Code: [Select]
(defun GetInserts ( blkNameList / ss Data tempName tempEnt)
   
    (setq blkNameList (mapcar 'strcase blkNameList))
    (setq ss (ssadd))
    (while (setq Data (tblnext "block" (not Data)))
        (if (vl-position (setq tempName (strcase (cdr (assoc 2 Data)))) blkNameList)
            (progn
                (setq Data
                    (entget
                        (cdr
                            (assoc
                                330
                                (entget (tblobjname "block" tempName))
                            )
                        )
                    )
                )
                (foreach i (member '(102 . "{BLKREFS") Data)
                    (if
                        (and
                            (equal (car i) 331)
                            (not (vlax-erased-p (setq tempEnt (cdr i))))
                        )
                        (ssadd tempEnt ss)
                    )
                )
            )
        )
    )
    (if (> (sslength ss) 0)
        ss
        nil
    )
)
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 03:18:39 PM
Give this one a go.


CAB this flies  :-D but, when I test it out on this drawing it returns nils and does not continue to close. Attached is thew DWG sample.

Thank you,
Daniel

Title: Re: Error is there a solution?
Post by: T.Willey on January 12, 2009, 03:19:59 PM
Or one with just Lisp

Code: [Select]
(defun GetInserts ( blkNameList / ss Data tempName tempEnt)
   
    (setq blkNameList (mapcar 'strcase blkNameList))
    (setq ss (ssadd))
    (while (setq Data (tblnext "block" (not Data)))
        (if (vl-position (setq tempName (strcase (cdr (assoc 2 Data)))) blkNameList)
            (progn
                (setq Data
                    (entget
                        (cdr
                            (assoc
                                330
                                (entget (tblobjname "block" tempName))
                            )
                        )
                    )
                )
                (foreach i (member '(102 . "{BLKREFS") Data)
                    (if
                        (and
                            (equal (car i) 331)
                            (entget (setq tempEnt (cdr i)))
                        )
                        (ssadd tempEnt ss)
                    )
                )
            )
        )
    )
    (if (> (sslength ss) 0)
        ss
        nil
    )
)
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 03:35:58 PM
OK another version.
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 03:41:26 PM
I swear after this my first two children are going to have to be named CAB and Ron  :-)

That worked but it is still nil on blank drawings from some reason. Qnew and run the command it should come up nil. Is that from an if statement?
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 03:56:05 PM
This was just thrown together to test for speed.
What did you want it to return? (too lazy to read the entire thread)  :-)
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 03:58:50 PM
This was just thrown together to test for speed.
What did you want it to return? (too lazy to read the entire thread)  :-)


It's working great but is just getting hung up on nil if the drawing has no blocks in it. I was planning on replacing the close command with this. That would mean if the drawing had no blocks/ or none that match WM,SS, etc this would hang up on nil and not close.
Title: Re: Error is there a solution?
Post by: ronjonp on January 12, 2009, 04:02:50 PM
Here is a mod of T Willey's function that will quit after the first occurrence found. I'd guess that it would be super fast...but have not tested it.

Code: [Select]
(defun GetInserts ( blkNameList / imdone Data tempName tempEnt)
   
    (setq blkNameList (mapcar 'strcase blkNameList))
    (while (and (setq Data (tblnext "block" (not Data)))(not imdone))
        (if (vl-position (setq tempName (strcase (cdr (assoc 2 Data)))) blkNameList)
            (progn
                (setq Data
                    (entget
                        (cdr
                            (assoc
                                330
                                (entget (tblobjname "block" tempName))
                            )
                        )
                    )
                )
                (foreach i (member '(102 . "{BLKREFS") Data)
                    (if
                        (and
                            (equal (car i) 331)
                            (entget (setq tempEnt (cdr i)))
                        )
                        (setq imdone T)
                    )
                )
            )
        )
    )
  (and imdone)
 
)

*tested....and it's SUPER fast...nice one Tim.
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 04:11:36 PM
I localized the variables which may have been the problem.

<edit: removed code with error>
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 04:17:27 PM
I localized the variables which may have been the problem.



 :-o still nil on when no blocks exist or those that do not match WM, SS, FM or RE, hmm
Title: Re: Error is there a solution?
Post by: T.Willey on January 12, 2009, 04:24:11 PM
<snip>


*tested....and it's SUPER fast...nice one Tim.

Thanks for testing Ron.  I figured it would be quicker to just step through one thing, that being the block table here, instead of searching the database as many times as there are block names.
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 04:29:36 PM
OK, this should do it. Sorry.  :oops:
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 04:32:52 PM
Thanks guys both versions are working properly. I will do some further testing but it's looking good!
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 04:33:40 PM
How is close all connected to close? If I replaced close would this take care of close all?
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 04:42:16 PM
CAB, I loaded into the startup and the old close all still function not the newclose. So I'm guessing I have to redefine....
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 05:01:47 PM
Name the lisp with (defun c:close
load it via startup and use this in a lisp that loads last
(command "undefine" "Close")
Do you have something loading at the end of startup?
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 05:07:34 PM
Yep, zero width lisp. I noticed the top right X will allow the user to closeall even with the command undefined.
Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 06:48:35 PM
I guess we are stuck. We can redefine the CLOSE, QUIT, and SAVE commands but the X out issues a .CLOSE
which skips our close routine. Although a reactor can catch the X out close the reactor can not stop the CLOSE.

Pondering a solution...  :|
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 07:48:58 PM
Will then it just becomes a reminder message  :|. I've been thinking of ways I can further use it. My first thought was just to place it on the machines, but I'm worried about the user getting annoyed and removing it at will. So I could bury it in acaddoc.lisp and lock the privileges on the folder  :evil:. I've been looking at a way to create a report to a text file but I'm not having any luck. I've come across an old command from 2004 that you wrote, but I'm not sure if it would work.

Have you or anyone else you know have created some type of logging report?

Tricky, tricky...  :-(



 

Title: Re: Error is there a solution?
Post by: CAB on January 12, 2009, 08:13:24 PM
Output to a text file is easy once you have done one. I'll post a routine tomorrow.

What do you want to include in the output & do you want to append to an existing log file
or create a new one each time?
Title: Re: Error is there a solution?
Post by: cadmoogle on January 12, 2009, 09:26:51 PM
Output to a text file is easy once you have done one. I'll post a routine tomorrow.

What do you want to include in the output & do you want to append to an existing log file
or create a new one each time?


Append the current log and and store it public or private location.

Store the time/date, drawing name and user saving the project. Is it possible after it warns the user of the blocks in the drawing (like it does now). Show a yes or no prompt after the alerts; prompt the user and ask. Do you wish to exit the drawing with out renaming the blocks? if they hit yes it will then append or create the log without telling the user. No, will close the drawing.

I'm thinking that will probably be it  :angel:

Besides needing to find a way to secure the lisp without them modifying it.. All arrows are still pointing towards acaddoc.lsp and locking the folder.

Thanks again for all of the help :)
Title: Re: Error is there a solution?
Post by: cadmoogle on January 13, 2009, 12:00:37 PM
It appears the top right triggers _quit which worked when redefined.The window X triggers _close. So I was able to redefine both commands to prompt the command.
Title: Re: Error is there a solution?
Post by: CAB on January 13, 2009, 12:08:51 PM
Looks like the X out will vary from one ACAD version to another.
As long as there is no dot before the command like 2000 has a dotCLOSE and can not be redefined.

You will need to redefine QUIT, CLOSE & SAVE.


Code: [Select]
(defun c:quit() (c:close))
(defun c:save() (c:close))
(defun c:Close (/ NotOK2Close ss )
Title: Re: Error is there a solution?
Post by: cadmoogle on January 13, 2009, 01:16:48 PM
I load the lisp on a 2009 regular AutoCAD vs my 2009 Map 3D and this is the result when the command is ran.

Quote
Command: (LOAD "C:/Documents and Settings/mrs300/Desktop/NewClose_CAB.lsp")
BLOCKCHECK

Command: newclose
; error: no function definition: VLAX-GET-ACAD-OBJECT

Command:

I still need to test it on 2008
Title: Re: Error is there a solution?
Post by: CAB on January 13, 2009, 01:24:53 PM
Add this to the lisp!
Code: [Select]
(vl-load-com)
Title: Re: Error is there a solution?
Post by: cadmoogle on January 13, 2009, 01:51:05 PM
Add this to the lisp!
Code: [Select]
(vl-load-com)

Figures  8-)
Title: Re: Error is there a solution?
Post by: wizman on January 14, 2009, 03:12:11 PM
just adding a note where another consideration/test to be done also is during publishing where drawings open and close.