Display full version of the post: LISP Error

kameron1967
21.02.2011, 22:11
Hi.  Someone helped me with this, but I'm not able to get it to run. It has a syntax error.
[CODE]
(defun C:NEWL ();R-1(vl-load-com);R-1(setq PickItem (car (entsel "\nPick object for new layer: ")));R-1(setq ObjLayer (cdr (assoc 8 (entget pickItem))));R-1(setq ObjType (cdr (assoc 0 (entget pickItem))));R-1(princ (strcat ObjLayer is layer name of " ObjType " selected"));R-1(initget "N D V");R-1(Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1);R-0

HAWDesigner
21.02.2011, 23:27


The initial error I got was "ERROR: malformed string on input".By changing Line7 to the following, it cleared that error, but every time I enter a suffix type, I now get the error: "Invalid Option Keyword"[CODE](princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1[/CODE]NOTE: You were missing a " (quote) between ObjLayer and is.


HAWDesigner2011-02-21 23:29:02

kameron1967
22.02.2011, 01:43
Thanks.  So if I wanted to create a new layer based on the entity that I selected (for instance a line on H-ROOM layer), how would I attach the modifier to that entity so that if I choose D for suffix, it will automatically create a new layer based on the entity so that the new layer would look like this: H-ROOM-D-PKG1?  Thanks.
 
(Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"))
 
Would it be something like this..?
 
      (setq oLayers
      (vla-get-layers        (vla-get-activedocument   (vlax-get-acad-object))))
(if (not (tblsearch "LAYER" objlayer))       (progn 
         (setq LyrNew (vla-add oLayers LYR)        LyrTab (vla-item oLayers sLYR)        )  (vla-put-linetype LyrNew (vla-get-linetype LyrTab))  (vla-put-truecolor LyrNew (vla-get-truecolor LyrTab))  (vla-put-truecolor LyrNew (vla-get-truecolor LyrTab))  (vla-put-freeze LyrNew (vla-get-freeze LyrTab))  (vla-put-layeron LyrNew (vla-get-layeron LyrTab))  (vla-put-lineweight LyrNew (vla-get-lineweight LyrTab))  (vla-put-lock LyrNew (vla-get-lock LyrTab))  (vla-put-material LyrNew (vla-get-material LyrTab))  ;(vla-put-plotstylename LyrNew (vla-get-plotstylename LyrTab))  ))
(setq ent (car(entsel)))(setq nlayer(cdr (assoc 8 (entget ent))))
(setq LyrNew (strcat LYR lyrsuffix))kameron19672011-02-22 01:50:53

HAWDesigner
22.02.2011, 14:00
I'm not an expert on LISP yet, sorry. Finding syntax errors is about as far as my LISP abilities go. Perhaps CarlB can lend you a hand on this.Good Luck!!

Vladimir Michl
22.02.2011, 14:58
Yes, this is one of the ways how to do it. This LISP code seems to be mixed from several sources - the names of layer variables are mixed: objlayer, LYR, nlayer.
 
Assumes e.g. that objlayer is already filled with the old layer name.

kameron1967
22.02.2011, 18:00
yes, you're right.  It was taken from various source.  I need to somehow tie them all in so that whatever letter I choose, it appends the right suffix to the new layer that it will be creating.
If anyone has a shortcut to creating a simple layer modifer, I'd love to see it.  Basically, if N is chosen, it will add the -N-PKG1 in the new layer based on the entity selected.  Thanks.

CarlB
23.02.2011, 02:06
OK since my name was mentioned..here's my take at a simple lisp..
 
[code]
(defun C:NEWL ();R-1   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1   (setq ObjLayer (cdr (assoc 8 (entget pickItem))));R-1   (setq ObjType (cdr (assoc 0 (entget pickItem))));R-1   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1   (initget "N D V");R-1   (Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1   (setq NewLyrName      (cond          ((= LyrSuffix "N") (strcat ObjLayer "-N-PKG-1" ))         ((= LyrSuffix "D") (strcat ObjLayer "-D-PKG-1"))         ((= LyrSuffix "V") (strcat ObjLayer "-V-PKG-1"))       )    )    (command "._Layer" "_M" NewLyrname "")   (princ))[/code]

kameron1967
23.02.2011, 02:24
Thanks, CarlB.  You're a savior!

HAWDesigner
23.02.2011, 15:26

Nice Carl, thanks for that. I hope I didn't throw you under the bus there. Here's something I noticed in v2009:
[CODE](Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1[/CODE]The code above results in an error if you select the value from the Drafting ToolTips.

... because it is entering the entire value instead of just the N, D, or V as the "(initget "N D V");R-1" requests.In order to prevent that error, I had to change the line to the following, but I know that doesn't fully explain what's going on.
[CODE](Setq LyrSuffix (getkword "\nEnter suffix type [N/D/V]:"));R-1

[/CODE]Is there any way to have it both ways?
HAWDesigner2011-02-23 15:27:08

kameron1967
23.02.2011, 17:48
CarlB - is there a way to make it so that the newly created layer of the entity that we selected retains that same layer information as the one entity that we selected?  As of right now, it creates a new layer, but with default color and linetype.  If we can specify the linetype and color associated to each modifier, that would work also.  Thanks.
 
[QUOTE=CarlB]OK since my name was mentioned..here's my take at a simple lisp..
 
[code]
(defun C:NEWL ();R-1   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1   (setq ObjLayer (cdr (assoc 8 (entget pickItem))));R-1   (setq ObjType (cdr (assoc 0 (entget pickItem))));R-1   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1   (initget "N D V");R-1   (Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1   (setq NewLyrName      (cond          ((= LyrSuffix "N") (strcat ObjLayer "-N-PKG-1" ))         ((= LyrSuffix "D") (strcat ObjLayer "-D-PKG-1"))         ((= LyrSuffix "V") (strcat ObjLayer "-V-PKG-1"))       )    )    (command "._Layer" "_M" NewLyrname "")   (princ))[/code][/QUOTE]

CarlB
23.02.2011, 19:50
Revised to take on layer color & linetype. no checking for locked status, etc.  Enjoy!
 
[code](defun C:NEWL ();R-1, R-2 to reproduce layer settings 2/23/11   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1   (setq Entdata (entget pickItem))   (setq ObjLayer (cdr (assoc 8 EntData)));R-1   (setq ObjType (cdr (assoc 0 EntData)));R-1   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1   (setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2   (setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2   (setq LyrColor (cdr (assoc 62 Lyrdata)));R-2   (initget "N D V");R-1   (Setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1]:"));R-1   (setq NewLyrName      (cond        ((= LyrSuffix "N") (strcat ObjLayer "-N-PKG-1" ))         ((= LyrSuffix "D") (strcat ObjLayer "-D-PKG-1"))        ((= LyrSuffix "V") (strcat ObjLayer "-V-PKG-1"))      )   )   (command "._Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "" "");R-2   (princ))[/code]

kameron1967
28.02.2011, 19:06
CarlB,
 
Sorry to keep bothering you.  But if I wanted to also include lineweight, but have the ability to modify each aspect of the layer color, linetype and lineweight within the selected suffix - for instance D, can I specify the layer information within the parenthesis?  See below.  Thanks.
 
        ((= LyrSuffix "A")
(setq LyrLtype "sphantom")(setq LyrColor "1");(setq LyrLw "0.25") - what's the variable for lineweight?
(strcat ObjLayer "-A-D1C1270" ))
 
  kameron19672011-02-28 20:13:51

CarlB
28.02.2011, 20:02
Well the 'cond' was a subfunction of a 'setq layer' so you should rearrange like below to add more 'setqs' to the cond:
 


(cond
  ((= LyrSuffix "A")
     (setq xxxlayer (strcat ObjLayer "-A-D1C1270" ))
    (setq lyrcolor "1")
   (setq lyrltype "continuous")   (setq lyrweight "0.25"));R-3
 
-or shorter versio-
 

(cond
  ((= LyrSuffix "A")
     (setq xxxlayer (strcat ObjLayer "-A-D1C1270" )
    lyrcolor "1"
    lyrltype "continuous"   lyrweight "0.25");R-3
 

kameron1967
28.02.2011, 20:34
Thanks, CarlB.  I was trying so hard to find the LYRweight variable.  I tried LYRLW, LYRLWEIGHT, but couldn't get it to work.  I kind of makes sense for the variable to be called LYRweight, but I would never have guessed it.  Once again, you're my savior!
 
One last question:  What is the lyrweight number?  I never know where to find this info (see below).  Thanks.
 
(setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2   (setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2   (setq LyrColor (cdr (assoc 62 Lyrdata)));R-2  
(setq Lyrweight (cdr (assoc ?? Lyrdata)));R-2  
 
kameron19672011-02-28 21:02:09

CarlB
28.02.2011, 21:03
I think we have more to work out...
I had thought you were just assigning a lineweight to a layer with this code, so the variable name could be whatever you want to call it, then that same variable name would be used later in the command to define the new layer:
(command ".-layer" etc.... "_LW" lyrweight etc...)
 
It you want to assign the same layer weight as object layer selected, will need some other steps...

kameron1967
28.02.2011, 21:07
CarlB - there are some layers that require different lineweight to be defined, where the rest uses whatever was assigned in the original layer.  I thought if I just set the variable for the lineweight on the layer table, it will default to that, unless I specified it as shown below:
 
 
(setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2   (setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2   (setq LyrColor (cdr (assoc 62 Lyrdata)));R-2   (setq Lyrweight (cdr (assoc 370 Lyrdata)));R-2   (LINEWEIGHT)
 
        ((= LyrSuffix "X")(setq LyrLtype "sphantom")(setq LyrColor "8")(setq Lyrweight "0.13") (strcat ObjLayer "-X-D1C1270" ));R-3
       );R-2
    );R-1
(command "-Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "_lw" Lyrweight "" "");R-2   ADDED LINEWEIGHT HERE AS WELLkameron19672011-03-01 00:23:21

CarlB
01.03.2011, 07:44
Your idea is sound, extracting default data, overriding it later if desired. Since i don't have AutoCADd to check, not sure the 370 code & tblsearch will give you lineweight, or if so will be the correct format to feed back to the "layer" command. You can give me an update on that :)
 
[code](defun C:NEWL ();R-1, R-2 to reproduce layer settings 2/23/11   (setq PickItem (car (entsel "\nPick object for new layer: ")));R-1   (setq Entdata (entget pickItem))   (setq ObjLayer (cdr (assoc 8 EntData)));R-1   (setq ObjType (cdr (assoc 0 EntData)));R-1   (princ (strcat ObjLayer " is layer name of " ObjType " selected"));R-1   (setq Lyrdata (tblsearch "LAYER" ObjLayer));R-2   (setq LyrLtype (cdr (assoc 6 Lyrdata)));R-2   (setq LyrColor (cdr (assoc 62 Lyrdata)));R-2   (setq LyrWeight (cdr (assoc 370 Lyrdata)));;R-3   (initget "N D V X");R-1   (setq LyrSuffix (getkword "\nEnter suffix type [N-PKG-1/D-PKG1/V-PKG-1/X-PKG-1]:"));R-1   (cond       ((= LyrSuffix "N")            (setq NewLyrName (strcat ObjLayer "-N-PKG-1"))        )       ((= LyrSuffix "D")              (setq NewLyrName (strcat ObjLayer "-D-PKG-1"))        )       ((= LyrSuffix "V")              (setq NewLyrName (strcat ObjLayer "-V-PKG-1"))        )       ((= LyrSuffix "X");;R-3              (setq NewLyrName (strcat ObjLayer "-X-PKG-1"))              (setq LyrLtype "PHANTOM")              (setq LyrColor "8")              (setq LyrWeight "0.13")                       )   )   (command "._Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "_LW" LyrWeight "" "");R-2&3   (princ))[/code]CarlB2011-03-01 07:44:47

kameron1967
01.03.2011, 22:04
CarlB,
 
This is the solution.  In addition to the code shown below, the lineweight needs to be 13 instead of 0.13.
 
Thanks though for your valuable help.  I really appreciate your help in this.
 
[code]
 
(setqLyrEdata (entget (tblobjname "Layer" ObjLayer))LyrWeight (cdr (assoc 370 LyrEdata)))((= LyrSuffix "X") (setq NewLyrName (strcat ObjLayer "-X-PKG-1")) (setq LyrLtype "PHANTOM") (setq LyrColor "8") (setq LyrWeight 53)) )
(command "-Layer" "_M" NewLyrname "_C" LyrColor "" "_L" LyrLtype "" "LW" (if (= LyrWeight -3) "D" (/ LyrWeight 100.0)) "" "")(princ))(princ "\n<!> Type {LAX} and choose your layer modifier <!>")