Insert Layers - getting error: malformed string on input

Insert Layers - getting error: malformed string on input

RedMan77
Collaborator Collaborator
1,224 Views
9 Replies
Message 1 of 10

Insert Layers - getting error: malformed string on input

RedMan77
Collaborator
Collaborator

MAKE STANDARD LAYERS BASED LAYER NAMES WITH OBJECT LINE WEIGHTS
(DEFUN C:NCE (/ CME LYR RGM)
(SETQ CME (GETVAR "CMDECHO")
LYR (GETVAR "C_LAYER")
RGM (GETVAR "REGENMODE"))
(SETVAR "CMDECHO" 0)
(SETVAR "REGENMODE" 0)

;;*-----------------------------------------------------------------------------------------*
;;;;GENERAL _LAYERS
(COMMAND "_CLAYER" "MAKE" "G-ANNO-TEXT" "COLOR" "2" "" "LW" "0.35" ""
"MAKE" "G-ANNO-TEXT-D" "COLOR" "2" "" "LW" "0.35" ""
"MAKE" "G-ANNO-TEXT-N" "COLOR" "2" "" "LW" "0.35" ""

;;*-----------------------------------------------------------------------------------------*
;;;;ELECTRICAL _LAYERS
(COMMAND "_CLAYER"
"MAKE" "E-POWR-EQPM" "COLOR" "21" "" "" "" "
"MAKE" "E-POWR-EQPM-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-EQPM-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-POWR-DEVC" "COLOR" "21" "" "" "" ""
"MAKE" "E-POWR-DEVC-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-DEVC-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-POWR-WIRE" "COLOR" "21" "" "" "" ""
"MAKE" "E-POWR-WIRE-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-WIRE-N" "COLOR" "3" "" "" "" "" "" "" ""
"MAKE" "E-LITE-DEVC" "COLOR" "21" "" "" "" ""
"MAKE" "E-LITE-DEVC-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-DEVC-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-LITE-EQPM" "COLOR" "21" "" "" "" ""
"MAKE" "E-LITE-EQPM-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-EQPM-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-COMM-DEVC" "COLOR" "8" "" "" "" ""
"MAKE" "E-COMM-DEVC-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-COMM-DEVC-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-COMM-EQPM" "COLOR" "8" "" "" "" ""
"MAKE" "E-COMM-EQPM-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-COMM-EQPM-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-LITE-DEVC" "COLOR" "8" "" "" "" ""
"MAKE" "E-LITE-DEVC-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-DEVC-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-FIRE-EQPM" "COLOR" "8" "" "" "" ""
"MAKE" "E-FIRE-EQPM-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-FIRE-EQPM-N" "COLOR" "14" "" "" "" "" "" "" ""
"MAKE" "E-FIRE-DEVC" "COLOR" "8" "" "" "" ""
"MAKE" "E-FIRE-DEVC-D" "COLOR" "5" "" "" "" "" "LT" "HIDDEN2" ""
"MAKE" "E-FIRE-DEVC-N" "COLOR" "14" "" "" "" "" "" "" "" "")


;;*-----------------------------------------------------------------------------------------*
(SETVAR "CMDECHO" CME
"C_LAYER" LYR
"REGENMODE" RGM) 

 

(PRINC))

 

--------------------------------------

 

I am using Vlisp which is a new thing for me.  I solved one issue only to create several more. Need a bit of help please.  If you notice the issue is with E-powr-eqpm (see attachment below).  Not sure what I am doing wrong.  If there is a more efficient way of inserting layers via lisp please let me know.  Thanks in advance.

 

Rob

 


cap2.JPG

0 Likes
Accepted solutions (1)
1,225 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Looks to me like using the System Variable name instead of the command name, and way too many Enters [""], which end Layer commands and recall them and end them again.  In the Electrical area, try:

....

(COMMAND "_.LAYER"
  "MAKE" "E-POWR-EQPM" "COLOR" "21" ""
  "MAKE" "E-POWR-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
  "MAKE" "E-POWR-EQPM-N" "COLOR" "14" ""
  "MAKE" "E-POWR-DEVC" "COLOR" "21" ""
  "MAKE" "E-POWR-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""

.... etc.

 

[Do some manually and you'll see how many Enters are needed -- in this case, one after each color or linetype designation to accept the current Layer, created and set by the Make option, as the default one to which to assign the color/linetype.]

 

In the General area, you don't have all those extraneous Enters, but you need to use the right command name, and at the end of that part you need an additional Enter to finish the Layer command and right parenthesis to finish the (command) function.

 

And where you do need the System Variable name [in setting and using the LYR variable], it's CLAYER, not C_LAYER.

Kent Cooper, AIA
Message 3 of 10

hmsilva
Mentor
Mentor

Hi Rob,

in addition to Kent1Cooper's advices, the 'setvar' function, only expects one argument, the system variable value...

The
(SETVAR "CMDECHO" CME
        "CLAYER" LYR
        "REGENMODE" RGM)
will error.

Or you use

(SETVAR "CMDECHO" CME)
(SETVAR "CLAYER" LYR)
(SETVAR "REGENMODE" RGM)

or you may use something like this

(vl-every 'setvar '("CMDECHO" "CLAYER" "REGENMODE") (list CME LYR RGM))

 

Hope this helps,
Henrique

 

 

EESignature

Message 4 of 10

RedMan77
Collaborator
Collaborator

Thanks guys.  I made several mistakes that seem to just cascade.  At first the routine worked, BUT it would bog the system down and as each layer was added (which is what I wanted in theory) it would say unknown command at the command line.  Realized it was very inefficient.  It was as the make layer command was being doen one by one.  

 

First I edited the routine with the text editor and was making all kinds of syntax mistakes.  The C_Layer was a typo.  Once I went to the VLISP editor I saw what the errors were but was unsure how to correct them.  I was trying to figure out how I could just enter the system variable once instead of multiple times but I didn't know how to string them together.  Here is the funny part is I should have walked through the create layer command and figured out how many enters were needed but I copied from an existing routine.  Mistake.  Wont edit a routine in the text editor again but only in VLISP.

 

What I dont get is if I type a " after "_.Layer all my "MAKE" "E....  turn pink.  Whats happening in the VLISP when adding a " to the end of "MAKE" "E-POWR-EQPM" "COLOR" "21" "" gooes from pink to black?.

 

Hmsilva

As far as the Setvar is it not needed to include the 0 for cmdecho and regenmode?  Is the code you included for the begining, end or both of the routine?

 

I am getting this when I check the code in VLISP

 

; === Top statistic:
; Function definition (with number of arguments): ((C:NCE . 0))
; Check done.

 

Here is the code in its entirety.  Not getting the malformed error anymore.

 

;;;;;MAKE STANDARD LAYERS

(DEFUN C:NCE (/ CME LYR RGM)
(SETQ CME (GETVAR "CMDECHO"))
(SETQ LYR (GETVAR "CLAYER"))
(SETQ RGM (GETVAR "REGENMODE"))
(SETVAR "CMDECHO" 0)
(SETVAR "REGENMODE" 0)

;;*-----------------------------------------------------------------------------------------*
;;;;ELECTRICAL LAYERS
(COMMAND "_.layer"

"MAKE" "E-POWR-EQPM" "COLOR" "21" ""
"MAKE" "E-POWR-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-EQPM-N" "COLOR" "14" ""
"MAKE" "E-POWR-DEVC" "COLOR" "21" ""
"MAKE" "E-POWR-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-DEVC-N" "COLOR" "14" ""
"MAKE" "E-POWR-WIRE" "COLOR" "21" ""
"MAKE" "E-POWR-WIRE-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-WIRE-N" "COLOR" "3" ""
"MAKE" "E-LITE-DEVC" "COLOR" "21" ""
"MAKE" "E-LITE-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-DEVC-N" "COLOR" "14" ""
"MAKE" "E-LITE-EQPM" "COLOR" "21" ""
"MAKE" "E-LITE-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-EQPM-N" "COLOR" "14" ""
"MAKE" "E-COMM-DEVC" "COLOR" "8" ""
"MAKE" "E-COMM-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-COMM-DEVC-N" "COLOR" "14" ""
"MAKE" "E-COMM-EQPM" "COLOR" "8" ""
"MAKE" "E-COMM-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-COMM-EQPM-N" "COLOR" "14" ""
"MAKE" "E-LITE-DEVC" "COLOR" "8" ""
"MAKE" "E-LITE-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-DEVC-N" "COLOR" "14" ""
"MAKE" "E-FIRE-EQPM" "COLOR" "8" ""
"MAKE" "E-FIRE-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-FIRE-EQPM-N" "COLOR" "14" ""
"MAKE" "E-FIRE-DEVC" "COLOR" "8" ""
"MAKE" "E-FIRE-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-FIRE-DEVC-N" "COLOR" "14" "")


;;*-----------------------------------------------------------------------------------------*
(SETVAR "CMDECHO" CME)
(SETVAR "CLAYER" LYR)
(SETVAR "REGENMODE" RGM)
(PRINC)
)

 

0 Likes
Message 5 of 10

RedMan77
Collaborator
Collaborator

When I execute the command now I get this (see below).  Its waiting for input instead of finishing it for me.  I really appreciate your help.

 

 

 

cap3.JPG

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 6 of 10

hmsilva
Mentor
Mentor
Accepted solution

Rob,

my advice was just for the 'System Variables' restore statment...

 

Your code needs an extra 'enter' to ends the "_.layer" command...

 

;;;;;MAKE STANDARD LAYERS

(DEFUN C:NCE (/ CME LYR RGM)
(SETQ CME (GETVAR "CMDECHO")
      LYR (GETVAR "CLAYER")
      RGM (GETVAR "REGENMODE")
)
(SETVAR "CMDECHO" 0)
(SETVAR "REGENMODE" 0)

;;*-----------------------------------------------?------------------------------------------*
;;;;ELECTRICAL LAYERS
(COMMAND "_.layer"

"MAKE" "E-POWR-EQPM" "COLOR" "21" ""
"MAKE" "E-POWR-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-EQPM-N" "COLOR" "14" ""
"MAKE" "E-POWR-DEVC" "COLOR" "21" ""
"MAKE" "E-POWR-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-DEVC-N" "COLOR" "14" ""
"MAKE" "E-POWR-WIRE" "COLOR" "21" ""
"MAKE" "E-POWR-WIRE-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-POWR-WIRE-N" "COLOR" "3" ""
"MAKE" "E-LITE-DEVC" "COLOR" "21" ""
"MAKE" "E-LITE-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-DEVC-N" "COLOR" "14" ""
"MAKE" "E-LITE-EQPM" "COLOR" "21" ""
"MAKE" "E-LITE-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-EQPM-N" "COLOR" "14" ""
"MAKE" "E-COMM-DEVC" "COLOR" "8" ""
"MAKE" "E-COMM-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-COMM-DEVC-N" "COLOR" "14" ""
"MAKE" "E-COMM-EQPM" "COLOR" "8" ""
"MAKE" "E-COMM-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-COMM-EQPM-N" "COLOR" "14" ""
"MAKE" "E-LITE-DEVC" "COLOR" "8" ""
"MAKE" "E-LITE-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-LITE-DEVC-N" "COLOR" "14" ""
"MAKE" "E-FIRE-EQPM" "COLOR" "8" ""
"MAKE" "E-FIRE-EQPM-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-FIRE-EQPM-N" "COLOR" "14" ""
"MAKE" "E-FIRE-DEVC" "COLOR" "8" ""
"MAKE" "E-FIRE-DEVC-D" "COLOR" "5" "" "LT" "HIDDEN2" ""
"MAKE" "E-FIRE-DEVC-N" "COLOR" "14" "" "")


;;*-----------------------------------------------?------------------------------------------*
(SETVAR "CMDECHO" CME)
(SETVAR "CLAYER" LYR)
(SETVAR "REGENMODE" RGM)
(PRINC)
)

 

Hope this helps,
Henrique 

EESignature

Message 7 of 10

RedMan77
Collaborator
Collaborator

Wow. It works! That was way faster than my first run of the routine.  Sorry to be a bother but can I ask just a few more questions.

 

1) What is happening after adding a " and part of the code is changing from pink to black in the VLISP editor?

 

2)  Is this the common method to string together setq?

(SETQ CME (GETVAR "CMDECHO")
      LYR (GETVAR "CLAYER")
      RGM (GETVAR "REGENMODE")

3) What is meant by the restore statement.  

 

Thanks for your help.  And Kent too!

0 Likes
Message 8 of 10

hmsilva
Mentor
Mentor

@RedMan77 wrote:

1) What is happening after adding a " and part of the code is changing from pink to black in the VLISP editor?


