Controlling visibility with lisp

Controlling visibility with lisp

phartwell
Contributor Contributor
866 Views
2 Replies
Message 1 of 3

Controlling visibility with lisp

phartwell
Contributor
Contributor

I am new to lisp (and this forum) so please excuse the very basic question.

 

I am using Plant3D and wanted to use lisp to find layer groups and isolate them.

My layers are organised by a naming structure ie C-xx Civil layers S-xx Structural layers E-xx Equipment layers etc.

 

I have started with the following code, which works for a single input. What I would like to do is put it inside a while loop so I can isolate several layer groups ie. C- & E- to isolate all the Civil and Equipment layers. But I can't work out a format that works. Would anyone be able to give me any advice?

 

Philip

 

;laygroupshow * lisp to show all layers that start with the characters entered by the user ie isolate all civil layers by entering C-
(defun C:laygroupshow()
      (setq MyLaygroup (getstring T "\n Enter initial search text: ie C- :-")) ; Prompt for search text
      (setq MyLaygroup (strcat MyLaygroup "*")) ; Add Wildcard * to end of string
      (setq sel1 (ssget "X" (list (cons 8 MyLaygroup)))) ; Set sel1 to layers that match search condition
      (command "ISOLATEOBJECTS" sel1 "") ;isolate selected objects
      (princ)
)

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

CodeDing
Advisor
Advisor
Accepted solution

@phartwell ,

 

There are a couple ways you could go about this.. My method sticks to your original request, but for example you could even set this up where the user can input a comma-delimited string "c-,s-,..." and go about it that way also.

 

Give this a go:

(defun c:LayGroupShow ( / grp grpStr ss)
(setq grpStr "")
(while (not (eq "" (setq grp (strcase (getstring "\nEnter initial search text (e.g. \"C-\")(Enter to continue): ")))))
  (if (eq "" grpStr)
    (setq grpStr (strcat grp "*"))
    (setq grpStr (strcat grpStr "," grp "*"))
  );if
);while
(if (not (eq "" grpStr))
  (if (setq ss (ssget "_X" (list (cons 8 grpStr))))
    (command "_.ISOLATEOBJECTS" ss "")
    (prompt (strcat "\nNo Objects found to isolate from search text:\n" grpStr))
  );if
;else
  (prompt "\nNo search text provided.. No actions performed.")
);if
(setq ss nil) (princ) );defun

Best,

~DD

Message 3 of 3

phartwell
Contributor
Contributor

Thank you very much for this, I missed your reply when it first came in and then got pandemic distracted. It works beautifully and really helps me manage visibility in the design environment.

 

Philip

0 Likes