Jump to content

Recommended Posts

Posted (edited)

I'm wanting to create a way to quickly change the layers of a CADworx object.  

 

This is what I have so far but its not working like I want. The problem is no matter how many objects I select, it only changes the first then stops working completely. If I try to run it again and select another object it wont do anything. I need to be able to select objects manually.

 

Can someone point me in the right direction?

 

(defun C:ttt ()
   (setq STL_SS nil)
   (graphscr)
   (setq STL_SS (ssget '((0 . "LINE")(8 . "CL_Steel"))));;;FIND ALL THE LINES ON LAYER CL-STEEL
   (setq CL_CNT 0)
   (if (/= STL_SS nil)
      (repeat (sslength STL_SS)
         (setq STL_NAME (ssname STL_SS CL_CNT))
         (setvar "pickstyle" 0)
            (command "chprop" STL_NAME "" "LA" "BEAM_CL" "")
         (setq CL_CNT (1+ CL_CNT))
      );;;repeat
   );;;if
   (setq STL_SS nil)
   (setq STL_SS (ssget "L" '((0 . "3DSOLID")(8 . "STEEL"))));;;FIND ALL THE SOLIDS ON LAYER STEEL
   (setq CL_CNT 0)
   (if (/= STL_SS nil)
      (repeat (sslength STL_SS)
         (setq STL_NAME (ssname STL_SS CL_CNT))
            (command "chprop" STL_NAME "" "LA" "BEAM" "")
         (setq CL_CNT (1+ CL_CNT))
      );;;repeat
   );;;if
   (setvar "pickstyle" 1)
(princ)
)

 

Edited by jonathann3891
Posted

Hi,

Something like this?

(defun c:test (/ s i n e )
  (if (setq s (ssget '((-4 . "<OR") (-4 . "<AND") (0 . "LINE")(8 . "CL_Steel") (-4 . "AND>")
                                    (-4 . "<AND") (0 . "3DSOLID")(8 . "STEEL") (-4 . "AND>")
                       (-4 . "OR>"))))
    (repeat (setq i (sslength s))
      (setq i (1- i)
            e (entget (ssname s i))
            )
      (entmod (subst (cons 8 (if (= (cdr (assoc 0 e)) "LINE") "BEAM_CL" "BEAM")) (assoc 8 e) e))
      )
    )
(princ)
)

 

Posted (edited)

Nice Tharwat, just thinking the problem would lend its self to a list  answer,  the only problem is when calling the ssget would require repeated select but if "all" is the suggested option then can use "X"

 

(defun AH:changelay (lst / s y x e)
(setq y 0)
(repeat (setq x (/ (length lst) 3))
    (if (setq s (ssget "x" (list (cons 0 (nth y lst))(cons 8 (nth (+ y 1) lst)))))
      (repeat (setq i (sslength s))
        (setq i (1- i)
            e (entget (ssname s i))
            )
        (entmod (subst (cons 8 (nth (+ y 2) lst))(assoc 8 e) e))
      )
      (alert (strcat "layer not found  " (nth (+ y 1) lst)))
    )
    (setq y (+ y 3))
)
(princ)
)

(AH:changelay ( list "line" "Cl_Steel" "BEM_CL" "3DSOLID" "STEEL" "BEAM" "line" "Ex-Serv-Gas" "Gas-Main"))

or

(AH:changelay ( list 
"line" "Cl_Steel" "BEAM_CL" 
"3DSOLID" "STEEL" "BEAM" 
"line" "Ex-Serv-Gas" "Gas-Main"
))


Could add the "x" as part of the list and check for a user slect.

 


(AH:changelay ( list 
"line" "Cl_Steel" "BEAM_CL" "x"
"3DSOLID" "STEEL" "BEAM" ""
"line" "Ex-Serv-Gas" "Gas-Main" "X" )
)

 

 

Edited by BIGAL
Posted

Tharwat that works perfectly and much simpler.

 

Thanks!

Posted
45 minutes ago, jonathann3891 said:

Tharwat that works perfectly and much simpler.

 

Thanks!

You're welcome anytime. :) 

 

Thank you @BIGAL. :) 

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