A string is a group of characters surrounded by quotation marks

when a string is not 'closed' with a quotation mark, AutoCAD evaluates the characters not as a string, but as different types...

 


@RedMan77 wrote:

2)  Is this the common method to string together setq?

(SETQ CME (GETVAR "CMDECHO")
      LYR (GETVAR "CLAYER")
      RGM (GETVAR "REGENMODE")

 


Yes, sets multiple variables inside a 'setq' function, should be faster than set one variable in each 'setq' function.

 


RedMan77 wrote:

3) What is meant by the restore statement.  


You did store the original values from 'CMDECHO', 'CLAYER' and 'REGENMODE' with

(SETQ CME (GETVAR "CMDECHO")
      LYR (GETVAR "CLAYER")
      RGM (GETVAR "REGENMODE")
)

you did set the new 'CMDECHO', 'CLAYER' and 'REGENMODE' values, with

(SETVAR "CMDECHO" 0)
(SETVAR "REGENMODE" 0)
;; and
(COMMAND "_.layer" "MAKE" ...

So, what I meant by 'restore statement' was the System Variables restore to the original values...

(SETVAR "CMDECHO" CME)
(SETVAR "CLAYER" LYR)
(SETVAR "REGENMODE" RGM)

@RedMan77 wrote:

Thanks for your help. 


You're welcome, RedMan77
Glad I could help

Henrique

 

 

EESignature

Message 9 of 10

RedMan77
Collaborator
Collaborator

That is absolutely awesome!  Alot of stuff just clicked!  Thank you very much for taking the time to not only solve the issue but explain some of the process.

0 Likes
Message 10 of 10

hmsilva
Mentor
Mentor

@RedMan77 wrote:

That is absolutely awesome!  Alot of stuff just clicked!  Thank you very much for taking the time to not only solve the issue but explain some of the process.


You're welcome, RedMan77
Glad it's useful for you!

 

Henrique

EESignature

0 Likes