Author Topic: Error in code - Can someone help?  (Read 6678 times)

0 Members and 1 Guest are viewing this topic.

stusic

  • Guest
Error in code - Can someone help?
« on: July 17, 2012, 12:57:57 PM »
I've got this code, patchworked from other LIPSers and a bunch of other things, but I keep getting errors and can't for the life of me find it. Can someone take a look and see if they can find what's up? I'm just trying to define different variables (the "fld#") and populate an attributed block with those variables.

Thanks so much :)

Code: [Select]
(vl-load-com)

(defun c:UTB (filePath     /    i   folder folders
      ent
      ss     att    fld1   fld2   fld3 fld4 fld5   fld6
      dwg    dn     a
     )


;; DRAWNBY
(setq fld1 (strcat (eval "%<\\AcVar Login \\f \"%tc1\">%")))
 
;; DRAWNDATE
(setq fld2 (strcat (eval "%<\\AcVar CreateDate \\f \"M/d/yyyy\">%")))
 
;; DRAWING_NO
(setq fld3 (strcat (eval "%<\\AcVar Filename \\f \"%tc1%fn2\">%")))

;; ITEM_NO
(setq dn (strlen (getvar "dwgname")))

(setq fld4
   (cond
     ((= dn 14) (substr (getvar "dwgname") 1 8))
     ((= dn 15) (substr (getvar "dwgname") 1 8))
     ((= dn 16) (substr (getvar "dwgname") 1 10))
     ((= dn 17) (substr (getvar "dwgname") 1 10))
     (t (princ "Drawing Format Unrecognized"))
   )
    )

;; DESCRIPTION
(setq fld5
       (cond
((wcmatch (setq dwg (getvar 'dwgname)) "*PD*")
  "PIPING DIAGRAM"
)
((wcmatch dwg "*HL*") "HEADER LAYOUT")
((wcmatch dwg "*CL*") "COMPRESSOR LAYOUT")
((wcmatch dwg "*CHL*") "COMPRESSOR HEADER LAYOUT")
((wcmatch dwg "*WD*") "WIRING DIAGRAM")
((wcmatch dwg "*KS1*") "HOUSE PLAN VIEW")
((wcmatch dwg "*KS2*") "HOUSE LIFTING & ELEVATION")
((wcmatch dwg "*KS3*") "HOUSE BASE")
((wcmatch dwg "*KS4*") "HOUSE WALLS")
((wcmatch dwg "*KS5*") "HOUSE ROOF")
((wcmatch dwg "*KS6*") "CONDENSER SUPPORT")
((wcmatch dwg "*KS7*") "CATWALK")
((wcmatch dwg "*KS8*") "HANDRAILS")
((wcmatch dwg "*KS9*") "SHEETMETAL LAYOUT")
((wcmatch dwg "*KS10*") "CURB")
((wcmatch dwg "*KE1*") "ELECTRICAL PLAN VIEW")
((wcmatch dwg "*KE2*") "LINE DIAGRAM & PANEL SCHEDULES")
((wcmatch dwg "*KE3*") "HOUSE CONTROLS DIAGRAM")
((wcmatch dwg "*KE4*") "DEFROST PANEL WIRING DIAGRAM")
((wcmatch dwg "*KM1*") "HOUSE PIPING DIAGRAM")
(t
  (princ
    "\nNo matching drawing descriptions found. Valid name extentions are: HL, CL, CHL, WD, KS1, KS2, KS3, KS4, KS5, KS6, KS7, KS8, KS9, KS10, KE1, KE2, KE3, KE4, KM1"
  )
)
       )
)

;; SALES_ORDER
  (defun _FilePath->List (filePath / i folder folders)
  (setq filePath (vl-string-translate "\\" "/" filePath))
  (while (setq i (vl-string-search "/" filePath))
     (setq folders (cons (setq folder (substr filePath 1 i)) folders))
     (setq filePath (substr filePath (+ 2 i)))
     )
  (reverse folders)
  )

  (setq fld6 (nth 2 filePath))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(if (setq ss (ssget "X"
    (list (cons 0 "INSERT")
  (cons 2 "*BORDER*")
  (cons 66 1)
  (if (getvar "CTAB")
    (cons 410 (getvar "CTAB"))
    (cons 67 (- 1 (getvar "TILEMODE")))
  )
    )
     )
    )

  (progn
    (foreach ent (mapcar 'cadr (ssnamex ss))
      (setq att (entnext ent))
      (while (not (eq "SEQEND" (cdadr (entget att))))
(cond
  ((eq "DRAWNBY" (cdr (assoc 2 (entget att))))
   (entmod
     (subst (cons 1 fld1) (assoc 1 (entget att)) (entget att))
   )
  )
  ((eq "DRAWNDATE" (cdr (assoc 2 (entget att))))
   (entmod
     (subst (cons 1 fld2) (assoc 1 (entget att)) (entget att))
   )
  )
  ((eq "DRAWING_NO" (cdr (assoc 2 (entget att))))
   (entmod
     (subst (cons 1 fld3) (assoc 1 (entget att)) (entget att))
   )
  )
  ((eq "ITEM_NO" (cdr (assoc 2 (entget att))))
   (entmod
     (subst (cons 1 fld4) (assoc 1 (entget att)) (entget att))
   )
  )
  ((eq "DESCRIPTION" (cdr (assoc 2 (entget att))))
   (entmod
     (subst (cons 1 fld5) (assoc 1 (entget att)) (entget att))
   )
  )
  ((eq "SALES_ORDER" (cdr (assoc 2 (entget att))))
   (entmod
     (subst (cons 1 fld6) (assoc 1 (entget att)) (entget att))
   )
  )
)
(setq att (entnext att))
      )
    )
    (command "_regenall")
  )
  (princ "\n<!> No Blocks Found <!>")
)
)

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #1 on: July 17, 2012, 05:23:46 PM »
... You're killing me, stusic. LoL
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #2 on: July 18, 2012, 06:39:39 AM »
... You're killing me, stusic. LoL

You? I'm killing me!

This one stupid lisp ain't that difficult, and I've gotten help with pieces here and there, but come time to put it all together and it bombs out. I've never been able to figure out error checking in vlide, so some vague error doesn't tell me a thing. I'm really ready to move on to something else.

I think the ITEM_NO code looks okay (per examples by pbjse). I don't think I'm using your code for SALES_ORDER correctly, but even if I comment it out, it still bombs. It's killing me. Please ignore this thread, Renderman, I've taken up enough of your time. I was hoping this was just a simple syntax error where someone might just say, "Hey! You're missing a closing paren, idiot!".

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Error in code - Can someone help?
« Reply #3 on: July 18, 2012, 08:10:55 AM »
You need to upload test DWG so that someone can easily test the code.
It's too much work to recreate the test conditions.
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.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Error in code - Can someone help?
« Reply #4 on: July 18, 2012, 08:51:44 AM »
Do you not use the VLIDE editor?

One error I see is this line:
Code: [Select]
(setq fld6 (nth 2 filePath))
filepath is never set so it bonks out ... plus you are feeding nth a string when it needs a list.

Perhaps this instead?
Code: [Select]
(setq fld6 (nth 2 (_FilePath->List (getvar 'dwgprefix))))
« Last Edit: July 18, 2012, 09:21:58 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #5 on: July 18, 2012, 10:09:18 AM »
You need to upload test DWG so that someone can easily test the code.
It's too much work to recreate the test conditions.

I was hoping it'd be an obvious error that one could identify without testing, but, again, I was wrong. Thanks, Cab.

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #6 on: July 18, 2012, 10:18:18 AM »
Do you not use the VLIDE editor?

I do, but I just have never gotten the hang of the error-checking within it. I know there's a way you can load the code into acad, but I still use appload...  :ugly:

One error I see is this line:
Code: [Select]
(setq fld6 (nth 2 filePath))
filepath is never set so it bonks out ... plus you are feeding nth a string when it needs a list.

Perhaps this instead?
Code: [Select]
(setq fld6 (nth 2 (_FilePath->List (getvar 'dwgprefix))))

Code: [Select]
;; SALES_ORDER
  (defun _FilePath->List (filePath / i folder folders)
  (setq filePath (vl-string-translate "\\" "/" filePath))
  (while (setq i (vl-string-search "/" filePath))
     (setq folders (cons (setq folder (substr filePath 1 i)) folders))
     (setq filePath (substr filePath (+ 2 i)))
     )
  (reverse folders)
  )

I know I'm not doing this part right - Renderman gave me the snippet above it, but it's using things I haven't fiddled with before. I was kinda taking stabs at it, hoping it'll work. I'm just trying to isolate the name of the third folder up from the the drawing location (which Renderman's code does) and apply that to the "fld6" variable.

So the:
Code: [Select]
(setq fld6 (nth 2 filePath))was my attempt at getting his code into my variable (and definitely not his handiwork :))

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Error in code - Can someone help?
« Reply #7 on: July 18, 2012, 10:24:47 AM »
So did my suggestion fix your problem?

You could try something like this:

Code: [Select]
(or ;; Grabs the 3rd folder up from drawing directory
    (setq fld6 (nth 2 (_FilePath->List (reverse (getvar 'dwgprefix)))))
    ;; fld6 not set so set it to the drive letter
    (setq fld6 (car (_FilePath->List (getvar 'dwgprefix))))
)
« Last Edit: July 18, 2012, 10:32:42 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #8 on: July 18, 2012, 12:09:33 PM »
I'm sure more can be done to improve this, but I am unable to test the block you posted as I do not have your directory structure on my system:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:UTB (/        *error*  _FilePath->List   _entmod  ss
  2.               fld1     fld2     fld3     fld4     fld5     fld6
  3.               dwg      dn       filePath i        ent      att
  4.               attData  tag
  5.              )
  6.  
  7.   ;; Error handler
  8.   (defun *error* (msg)
  9.     (and oldCmdecho (setvar 'cmdecho oldCmdecho))
  10.     (cond ((not msg))                                                   ; Normal exit
  11.           ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
  12.           ((princ (strcat "\n** Error: " msg " ** ")))
  13.     )                                                                   ; Fatal error, display it
  14.     (princ)
  15.   )
  16.  
  17.   (defun _FilePath->List (filePath / i folder folders)
  18.     ;; RenderMan, 2012
  19.     (setq filePath (vl-string-translate "\\" "/" filePath))
  20.     (while (setq i (vl-string-search "/" filePath))
  21.       (setq folders (cons (setq folder (substr filePath 1 i)) folders))
  22.       (setq filePath (substr filePath (+ 2 i)))
  23.     )
  24.     (reverse folders)
  25.   )
  26.  
  27.   (defun _entmod (fld data)
  28.     (entmod (subst (cons 1 fld) (assoc 1 data) data))
  29.   )
  30.  
  31.   ;; Main code
  32.   (if (and
  33.         (setq ss (ssget "_x"
  34.                         (list (cons 0 "INSERT")
  35.                               (cons 2 "*BORDER*")
  36.                               (cons 66 1)
  37. ;;;                              (cons 410 (getvar 'ctab))
  38.                         )
  39.                  )
  40.         )
  41.         (setq fld1 "%<\\AcVar Login \\f \"%tc1\">%")                    ; Field: Drawn by
  42.         (setq fld2 "%<\\AcVar CreateDate \\f \"M/d/yyyy\">%")           ; Field: Drawn date
  43.         (setq fld3 "%<\\AcVar Filename \\f \"%tc1%fn2\">%")             ; Field: Drawing number
  44.         (setq fld4                                                      ; Field: Item number
  45.                (cond
  46.                  ((or (= (setq dn (strlen (setq dwg (getvar 'dwgname)))) 14)
  47.                       (= dn 15)
  48.                   )
  49.                   (substr dn 1 8)
  50.                  )
  51.                  ((or (= dn 16) (= dn 17)) (substr dn 1 10))
  52.                )
  53.         )
  54.         (setq fld5                                                      ; Field: Description
  55.                (cond
  56.                  ((wcmatch dwg "*PD*") "PIPING DIAGRAM")
  57.                  ((wcmatch dwg "*HL*") "HEADER LAYOUT")
  58.                  ((wcmatch dwg "*CL*") "COMPRESSOR LAYOUT")
  59.                  ((wcmatch dwg "*CHL*") "COMPRESSOR HEADER LAYOUT")
  60.                  ((wcmatch dwg "*WD*") "WIRING DIAGRAM")
  61.                  ((wcmatch dwg "*KS1*") "HOUSE PLAN VIEW")
  62.                  ((wcmatch dwg "*KS2*") "HOUSE LIFTING & ELEVATION")
  63.                  ((wcmatch dwg "*KS3*") "HOUSE BASE")
  64.                  ((wcmatch dwg "*KS4*") "HOUSE WALLS")
  65.                  ((wcmatch dwg "*KS5*") "HOUSE ROOF")
  66.                  ((wcmatch dwg "*KS6*") "CONDENSER SUPPORT")
  67.                  ((wcmatch dwg "*KS7*") "CATWALK")
  68.                  ((wcmatch dwg "*KS8*") "HANDRAILS")
  69.                  ((wcmatch dwg "*KS9*") "SHEETMETAL LAYOUT")
  70.                  ((wcmatch dwg "*KS10*") "CURB")
  71.                  ((wcmatch dwg "*KE1*") "ELECTRICAL PLAN VIEW")
  72.                  ((wcmatch dwg "*KE2*") "LINE DIAGRAM & PANEL SCHEDULES")
  73.                  ((wcmatch dwg "*KE3*") "HOUSE CONTROLS DIAGRAM")
  74.                  ((wcmatch dwg "*KE4*") "DEFROST PANEL WIRING DIAGRAM")
  75.                  ((wcmatch dwg "*KM1*") "HOUSE PIPING DIAGRAM")
  76.                )
  77.         )
  78.         (or                                                             ; Field: Folder
  79.           (setq fld6
  80.                  (nth 2
  81.                       (setq filePath (_FilePath->List (getvar 'dwgprefix)))
  82.                  )
  83.           )
  84.           (setq fld6 (car filePath))
  85.         )
  86.       )
  87.     (progn
  88.       (setq i -1)
  89.       (while (setq ent (ssname ss (setq i (1+ i))))
  90.         (setq att (entnext ent))
  91.         (setq attData (entget att))
  92.         (while (not (= "SEQEND" (cdadr attData)))
  93.           (setq tag (cdr (assoc 2 attData)))
  94.           (cond
  95.             ((= "DRAWNBY" tag) (_entmod fld1 attData))
  96.             ((= "DRAWNDATE" tag) (_entmod fld2 attData))
  97.             ((= "DRAWING_NO" tag) (_entmod fld3 attData))
  98.             ((= "ITEM_NO" tag) (_entmod fld4 attData))
  99.             ((= "DESCRIPTION" tag) (_entmod fld5 attData))
  100.             ((= "SALES_ORDER" tag) (_entmod fld6 attData))
  101.           )
  102.           (setq att (entnext att))
  103.         )
  104.       )
  105.       (command "._regenall")
  106.       (*error* nil)
  107.     )
  108.     (cond
  109.       (fld4 (*error* "No matching drawing descriptions found"))
  110.       (fld3 (*error* "Drawing format unrecognized"))
  111.       ((*error* "No blocks found"))
  112.     )
  113.   )
  114. )
  115.  

Good luck!
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #9 on: July 20, 2012, 06:17:12 AM »
Not ignoring you guys, just gotta get a few things done first to avoid working this Saturday. I've copied over Renderman's code, but I get an error, so I'm I'm teaching myself the debugging tools of VLIDE to try and figure it out before I come back with hat in hand (again). I figured that code would be better for debugging, because it shouldn't be completely screwed to start off with. I'll report soon, standby.

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #10 on: July 20, 2012, 11:22:42 AM »
I'm sure more can be done to improve this, but I am unable to test the block you posted as I do not have your directory structure on my system:

Not ignoring you guys, just gotta get a few things done first to avoid working this Saturday. I've copied over Renderman's code, but I get an error, so I'm I'm teaching myself the debugging tools of VLIDE to try and figure it out before I come back with hat in hand (again). I figured that code would be better for debugging, because it shouldn't be completely screwed to start off with. I'll report soon, standby.

That's too bad... :| *kicks dirt* 
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #11 on: July 20, 2012, 03:16:14 PM »
That's too bad... :| *kicks dirt*

I don't think it's a serious error, most likely an oversight, but I thought it would be a good opportunity to work through the debugging tools (although I've yet to solve it).

Part of what I found was the dn in "(substr dn 1 10)" seemed like it should be dwg, since dn only holds the strlen. So when we tried to get the first 10 characters, it bombed because the variable dn was only two characters ("16"). Let me know if that was correct - it made sense to me, but so does deja vu.

I changed that and got a little further, but now it seems to hiccup around the "(setq att (entnext att))" with "** Error: bad argument type: lentityp nil **", but I can't figure out why (but I'm working on it).

Btw, not too bad for not having anything to work with ;)

BlackBox

  • King Gator
  • Posts: 3770
Re: Error in code - Can someone help?
« Reply #12 on: July 20, 2012, 03:24:33 PM »

Part of what I found was the dn in "(substr dn 1 10)" seemed like it should be dwg, since dn only holds the strlen. So when we tried to get the first 10 characters, it bombed because the variable dn was only two characters ("16"). Let me know if that was correct - it made sense to me, but so does deja vu.

Bingo... I totally overlooked that the other day. Perhaps unfair to you, I really rushed that code attempt using snippets from various other routines.


Btw, not too bad for not having anything to work with ;)

 :lol:
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #13 on: July 20, 2012, 03:32:51 PM »
unfair

This word, I do not think it means what you think it means.

I think what you meant was "extremely helpful".

stusic

  • Guest
Re: Error in code - Can someone help?
« Reply #14 on: July 20, 2012, 03:45:23 PM »
Doh, I commented out
Code: [Select]
(setq att (entnext att))and it got hung. Maybe I'll read up on the WHILE function a bit ;)