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

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Newt
  • Posts: 62
If statement. Layer gets made but color won't set.
« on: November 16, 2018, 05:33:47 PM »
I can't figure out why in the second "progn" the layer will get made, but it's color won't get set to 136.


Code - Auto/Visual Lisp: [Select]
  1.  
  2. (if (tblsearch "LAYER" "FiberMgt_136") ;Check if the layer exists
  3.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  4.   (command "_chprop" fm136 "" "p" "la" "FiberMgt_136" "" (command)(command))
  5. ) ;End if progn?
  6.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  7.   (command "._Layer" "Make" "FiberMgt_136" "_Color" "136" "" "" (command)(command));;[b]Color won't set here. The layer gets made and objects get moved to the layer. But the color is White:[/i]
  8.   (command "_chprop" fm136 "" "p" "la" "Fibermgt_136" "" (command)(command))
  9. ) ;End if progn
  10. ) ;End of if
  11.  
  12.    (setvar 'osmode osm)
  13.    (princ)
  14. )

J. Logan
ACAD 218
J. Logan
ACAD 2018

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

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #1 on: November 16, 2018, 05:55:45 PM »
Edit: All of this works fine but my approach is wonky. The FiberMgt layers will only exist on a building equipment plan. There's another portion of the code (not shown) which deals with changing objects from their bylayer color to a construction/rev color. Those changes occur on the building equipment plan and a multitude of schematics, wiring diagrams and etc. As it stands now the code below will create the FiberMgt layer on every type of drawing if the layer doesn't exist.

I don't want that. I want it to do everything it's doing just not on every type of drawing.
Title Block is attributed - Could I...

