No objects exist in Selection Set - error: bad argument type: consp nil

No objects exist in Selection Set - error: bad argument type: consp nil

RDunkley
Advocate Advocate
1,741 Views
2 Replies
Message 1 of 3

No objects exist in Selection Set - error: bad argument type: consp nil

RDunkley
Advocate
Advocate

Hi,

 

I have a routine that I have been working on (cobbled together from various sources...) and have been getting this error "error: bad argument type: lselsetp nil" for the functions that have no objects in their selection set.

 

I am fairly new to lisp, what would be the best way to check if there are any objects in the selection set and if not end the function?

 

Regards.

Ross.

 

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Set elevations to 2 Decimal Places via Change in Point Label Style (EX_INVERT)
;---------------------------------
(vl-load-com)
(defun c:2DINV ( / Cpnt)

(SETQ CadApp (VLAX-GET-ACAD-OBJECT));Get AutoCAD Object
(setq C3dApp (vla-getinterfaceobject CadApp "AeccXUiLand.AeccApplication.11.0"));2017 C3D
(setq C3Ddoc (vla-get-activedocument C3dApp));Get Active Document
(setq ptlblstyles (vlax-get C3Ddoc 'pointlabelstyles));Get Point Styles
(setq style1 (vlax-get-property ptlblstyles 'item "ONK_(Elev) ONLY (INV) (2DP)"));get the Point Style
(mapcar 'vlax-release-object (list C3Ddoc C3dApp CadApp));release objects

;Select Points
(setq Slcsct (ssget "X" '((0 . "AECC_COGO_POINT")(8 . "EX_INVERT"))))

;Selection Length
(setq SlcLen (sslength Slcsct))

;Counter
(setq tn 0)

(repeat SlcLen
(setq tmpname (ssname Slcsct tn))
(setq Cpnt (vlax-ename->vla-object tmpname))
(vlax-put-property Cpnt 'LabelStyle style1 )
(setq tn ( + tn 1))
);repeat
);defun

(princ)

Currently using Civil 3D 2024 & AutoCAD 2025
0 Likes
Accepted solutions (1)
1,742 Views
2 Replies
Replies (2)
Message 2 of 3

Ranjit_Singh
Advisor
Advisor

I haven't tested but just localized the variables and added an if statement to check if the selection set has any objects. Give it a try

Spoiler
(vl-load-com)
(defun c:2DINV  (/ Cpnt CadApp C3dApp C3DDoc PTLBLSTYLES SLCLEN SLCSCT STYLE1 TMPNAME TN)
    (SETQ CadApp (VLAX-GET-ACAD-OBJECT))
    (setq C3dApp (vla-getinterfaceobject CadApp "AeccXUiLand.AeccApplication.11.0"))
    (setq C3Ddoc (vla-get-activedocument C3dApp))
    (setq ptlblstyles (vlax-get C3Ddoc 'pointlabelstyles))
    (setq style1 (vlax-get-property ptlblstyles 'item "ONK_(Elev) ONLY (INV) (2DP)"))
    (mapcar 'vlax-release-object (list C3Ddoc C3dApp CadApp))
    (setq Slcsct (ssget "X" '((0 . "AECC_COGO_POINT") (8 . "EX_INVERT"))))
    (if Slcsct
        (progn (setq SlcLen (sslength Slcsct))
               (setq tn 0)
               (repeat SlcLen
                   (setq tmpname (ssname Slcsct tn))
                   (setq Cpnt (vlax-ename->vla-object tmpname))
                   (vlax-put-property Cpnt 'LabelStyle style1)
                   (setq tn (+ tn 1)))))
    (princ))
0 Likes
Message 3 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

Your Subject line and description don't agree about what the error message is, but assuming it's really the latter [about the selection]....

 

Because (ssget) returns nil if nothing is found, try this:

....

;Select Points
(if (setq Slcsct (ssget "X" '((0 . "AECC_COGO_POINT")(8 . "EX_INVERT"))))

  (progn ; then

;Selection Length

    (setq SlcLen (sslength Slcsct))

;Counter
    (setq tn 0)

    (repeat SlcLen
      (setq tmpname (ssname Slcsct tn))
      (setq Cpnt (vlax-ename->vla-object tmpname))
      (vlax-put-property Cpnt 'LabelStyle style1 )
      (setq tn ( + tn 1))
    );repeat

  ); progn

); if

....

 

You can add an 'else' argument if you like, with a (prompt) or (alert) notifying the User that nothing qualifying was found.

Kent Cooper, AIA
0 Likes