RJW 发表于 2022-7-6 17:22:28

循环和用户选择。。。。

我创建了下面的例程,作为将图形转换为公司标准图层的更大例程的一部分。它工作得很好,除了我需要用户在继续之前选择一行或点击“回车”键。现在,如果你在空间中选择一个空点而不是一条线,例程就会继续运行。
举个例子,如果Matchprop完全符合我的要求。。。它会不断提示您在继续之前选择一个源点。
TIA需要任何帮助!
 
(如果(setq ent1(entsel“\n拾取现有电气设备……………..如果没有,'Enter'))
(setq lay1(值8(entget(car ent1)))
)
(如果铺设1
(if(setq ss(ssget“x”(list(cons 410(getvar“ctab”)))(cons 8 lay1)))
(progn(sssetfirst nil ss))
)
)
(命令“chprop”“P”“”“la”“D-EX-ELECT”“C”“bylayer”“LT”“bylayer”“)

ASMI 发表于 2022-7-6 17:34:40

我认为您需要创建所有公司层的列表,并使用FOREACH函数进行循环。
 
; 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>: ")))
   (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
 
未测试。

RJW 发表于 2022-7-6 17:49:24

Kewl。。谢谢我试试看!

RJW 发表于 2022-7-6 17:59:33

ASMI,
它工作得很好,但缺少的一个元素是,如果你不小心什么都没有选择,它会跳到下一层。我如何确保在进入下一步之前选中一个实体?
再次感谢!

Lee Mac 发表于 2022-7-6 18:08:08

ASMI,
 
这可能吗?
 
; 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>: ")))
   (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>: ")))
   (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

ASMI 发表于 2022-7-6 18:15:01

这是吗?
 
(defun c:测试(/layLst cEnt cLay cSet cAns);创建所有公司图层列表(setq layLst’(“D-EX-ELECT”“Electrical2”“Electrical3”“Electrical4”);列表中的foreach层(foreach lay layLst(setq cEnt nil);如果用户为该层选择了实体,并且选择集已经创建(而不是cEnt)(setq cEnt(entsel(strcat“\n选择‘lay’>’的实体))(if(和cEnt(setq cLay(cdr(assoc 8(entget(car cEnt)k))))(setq cSet(ssget“x”(list(cons 410(getvar“ctab”)))(cons 8 cLay)));and and(progn;higlight选择集,供用户查看(sssetfirst nil cSet)(initget“Yes No”);如果用户按Y键或按Enter键(setq cAns(getkword(strcat“\n您想将cnahge层转换为“lay”?[是/否]:”))(如果(/=“否”cAns);更改选择集的属性(命令“chprop”“P”“”“la”lay“C”“bylayer”“LT”“bylayer”“)(progn(princ(strcat“\nLayer”“lay”'由用户传递))(sssetfirst nil nil));结束程序);如果结束);结束progn(progn(princ(strcat)“\n>>>未为“lay”选择任何内容

CAB 发表于 2022-7-6 18:29:40

另一个变体。
(defun c:测试(/layLst cEnt cLay cSet cAns);;创建所有公司图层列表(setq layLst’(“D-EX-ELECT”“Electrical2”“Electrical3”“Electrical4”);;foreach lay layLst;;如果用户已为此层选择实体,并且已创建选择集(而(cond((and(setq cEnt(entsel(strcat“\nSelect entity for‘lay’>”)))(setq cLay(cdr(assoc 8(entget(car cEnt)k)k))(setq cSet(ssget“x”(list(cons 410(getvar“ctab”)))(cons 8 cLay));;higlight选择集,用户可以看到它(sssetfirst nil cSet)(initget“Yes No”);;如果用户按Y键或按Enter键(setq cAns(getkword(strcat“\n您想将层更改为”lay“?[是/否]:”)))(如果(/=“否”cAns);更改选择集的属性(命令“chprop”“P”“la”lay“C”“bylayer”“LT”“bylayer”“)(progn(princ(strcat“\nLayer”“lay”'由用户传递))(sssetfirst nil nil)))((progn(princ(strcat“\n>>未为“lay”选择任何内容)
页: [1]
查看完整版本: 循环和用户选择。。。。