Jump to content

looping through list?


Dustin11

Recommended Posts

I have this rough draft code I'm building to be used as a layer checker but I also need to to loop through once using the first item in the list, then loop through a second time using the second item on the list, then a third, fouth, etc..... but I can't seem figure out a way to make it do that. I'm also pretty sure that where I have the "repeat" function is incorrect because after I added it the code stopped working, but I haven't tried messing around with that to get it working again.

 

 
(defun c:mscheck (/ sys ss count msg)
 (setq sys (list "H-LOWP"))
 (setq sys (append sys '("H-LOWP-EXST" "H-MEDP" "H-MEDP-EXST" "H-EXHS" "H-EXHS-EXST" "H-GRDS" "H-GRDS-EXST" "H-RTRN" "H-RTRN-EXST" "G-GENL-TEXT" "G-GENL-TEXT-EXST" "G-EQPM" "G-EQPM-EXST" "H-STAT" "H-STAT-EXST" "H-OAIR" "H-OAIR-EXST")))
 (setq count (length sys))
 (repeat count  
 (if (tblsearch "layer" sys)foreach
   (progn
     (setq ss (ssget "_X" (list (cons 8 sys))))
     (if (= ss nil)
(progn
  (setq count "0")
  );progn
(progn
  (setq count (sslength (ssget "_P")))
  );progn
);if
     );progn
   (progn
     (setq count "DNE") 
     );progn
   );if
 (setq msg (cons sys count))
 (print msg)
 (princ)
   );repeat
 );defun

Link to comment
Share on other sites

(defun c:FOO (/ ss)
 (foreach layerName '("H-LOWP" "H-LOWP-EXST" "H-MEDP" "H-MEDP-EXST"
                      "H-EXHS" "H-EXHS-EXST" "H-GRDS" "H-GRDS-EXST"
                      "H-RTRN" "H-RTRN-EXST" "G-GENL-TEXT"
                      "G-GENL-TEXT-EXST" "G-EQPM" "G-EQPM-EXST"
                      "H-STAT" "H-STAT-EXST" "H-OAIR" "H-OAIR-EXST"
                     )
   (prompt
     (strcat "\n["
             layerName
             "] : "
             (if (setq ss (ssget "_x" (list (cons 8 layerName))))
               (itoa (sslength ss))
               "0"
             )
     )
   )
 )
 (textpage)
 (princ)
)

Link to comment
Share on other sites

Nice. it works perfectly. I'll have to dissect your code a littie bit and see what you did incase I need to write something like that again in the future.

 

Thanks.

Link to comment
Share on other sites

Nice. it works perfectly. I'll have to dissect your code a littie bit and see what you did incase I need to write something like that again in the future.

 

Thanks.

 

You're welcome; I'm happy to help. :beer:

 

Essentially, Foreach layerName in the list of layerNames, Prompt the user the layerName, and If there are Entities on that layer, include how many, Else zero.

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...