工法 发表于 2013-1-4 13:38:57

求助:关于默认输出的问题 钢框架小程序


(prompt"\nthe two points is GJ GG JG or JJ.Enter gj gg jg or jj : ")
(setq cc(getstring))
(setq ans(substr cc 1 1    )
      ane(substr cc 2 1    )
)

如果从键盘输入的话就按gj gg jg or jj 之一程序可以正常运行,如果键盘不输入,程序默认指定jj
,可以用什么函数指定呢?

请大家帮忙解答啊


Andyhon 发表于 2013-1-4 13:46:36

鍵盤不輸入,程序默認指定jj
(setq cc(getstring))
(if (= cc "") (setq cc jj))

改用 ustr
more info:
http://www.google.com/search?as_q=setq&as_epq=%28defun+ustr&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fbbs.mjtd.com

工法 发表于 2013-1-4 14:24:38

(defun C:zz( )

(setq v1 (getvar "cmdecho")   )      
(setq v2 (getvar "osmode")    )



(prompt"\nthe two points is GJ GG JG or JJ.Enter gj gg jg or jj : ")
(setq cc(getstring))
(if (= cc " " )       (setq cc "jj")
)

(setq ans(substr cc 1 1    )
      ane(substr cc 2 1    )
)


(setq mm (getpoint "\n选择第一个点:"))
(setq nn (getpoint "\n选择第二个点:"))
(setq angle1 (angle mm nn)   )

(setvar "cmdecho" 0)   
(setvar "osmode" 0)



(if(= ans "g")
(progn

      (setq p1(polar mm angle1 100))
      (setq p2(polar p1 angle1 300))
      (setq p3(polar p1 (+ (/ pi 2)angle1 )150))
      (setq p4(polar p1 (+(/ (* 3 pi) 2)angle1 )   150))
      (command "pline" p2 "w" 0 0p3 p4 "c" " ")
      (command "chprop" (entlast) "" "c" 4 "")
      (command "hatch" "solid" (entlast) "")       
      (command "chprop" (entlast) "" "c" 4 "")                  

)
)


(if(= ans "j")
    (progn

   (setq p5(polar mmangle1 100))
   (setq p6(polar p5angle1 300))
   (setq p7(polar p6 (+ (/ pi 2) angle1 ) 150))
   (setq p8(polar p6 (+ (/ (* 3 pi) 2)angle1) 150))
   (command "pline" p5 "w" 0 0p7 p8 "C" " ")
   (command "chprop" (entlast) "" "c" 4 "")

    )
)
;第一点的约束情况已经完成




(if(= ane "g")
(progn

    (setq pp1(polar nn (+ piangle1) 100))
    (setq pp2(polar pp1 (+ pi   angle1) 300))
    (setq pp3(polar pp1 (+ (/ pi 2)angle1 ) 150))
    (setq pp4(polar pp1 (+ (/ (* 3 pi) 2) angle1)150))
    (command "pline" pp2 "w" 0 0pp3 pp4 "C"" ")
    (command "chprop" (entlast) "" "c" 4 "")
    (command "hatch" "solid" (entlast) "")       
    (command "chprop" (entlast) "" "c" 4 "")
)
)


(if(= ane "j")
    (progn
   
   (setq pp5(polar nn( + piangle1)100))
   (setq pp6(polar pp5(+pi angle1)300))
   (setq pp7(polar pp6 (+ angle1(/ pi 2) )150))
   (setq pp8(polar pp6 (+ angle1(/ (* 3 pi) 2) ) 150))
   (command "pline" pp5 "w" 0 0pp7 pp8 "C"" ")
   (command "chprop" (entlast) "" "c" 4 "")

    )
)
;第二点的约束情况已经完成






(if (and (= ans "j") (= ane "g"))
    (progn
      (command "pline" p6   "W" 100 100pp1 "c"" ")
      (command "chprop" (entlast) "" "c" 4 "")
    )
)   
;一端铰接,一端刚接情况


(if (and (= ans"j") (= ane"j"))
   (progn      
          (command "pline"p6"W" 100 100pp6"c" " ")
          (command "chprop" (entlast) "" "c" 4 "")
   )
   
)   
;两端铰接情况

(if (and (= ans "g") (= ane "j"))   
   (progn
         (command "pline" p1    "W" 100 100pp6 "c"" ")
         (command "chprop" (entlast) "" "c" 4 "")
   )
      
)   
;一端刚接,一端铰接情况


(if (and (= ans "g") (= ane "g"))
    (progn   
         (command "pline" p1   "W" 100100   pp1 "c"" ")
         (command "chprop" (entlast) "" "c" 4 "")
    )
      
)   
;两端刚接情况


(setvar "cmdecho" v1)   
(setvar "osmode" v2)




(princ   )
)
(prompt "****精工<<C:zz>>*****")
(princ )




为什么按照默认的运行不了,求解释

工法 发表于 2013-1-4 14:42:46

解决了,原来是小冒号的问题。多谢版主Andyhon 啦
页: [1]
查看完整版本: 求助:关于默认输出的问题 钢框架小程序