(if (attribute "titleline4" reads Building Plan
(do the deed

or

(if (block FM insert exists
(do the deed

or is there something more I can add to what I have?


End Edit:

Never mind

Using Chprop doesn't require the "P" in it. Removed it and all is fine.

Code - Auto/Visual Lisp: [Select]
  1. (if (tblsearch "LAYER" "FiberMgt_136") ;Check if the layer exists
  2.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  3.   (command "_chprop" fm136 "" "la" "FiberMgt_136" "" (command)(command))[i]Removed "P" here[/i]
  4. ) ;End if progn?
  5.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  6.   (command "._Layer" "Make" "FiberMgt_136" "_Color" "136" "" "" (command)(command))
  7.   (command "_chprop" fm136 "" "la" "FiberMgt_136" "" (command)(command))[i]Removed "P" here[/i]
  8. ) ;End if progn
  9. ) ;End of if
« Last Edit: November 16, 2018, 07:08:51 PM by jlogan02 »
J. Logan
ACAD 2018

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

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 1138
  • class keyThumper<T>:ILazy<T>
Re: If statement. Layer gets made but color won't set.
« Reply #2 on: November 16, 2018, 06:55:47 PM »
Does this work for you.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq OldLayerName "AAC"
  3.      NewLayerName "ABCD"
  4.      LayerColor   "136"
  5.      fm136   (ssget "_X" (list (cons 8 OldLayerName)))
  6. )
  7.  
  8. (if (not (= (atoi LayerColor)
  9.    (cdr (assoc 62 (tblsearch "LAYER" NewLayerName)))
  10. )
  11.    )
  12.  (command "._Layer" "_Make" NewLayerName "_Color" LayerColor "" "")
  13. )
  14. (if fm136
  15.  (command "_chprop" fm136 "" "_la" NewLayerName "")
  16. )
  17.  
called Kerry in my other life

Sometimes the question is more important than the answer.

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #3 on: November 19, 2018, 05:14:36 PM »
That worked find Kdub.

Using this code gets me the value of the tag "SUBJECTCODE" in the attribute "TBLK_ATT_CTL"

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (defun c:FOO (/ LM:GetAttributeValue ss attValue)
  4.  
  5.  (defun LM:GetAttributeValue (blk tag / val enx)
  6.    (while
  7.      (and
  8.        (null val)
  9.        (= "ATTRIB"
  10.           (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
  11.        )
  12.      )
  13.       (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
  14.         (setq val (cdr (assoc 1 enx)))
  15.       )
  16.    )
  17.  )
  18.  
  19.  (setq ss (ssget "x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1))))
  20.  (setq attValue (LM:GetAttributeValue (ssname ss 0) "SUBJECTCODE"))
  21.  
  22. (if (ATTRIBUTE TAG VALUE = 90????
  23.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  24.   (command "_chprop" fm136 "" "la" "FiberMgt_136" "" (command)(command))
  25. ) ;End if progn?
  26.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  27.   (command "._Layer" "Make" "FiberMgt_136" "_Color" "136" "" "" (command)(command))
  28.   (command "_chprop" fm136 "" "la" "FiberMgt_136" "" (command)(command))
  29. ) ;End if progn
  30. ) ;End of if  
  31.  (princ)
  32. )
  33. )

Here's where I'm not having any luck. Seems to me, once I verify the attribute value is "90" I should be able to..

(if (subject code is "90"...
do stuff...

If (subject code isn't "90"...
Don't do stuff..

but I'm stuck.

J. Logan
ACAD2018
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12112
  • London, England
Re: If statement. Layer gets made but color won't set.
« Reply #4 on: November 19, 2018, 05:38:09 PM »
Code: [Select]
(if (= attValue "90")
Or:

Code: [Select]
(if (= (atoi attValue) 90)

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 1138
  • class keyThumper<T>:ILazy<T>
Re: If statement. Layer gets made but color won't set.
« Reply #5 on: November 19, 2018, 05:42:10 PM »

and :
are you certain the value will represent an integer ??
called Kerry in my other life

Sometimes the question is more important than the answer.

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #6 on: November 19, 2018, 06:33:08 PM »
Lee, I swear to god I tried that!!! Going to try again.

And yes Kdub, it always will. Now it could represent many different integer's, but I'm looking specifically for "90".

J. Logan
ACAD 2018
J. Logan
ACAD 2018

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

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #7 on: November 19, 2018, 07:25:30 PM »
Works, but doesn't work...

It will do as expected but doesn't honor the (if (= attValue 90)
It skips that line of code.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:FOO (/ LM:GetAttributeValue ss attValue)
  3.  
  4.  (defun LM:GetAttributeValue (blk tag / val enx)
  5.    (while
  6.      (and
  7.        (null val)
  8.        (= "ATTRIB"
  9.           (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
  10.        )
  11.      )
  12.       (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
  13.         (setq val (cdr (assoc 1 enx)))
  14.       )
  15.    )
  16.  )
  17.  
  18.  (setq cl56 (ssget "x" '((62 . 56)(0 . "LINE,POLYLINE,LWPOLYLINE,TEXT,MTEXT"))))
  19.    (command "_chprop" cl56 "" "C" "136" "" (command)(command))
  20.  
  21.  (setq ss (ssget "x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1))))
  22.  (setq attValue (LM:GetAttributeValue (ssname ss 0) "SUBJECTCODE")) ?????DO I have this line right ????
  23.  
  24. (if (= attValue 90)
  25.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  26.   (command "._Layer" "Make" "FiberMgt_136" "_Color" "136" "FiberMgt_136" "" (command)(command))
  27.   (command "_chprop" fm136 "" "P" "LA" "FiberMgt_136" "" (command)(command))
  28. ) ;End if progn?
  29.   (setq fm136 (ssget "x" '((8 . "FiberMgt_56"))))
  30.   (command "._Layer" "Make" "FiberMgt_136" "_Color" "136" "FiberMgt_136" "" (command)(command))
  31.   (command "_chprop" fm136 "" "P" "LA" "FiberMgt_136" "" (command)(command))
  32. ) ;End if progn
  33. ) ;End of if  
  34.  (princ)
  35. )

Edit Below:

I also get this message from the <Build  Output> window when I "Check TEXT in Editor"

[CHECKING TEXT FM136.lsp loading...]
..
; warning: local variable used as function: LM:GETATTRIBUTEVALUE
; Check done.

J. Logan
ACAD 2018
« Last Edit: November 19, 2018, 07:29:24 PM by jlogan02 »
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12112
  • London, England
Re: If statement. Layer gets made but color won't set.
« Reply #8 on: November 20, 2018, 08:14:31 AM »
It will do as expected but doesn't honor the (if (= attValue 90)
It skips that line of code.

The variable attValue will always be a string (or nil), therefore the test should be either:

Code: [Select]
(= attValue "90")or:
Code: [Select]
(= (atoi attValue) 90)
Per my earlier response.

I also get this message from the <Build  Output> window when I "Check TEXT in Editor"

[CHECKING TEXT FM136.lsp loading...]
..
; warning: local variable used as function: LM:GETATTRIBUTEVALUE
; Check done.

This is only a warning and will not affect the code operation, but the warning appears because you have declared the LM:GetAttributeValue as a symbol local to c:FOO. You can safely remove LM:GetAttributeValue from the list of local variables, as there is no need for this function to be local unless you have another (different) definition of the same function in the document namespace (which I highly doubt).

i.e.:
Code: [Select]
(/ LM:GetAttributeValue ss attValue)
Can become:
Code: [Select]
(/ cl56 fm136 ss attValue)
(I've added your other variables)

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #9 on: November 20, 2018, 12:11:50 PM »
Thanks for the help Lee. I'm just too old for this shite.

I changed...

Code - Auto/Visual Lisp: [Select]
  1. (setq attValue (LM:GetAttributeValue (ssname ss 0) "SUBJECTCODE"))

to

Code - Auto/Visual Lisp: [Select]
  1. (setq attValue (LM:GetAttributeValue (ssname ss 0) "TITLELINE4"))

and went with...

Code - Auto/Visual Lisp: [Select]
  1. (if (= attValue "BUILDING EQUIPMENT PLAN")

all works fine. the TitleLine4 and SubjectCode tags are the same thing. One can't be different from the other. All works fine this way.

J. Logan
ACAD2018
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12112
  • London, England
Re: If statement. Layer gets made but color won't set.
« Reply #10 on: November 20, 2018, 12:26:19 PM »
Good stuff  :-)

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #11 on: November 21, 2018, 03:50:05 PM »
Damn!!! Discovered I need to add another attValue...

I needed to add Interior Elevations.

Code - Auto/Visual Lisp: [Select]
  1.    (setq attValue (LM:GetAttributeValue (ssname ss 0) "TITLELINE4"))
  2.  
  3.  (if (= attValue "EQUIPMENT PLAN")
  4.   (progn
  5.    (setq fm1 (ssget "x" '((8 . "FiberMgt_1"))))
  6.     (command "._Layer" "Make" "FiberMgt_56" "_Color" "56" "FiberMgt_56" "" (command)(command))
  7.     (command "_chprop" fm1 "" "P" "LA" "FiberMgt_56" "" (command)(command))
  8.    );End if progn  
   
So I added a second
Code - Auto/Visual Lisp: [Select]
Would that be the correct method? It seems to work. EDIT: No it doesn't

Code - Auto/Visual Lisp: [Select]
  1.      (= attValue "INTERIOR ELEVATIONS")
  2.      (setq fm1 (ssget "x" '((8 . "FiberMgt_1"))))
  3.     (command "._Layer" "Make" "FiberMgt_56" "_Color" "56" "FiberMgt_56" "" (command)(command))
  4.     (command "_chprop" fm1 "" "P" "LA" "FiberMgt_56" "" (command)(command))
  5.    ) ;End if progn
  6.   ) ;End of if

J. Logan
ACAD2018
« Last Edit: November 21, 2018, 04:01:40 PM by jlogan02 »
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12112
  • London, England
Re: If statement. Layer gets made but color won't set.
« Reply #12 on: November 21, 2018, 05:14:45 PM »
With multiple conditions, the cond function becomes more applicable, e.g.:
Code - Auto/Visual Lisp: [Select]
  1.    (   (= attValue "EQUIPMENT PLAN")
  2.        (setq fm1 (ssget "_x" '((8 . "FiberMgt_1"))))
  3.        ;; ... etc.
  4.    )
  5.    (   (= attValue "INTERIOR ELEVATIONS")
  6.        (setq fm1 (ssget "x" '((8 . "FiberMgt_1"))))
  7.        ;; ... etc.
  8.    )
  9. )

jlogan02

  • Newt
  • Posts: 62
Re: If statement. Layer gets made but color won't set.
« Reply #13 on: November 26, 2018, 03:05:07 PM »
Perfect. Thanks Lee.
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 #14 on: November 26, 2018, 04:01:07 PM »
Since it appears you are changing the same properties for both conditions you could use wcmatch as well:
Code - Auto/Visual Lisp: [Select]
  1. (cond ((wcmatch (strcase attvalue) "EQUIPMENT PLAN,INTERIOR ELEVATIONS")
  2.       (setq fm1 (ssget "x" '((8 . "FiberMgt_1"))))
  3.       (command "._Layer" "Make" "FiberMgt_56" "_Color" "56" "FiberMgt_56" "" (command) (command))
  4.       (command "_chprop" fm1 "" "P" "LA" "FiberMgt_56" "" (command) (command))
  5.      ) ;End if prog
  6. )

Windows 10 x64 - AutoCAD /C3D 2019

Custom Build PC