Jump to content

error: bad argument type: lentityp nil


Elektrik

Recommended Posts

I do not know how to create lisp codes, but find a lisp code similar to what I had in my mind, but I used ChatGPT to enhance it the way I want it. I provided the lisp script that selects entities of a specified length from the entire drawing. I wanted the following enhancements:

1-Enable multi-selection: Allow the user to make multiple selections before running the script.

2-Filter by layer: Select only the entities that are on the same layer as the selected entities.

3-Match length: For each selected entity, select all entities of the same type and length from the same layer.

 

Now it gives me "bad argument type: lentityp nil lisp" error. Could anyone help me with this lisp? Thanks in advance.

 

The original code:

;;Create by Georgi Georgiev    - TRUDY
;;Date: 09.07.2020

(defun c:sel (/)
 (vl-load-com)
 (setq clear nil)
(setq sel1 (ssget ":S" '((0 . "LWPOLYLINE,line,circle"))))

(repeat (setq i (sslength sel1))
        (setq nam (ssname sel1 (setq i (1- i))))
        (setq ent (entget nam))
        (princ (cdr (assoc 0 ent)))
            (if (= (cdr (assoc 0 ent)) "CIRCLE")
                (setq rad (cdr (assoc 40 ent)))
                (setq len (vla-get-length (vlax-ename->vla-object nam)))
            )
)

(setq selall (ssget "X" (list (assoc 0 ent))))
(repeat (setq i (sslength selall))
            (setq namall (ssname selall (setq i (1- i))))
            (setq entall (entget namall))
                (if (= (cdr (assoc 0 ent)) "CIRCLE")
                    (setq radall (cdr (assoc 40 entall)))
                    (setq lenall (vla-get-length (vlax-ename->vla-object namall)))
                )
                (if (= (cdr (assoc 0 ent)) "CIRCLE")
                    (if (= rad radall) (setq clear (ssadd namall sel1)) (princ))
                    (if (= len lenall) (setq clear (ssadd namall sel1)) (princ))
                )
)
(sssetfirst nil clear)
(princ)
)

 

The lisp code provided by ChatGPT:

 

(defun c:mel (/ ss1 ss2 i j eName ent layerType rad len clear)
  (vl-load-com)

  ;; Kullanıcıya çoklu seçim yapma imkanı tanı
  (setq ss1 (ssget '((0 . "LWPOLYLINE,LINE,CIRCLE"))))

  ;; Boş seçim seti oluştur
  (setq clear (ssadd nil))

  ;; Tüm seçim setinde döngü
  (setq i 0)
  (while (< i (sslength ss1))
    (setq eName (ssname ss1 i))
    (setq ent (entget eName))
    (if ent
      (progn
        (setq layerType (cdr (assoc 8 ent))) ;; Layer tipi
        (cond
          ((= (cdr (assoc 0 ent)) "CIRCLE")
           (setq rad (cdr (assoc 40 ent)))
           ;; Tüm çizimde aynı yarıçapa ve layer'a sahip ögeleri seç
           (setq ss2 (ssget "X" (list (cons 0 "CIRCLE") (cons 40 rad) (cons 8 layerType))))
           (if ss2
             (progn
               (setq j 0)
               (while (< j (sslength ss2))
                 (setq clear (ssadd (ssname ss2 j) clear))
                 (setq j (1+ j))))))
          (T
           (setq len (vla-get-length (vlax-ename->vla-object eName)))
           ;; Tüm çizimde aynı uzunluğa ve layer'a sahip ögeleri seç
           (setq ss2 (ssget "X" (list (cons 0 (cdr (assoc 0 ent))) (cons 8 layerType))))
           (if ss2
             (progn
               (setq j 0)
               (while (< j (sslength ss2))
                 (setq ent2 (entget (ssname ss2 j)))
                 (if (and ent2 (= len (vla-get-length (vlax-ename->vla-object (ssname ss2 j)))))
                   (setq clear (ssadd (ssname ss2 j) clear)))
                 (setq j (1+ j))))))))
      (princ "\nHatalı varlık algılandı."))
    (setq i (1+ i)))

  ;; Seçilen ögeleri vurgula
  (sssetfirst nil clear)
  (princ)
)


 

 

 

Edited by SLW210
Added Code Tags!!
Link to comment
Share on other sites

Please see https://lee-mac.com/errormessages.html

 

Quote

bad argument type: lentityp <value>

 

A function requiring an entity argument has been passed an argument of incorrect data type with the value noted in the error message. Usually a result of passing the entget function a null entity argument.

 

  • Agree 1
Link to comment
Share on other sites

1st answer is that ChatGP is very unreliable so many times code is totally rewritten.

 

2nd "selects entities of a specified length from the entire drawing" length is not a searchable property must get object 1st then can get Length property.

 

You dont say what you want to do with answer so just made a list of lengths.

 

(defun c:wow ( / ss len)

(setq ent (entsel "\nPick a object for layer "))
(setq lay (cdr (assoc 8 (entget (car ent)))))
(setq ss (ssget (list (cons 0 "LWPOLYLINE,line,circle,Arc")(cons 8 Lay))))

(if (= ss nil)
(progn (alert "You have not selected any correct objects \nWill now exit")(exit))
)
(setq lst '())
(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq objname (vlax-get obj 'objectname))

  (cond
   ((= objname "AcDbArc")(setq len (vlax-get obj 'Arclength)))
   ((= objname "AcDbLine")(setq len (vlax-get obj 'length)))
   ((= objname "AcDbCircle")(setq len (vlax-get obj 'Circumference)))
   ((= objname "AcDbPolyline")(setq len (vlax-get obj 'length)))
  )

  (setq lst (cons len lst))
)

(princ)
)

 

 

 

 

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...