malformed list on input

malformed list on input

jaimuthu
Advocate Advocate
910 Views
3 Replies
Message 1 of 4

malformed list on input

jaimuthu
Advocate
Advocate
(defun C:lM (/ searchString basept ss n totalTextEntities)
  ; Set the search string to "muthu"
  (setq searchString "muthu")

  ; Prompt the user to enter the base point
  (setq basept (getpoint "\nEnter base point for marking Lines: "))

  ; Initialize a variable to count the total number of text entities found
  (setq totalTextEntities 0)

  ; Iterate through the layers in the active document
  (vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    ; Check if the layer name matches the search string using wildcards
    (if (wcmatch (vla-get-name lay) (strcat "*" searchString))
      (progn
        ; Get the selection set of text entities on the current layer
        (if (setq ss (ssget "_X" (list (cons 8 (vla-get-name lay)))))
          (progn
            ; Process each text entity found on the current layer
            (setq n (sslength ss))
            (repeat n
              (entmake
                (list
                  '(0 . "LINE")
                  (cons 10 basept)
                  (cons 11 (cdr (assoc 10 (entget (ssname ss (setq n (1- n))))))
                )
              )
            )
            ; Increment the total count of text entities found
            (setq totalTextEntities (+ totalTextEntities (sslength ss)))
          )
        )
      )
    )
  )

  ; Display the total count of text entities found
  (alert (strcat "Total text entities found: " (itoa totalTextEntities)))

  (princ)
)

.i want serach layer name contain muthu string  count and find  mark  with line error is malformed list on input

how to solve this problem

 

 

 

0 Likes
Accepted solutions (1)
911 Views
3 Replies
Replies (3)
Message 2 of 4

martti.halminen
Collaborator
Collaborator

The typical reason for "malformed list..." errors is mismatched or missing parentheses.

 

The first tool you need for serious programming in any language is an editor which immediately shows the corresponding opening parenthesis when you type the closing parenthesis.

 

Working with Lisp is much easier if your editor also knows how to indent your program based on its structure. Professionals read the program structure by the indentation, the parentheses are for the compiler.

 

In the mainstream Lisp culture (Common Lisp, nowadays) most programmers use some variant of Emacs.

 

Here is how GNU Emacs would indent your program:

 

(defun C:lM (/ searchString basept ss n totalTextEntities)
  (setq searchString "muthu")
  (setq basept (getpoint "\nEnter base point for marking Lines: "))
  (setq totalTextEntities 0)
  (vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
            (if (wcmatch (vla-get-name lay) (strcat "*" searchString))
                (progn
                  (if (setq ss (ssget "_X" (list (cons 8 (vla-get-name lay)))))
                      (progn
                        (setq n (sslength ss))
                        (repeat n
                                (entmake
                                 (list
                                  '(0 . "LINE")
                                  (cons 10 basept)
                                  (cons 11 (cdr (assoc 10 (entget (ssname ss (setq n (1- n)))))))))
                                (setq totalTextEntities (+ totalTextEntities (sslength ss))))))))
            (alert (strcat "Total text entities found: " (itoa totalTextEntities)))
            (princ))

- Your comments were superfluous: don't comment things any programmer can directly read in the program text, comment the things that are not shown: where did some outside data come from, what is the reason for some odd

program detail, what is the document detailing the requirement some detail implements.

 

Here the indentation shows something odd: did you really intend to write a separate report for found entities for every layer? Or was that intended to be outside the VLAX-FOR loop?

 

 

0 Likes
Message 3 of 4

calderg1000
Mentor
Mentor
Accepted solution

Regards @jaimuthu 

You just needed to complete a parenthesis. And a slight correction for the text counter on the layer.

(defun C:lM (/ searchString basept ss n totalTextEntities)
  (setq searchString "muthu")
  (setq basept (getpoint "\nEnter base point for marking Lines: "))
  (setq totalTextEntities 0)
  (vlax-for lay
            (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (wcmatch (vla-get-name lay) (strcat "*" searchString))
      (progn
        (if (setq ss (ssget "_X" (list (cons 8 (vla-get-name lay)))))
          (progn
            (setq n (sslength ss))
            (repeat n
              (entmake
                (list
                  '(0 . "LINE")
                  (cons 10 basept)
                  (cons 11
                        (cdr (assoc 10 (entget (ssname ss (setq n (1- n))))))
                  )
                )
              )
;;;              (setq totalTextEntities (+ totalTextEntities (sslength ss)))
            )
          )
        )
      )
    )
  )
  (setq totalTextEntities (+ totalTextEntities (sslength ss)))
  (alert (strcat "Total text entities found: " (itoa totalTextEntities)))
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

Notepad++ is free and has bracket checking built in.

0 Likes