Author Topic: Error is there a solution?  (Read 14201 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7027
Re: Error is there a solution?
« Reply #15 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 :)")
)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

dustinthiesse

  • Guest
Re: Error is there a solution?
« Reply #16 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

cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #17 on: January 09, 2009, 03:59:38 PM »
Command: ; error: bad SSGET list value

This is the result.

cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #18 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))
 )
)
)

« Last Edit: January 09, 2009, 04:27:35 PM by cadmoogle »

dustinthiesse

  • Guest
Re: Error is there a solution?
« Reply #19 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....

cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #20 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.

« Last Edit: January 09, 2009, 10:54:32 PM by cadmoogle »

ronjonp

  • Needs a day job
  • Posts: 7027
Re: Error is there a solution?
« Reply #21 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
  )
)
« Last Edit: January 10, 2009, 09:09:34 AM by CAB »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: Error is there a solution?
« Reply #22 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
« Last Edit: January 10, 2009, 09:09:10 AM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: Error is there a solution?
« Reply #23 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)
)
« Last Edit: January 10, 2009, 09:10:29 AM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #24 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!


cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #25 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
« Last Edit: January 09, 2009, 10:59:17 PM by cadmoogle »

cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #26 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

alanjt

  • Needs a day job
  • Posts: 5327
  • Standby for witty remark...
Re: Error is there a solution?
« Reply #27 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)
        )
    )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cadmoogle

  • Guest
Re: Error is there a solution?
« Reply #28 on: January 10, 2009, 02:04:38 AM »
Thanks Alan, where do I place it? I've actually never worked with the reactors myself.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: Error is there a solution?
« Reply #29 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....
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.