Jump to content

Recommended Posts

Posted

I created the routine below as part of a larger routine for converting drawings to my company's standard layers. It works perfectly except I need the user to either select a line or hit 'enter' before continuing. As it is now, if you pick an empty point in space instead of a line,the routine just keeps running.

As an example, if the Matchprop does exactly what I want...it keeps prompting you to pick a source point before it goes any further.

TIA for any help!

 

(if (setq ent1 (entsel "\n Pick an existing ELECTRICAL FIXTURE.................'Enter' if none "))

(setq lay1 (value 8 (entget (car ent1))))

)

(if lay1

(if (setq ss (ssget "x" (list (cons 410 (getvar "ctab")) (cons 8 lay1))))

(progn (sssetfirst nil ss))

)

)

(command "chprop" "P" "" "la" "D-EX-ELECT" "C" "bylayer" "LT" "bylayer" "")

Posted

I think you need to create list of all your company layers do loop with FOREACH function.

 

; create all company layers list
(setq layLst '("D-EX-ELECT" "Electrical2" "Electrical3" "Electrical4"))

; foreach layer in list
(foreach lay layLst

 ; if user has select entity for this layer and selection set has created
 (if
   (and
     (setq cEnt(entsel(strcat "\nSelect entity for '" lay "' or Enter for none> ")))
     (setq cLay(cdr(assoc 8(entget(car cEnt)))))
     (setq cSet(ssget "x"(list(cons 410(getvar "ctab"))(cons 8 cLay))))
     ); and and
   (progn

     ; higlight selection set for user can to see it
     (sssetfirst nil cSet)
     (initget "Yes No")

     ; if user press Y or hit Enter
     (setq cAns(getkword
	  (strcat "\nDo you want to cnahge layer to '" lay "'? [Yes/No]<Yes>: ")))
     (if(/= "No" cAns)

 ; change properties of selection set
(command "chprop" "P" "" "la" lay "C" "bylayer" "LT" "bylayer" "")
(princ(strcat "\nLayer '" lay "' passed by user "))
); end if
     ); end progn
   (princ(strcat "\nNothing selected for '" lay))
   ); end if
 ); end foreach

 

Not tested.

Posted

ASMI,

It works perfectly, but the one missing element is if you accidently select nothing, it skips ahead to the next layer. How do I get it make sure an entity is selected before moving on to the next step?

Thanks again!

Posted

ASMI,

 

Is this possible?

 

; create all company layers list
(setq layLst '("D-EX-ELECT" "Electrical2" "Electrical3" "Electrical4"))

; foreach layer in list
(foreach lay layLst

 ; if user has select entity for this layer and selection set has created
 (if
   (and
     (setq cEnt(entsel(strcat "\nSelect entity for '" lay "' or Enter for none> ")))
     (setq cLay(cdr(assoc 8(entget(car cEnt)))))
     (setq cSet(ssget "x"(list(cons 410(getvar "ctab"))(cons 8 cLay))))
     ); and and
   (progn

     ; higlight selection set for user can to see it
     (sssetfirst nil cSet)
     (initget "Yes No")

     ; if user press Y or hit Enter
     (setq cAns(getkword
         (strcat "\nDo you want to cnahge layer to '" lay "'? [Yes/No]<Yes>: ")))
     (if(/= "No" cAns)
   
    ; change properties of selection set
   (command "chprop" "P" "" "la" lay "C" "bylayer" "LT" "bylayer" "")
   (princ(strcat "\nLayer '" lay "' passed by user "))
   ); end if
     ); end progn
   (while
   (and
     (= (setq cEnt(entsel(strcat "\nSelect entity for '" lay "' or Enter for none> "))) nil)
     (setq cLay(cdr(assoc 8(entget(car cEnt)))))
     (setq cSet(ssget "x"(list(cons 410(getvar "ctab"))(cons 8 cLay))))
     ); end and

     ; higlight selection set for user can to see it
     (sssetfirst nil cSet)
     (initget "Yes No")

     ; if user press Y or hit Enter
     (setq cAns(getkword
         (strcat "\nDo you want to cnahge layer to '" lay "'? [Yes/No]<Yes>: ")))
     (if(/= "No" cAns)
   
    ; change properties of selection set
   (command "chprop" "P" "" "la" lay "C" "bylayer" "LT" "bylayer" "")
   ); end if
   ); end while
   ); end if
 ); end foreach

Posted

Is this?

 

(defun c:test(/ layLst cEnt cLay cSet cAns)

; create all company layers list
(setq layLst '("D-EX-ELECT" "Electrical2" "Electrical3" "Electrical4"))

; foreach layer in list
(foreach lay layLst
 (setq cEnt nil)
 ; if user has select entity for this layer and selection set has created
 (while(not cEnt)
    (setq cEnt(entsel(strcat "\nSelect entity for '" lay "' > ")))
 (if
   (and
     cEnt
     (setq cLay(cdr(assoc 8(entget(car cEnt)))))
     (setq cSet(ssget "x"(list(cons 410(getvar "ctab"))(cons 8 cLay))))
     ); and and
   (progn

     ; higlight selection set for user can to see it
     (sssetfirst nil cSet)
     (initget "Yes No")

     ; if user press Y or hit Enter
     (setq cAns(getkword
	  (strcat "\nDo you want to cnahge layer to '" lay "'? [Yes/No] <Yes>: ")))
     (if(/= "No" cAns)

 ; change properties of selection set
(command "chprop" "P" "" "la" lay "C" "bylayer" "LT" "bylayer" "")
(progn
(princ(strcat "\nLayer '" lay "' passed by user "))
(sssetfirst nil nil)
); end progn
); end if
     ); end progn
    (progn
      (princ(strcat "\n>>> Nothing selected for '" lay "' <<< "))
      (initget "Next Repeat")
      (if(= "Next"(setq cAns(getkword "\nRepeat or [Next]? <Repeat>: ")))
 (progn
   (setq cEnt T)
   (princ(strcat "\nLayer '" lay "' passed by user "))
  ); end progn
 ); end if
     ); end progn
    ); end if
   ); end while
 ); end foreach
 (princ "\n<<< End of layer list. Exit. >>> ")
 (princ)
 ); end of c:test

Posted

Another variation.

(defun c:test (/ layLst cEnt cLay cSet cAns)
 ;; create all company layers list
 (setq layLst '("D-EX-ELECT" "Electrical2" "Electrical3" "Electrical4"))
 ;; foreach layer in list
 (foreach lay layLst
   ;; if user has select entity for this layer and selection set has created
   (while
     (cond
       ((and (setq cEnt (entsel (strcat "\nSelect entity for '" lay "' > ")))
             (setq cLay (cdr (assoc 8 (entget (car cEnt)))))
        )
        (setq cSet (ssget "x" (list (cons 410 (getvar "ctab")) (cons 8 cLay))))
        ;; higlight selection set for user can to see it
        (sssetfirst nil cSet)
        (initget "Yes No")
        ;; if user press Y or hit Enter
        (setq cAns (getkword
                     (strcat "\nDo you want to change layer to '" lay "'? [Yes/No] <Yes>: ")))
        (if (/= "No" cAns) ; change properties of selection set
          (command "chprop" "P" "" "la" lay "C" "bylayer" "LT" "bylayer" "")
          (progn
            (princ (strcat "\nLayer '" lay "' passed by user "))
            (sssetfirst nil nil)
          )
        )
       )
       ((progn
          (princ (strcat "\n>>> Nothing selected for '" lay "' <<< "))
          (initget "Next Repeat")
          (if (= "Next" (setq cAns (getkword "\nRepeat or [Next]? <Repeat>: ")))
            (prompt (strcat "\nLayer '" lay "' passed by user "))
            t
          ) ; end if
        )
       )
     )
   )     ; end while
 )       ; end foreach
 (princ "\n<<< End of layer list. Exit. >>> ")
 (princ)
)         ; end of c:test

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