Author Topic: If statement. Layer gets made but color won't set.  (Read 526 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #15 on: November 27, 2018, 04:50:05 PM »
So here's my result with your suggestion for using wcmatch. Worked nicely and shortened the routine. Like it!

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ST136to191 (/ *error* osm cl136 fm136 ss attValue)
  2.  (defun *error* ( msg )
  3.        (if osm (setvar 'osmode osm))
  4.        (if (not (member msg '("Function cancelled" "quit / exit abort")))
  5.            (princ (strcat "\nError: " msg))
  6.        )
  7.        (princ)
  8.    )
  9.  
  10.    (setq osm (getvar 'osmode))
  11.    (setvar 'osmode 0)
  12.    (setvar 'cmdecho 0)
  13.  (defun LM:GetAttributeValue (blk tag / val enx)
  14.    (while
  15.      (and
  16.        (null val)
  17.        (= "ATTRIB"
  18.           (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
  19.        )
  20.      )
  21.       (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
  22.         (setq val (cdr (assoc 1 enx)))
  23.       )
  24.    )
  25.  )
  26.  
  27.   (setq cl136 (ssget "x" '((62 . 136)(0 . "LINE,POLYLINE,LWPOLYLINE,TEXT,MTEXT"))))
  28.     (command "_chprop" cl136 "" "_COLOR" "191" (command)(command))
  29.  
  30.    (setq ss (ssget "x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL")(66 . 1))))
  31.    (setq attValue (LM:GetAttributeValue (ssname ss 0) "TITLELINE4"))
  32.  
  33. (cond ((wcmatch (strcase attvalue) "EQUIPMENT PLAN,INTERIOR ELEVATIONS")
  34.       (setq fm136 (ssget "x" '((8 . "FiberMgt_136"))))
  35.        (command "._Layer" "Make" "FiberMgt_191" "_Color" "191" "FiberMgt_191" "Make" "FiberMgt_1" "Color" "RED" (command)(command))
  36.        (command "_chprop" fm136 "" "LA" "FiberMgt_191" "" (command)(command))
  37.        (command "._layer" "filter" "edit" "Stations Standard Layers" "add" "FiberMgt_191" "exit" (command)(command))
  38.  )
  39. )
  40. (rtos (getreal "\nPress Esc to exit, press Enter to force an error ..."))
  41.  
  42.    (setvar 'osmode osm)
  43.  (setvar 'cmdecho 1)  
  44.  
  45.  (princ)
  46. )

I get...

Command: ST136TO191
Unknown command "ST136TO191".  Press F1 for help.

I've looked for spaces and missing spaces. Just can't find the issue.

J. Logan
ACAD2019
« Last Edit: November 27, 2018, 04:53:34 PM by jlogan02 »
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.

ronjonp

  • Needs a day job
  • Posts: 6805
Re: If statement. Layer gets made but color won't set.
« Reply #16 on: November 27, 2018, 05:03:52 PM »
First thing that looks strange is all the (command)(command) calls?
 Maybe "._layer" should be ".-layer" ?
« Last Edit: November 27, 2018, 05:13:35 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2019

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 6805
Re: If statement. Layer gets made but color won't set.
« Reply #17 on: November 27, 2018, 05:22:09 PM »
Here's a quick ( untested ) stab at removing some of the command calls:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:st136to191 (/ *error* osm cl136 fm136 ss attvalue)
  2.  (defun _addlayer (name color ltype plot)
  3.    (cond ((not (tblsearch "layer" name))
  4.   (entmakex (list '(0 . "LAYER")
  5.   '(100 . "AcDbSymbolTableRecord")
  6.   '(100 . "AcDbLayerTableRecord")
  7.   '(70 . 0)
  8.   (cons 2 name)
  9.   (cons 62 color)
  10.   (cons 6
  11. (cond ((tblobjname "ltype" ltype))
  12.       ("continuous")
  13. )
  14.   )
  15.   (cons 290 plot)
  16.   ;;1 = plottable 0 = not=plottable
  17.     )
  18.   )
  19.  )
  20.  ((tblobjname "layer" name))
  21.    )
  22.  )
  23.  (defun *error* (msg)
  24.    (if osm
  25.      (setvar 'osmode osm)
  26.    )
  27.    (if (not (member msg '("Function cancelled" "quit / exit abort")))
  28.      (princ (strcat "\nError: " msg))
  29.    )
  30.    (princ)
  31.  )
  32.  (setq osm (getvar 'osmode))
  33.  (setvar 'osmode 0)
  34.  (setvar 'cmdecho 0)
  35.  (defun lm:getattributevalue (blk tag / val enx)
  36.    (while
  37.      (and (null val) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))))
  38.       (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
  39. (setq val (cdr (assoc 1 enx)))
  40.       )
  41.    )
  42.  )
  43.  (if (setq cl136 (ssget "x" '((62 . 136) (0 . "LINE,POLYLINE,LWPOLYLINE,TEXT,MTEXT"))))
  44.    (foreach x (mapcar 'cadr (ssnamex cl136)) (entmod (append (entget x) '((62 . 191)))))
  45.  )
  46.  (setq ss (ssget "x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1))))
  47.  (setq attvalue (lm:getattributevalue (ssname ss 0) "TITLELINE4"))
  48.  (cond ((wcmatch (strcase attvalue) "EQUIPMENT PLAN,INTERIOR ELEVATIONS")
  49. (_addlayer "FiberMgt_191" 191 "Continous" 1)
  50. (_addlayer "FiberMgt_1" 1 "Continous" 1)
  51. (if (setq fm136 (ssget "x" '((8 . "FiberMgt_136"))))
  52.   (foreach x (mapcar 'cadr (ssnamex fm136))
  53.     (entmod (append (entget x) '((8 . "FiberMgt_191"))))
  54.   )
  55. )
  56. ;; Changed to -layer
  57. (command ".-layer"
  58.  "filter"
  59.  "edit"
  60.  "Stations Standard Layers"
  61.  "add"
  62.  "FiberMgt_191"
  63.  "exit"
  64.  (command)
  65.  (command)
  66. )
  67. )
  68.  )
  69.  ;; Why this?
  70.  (rtos (getreal "\nPress Esc to exit, press Enter to force an error ..."))
  71.  (setvar 'osmode osm)
  72.  (setvar 'cmdecho 1)
  73.  (princ)
  74. )

Windows 10 x64 - AutoCAD /C3D 2019

Custom Build PC

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #18 on: November 29, 2018, 12:10:57 PM »
Sorry Ron, I didn't see this post. I had the command calls in there because it seemed that was the only way I could avoid getting "Unknown command..." errors at the command line.

I've been assuming I'm getting those because I'm ending the Change properties commands or the layers commands wrong/ungracefully. that was my fix. Perhaps I'm mistaken. I don't know how the message at the end got left in there. I did have error checking in it but removed it, well not all of it, while testing.

J. Logan
ACAD 2018
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.