Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lisp-Adding to a Selection Set

Status
Not open for further replies.

brengine

Mechanical
Apr 19, 2001
616
I'd like to take the LayerIsolate lisp routine from the Express Tools and modify it. We use 4 layers for one component, we call them layer groups. So for the component 1, the 4 actual layers needed to show the part are: layer 1s is solid lines only, layer 1c is centerlines only, layer 1h is hidden lines only, and layer 1p is phantom lines only. I would like to control the visibility of each group all together.

So what I want is a LayerIsolateGroup routine that will look at the selected items, and keep those layers on as well as the ?s, ?c, ?h, and ?p layers for each selection.

Here's the code to get the graphical selections:
Code:
  (if (not (setq SS (ssget "_i"))) 
    (progn 
      (prompt "\nSelect object(s) on the layer(s) to be isolated: ") 
      (setq SS (ssget)) 
    ) 
  ) 
  
  
  (if SS 
    (progn 
  
      (setq CNT 0) 
  
      (while (and ss 
                  (> (sslength ss) 0) 
                  (setq LAY (ssname SS CNT)) 
             );and 
        (setq LAY (cdr (assoc 8 (entget LAY)))) 
        (if (not (member LAY LAYLST)) 
          (setq LAYLST (cons LAY LAYLST)) 
        ) 
        (setq CNT (1+ CNT)) 
      )

Any idea how to add the additional layer names to LAYLST (or maybe LAY...I'm not really sure but I think LAYLST)? I think that is what I want to do because later in the code are these 3 lines:
Code:
          (command "_.-LAYER" "_OFF" "*" "_Y") 
          (foreach VAL LAYLST (command "_ON" VAL)) 
          (command "")

I've also found this to check whether a layer exists (NEWLAYER in this example):
(setq flag (tblsearch "LAYER" "NEWLAYER"))

And this for the string length:
strlen

Thanks,
Ken
 
Replies continue below

Recommended for you

Heres the VLISP way to cycle through all the layers. This example shows how to unlock all of the layers but you can apply a test to the layer names and then apply the property you want the layers to have (eg be ON and THAWED). IHTH.

(setq *acad-object* nil) ; Initialize global variable
(setq *active-document* nil) ; Initialize global variable
(defun pp_GetActiveDocument ()
(cond (*active-document*) ; Return the cached object
(T
(setq *active-document* (vla-Get-ActiveDocument (pp_GetAcadObject)))
)
)
)
(defun pp_GetAcadObject ()
(cond (*acad-object*) ; Return the cached object
(T
(setq *acad-object* (vlax-Get-Acad-Object))
)
)
)
(defun pp_UnlockAllLayers (/ EA_LYR)
(vl-catch-all-error-p
(vlax-for EA_LYR (vla-get-Layers (pp_GetActiveDocument))
(vla-put-lock EA_LYR :vlax-false)
)
)
)


"The fear of the Lord is the beginning of wisdom"
 
Add this to your Acad.lsp file, then type L1 to make it work.

(Defun C:L1 ()
(Command("Layer" "Freeze" "*" "Thaw" "1*")
(princ)
)
 
Thanks for the reply's. I've gotten something kludged together that mostly works, but I'll look more into what you've shown me and see if I can get this thing completely working for me.

Thanks,
Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor