为什么这不起作用
这就是我想要的,除了一件事。我不知道如何改变它。我只想让它问我一次间距是多少,但它是在问我每一行的间距。;Version 1.00
(defun c:cs (/)
(and (setq ss (ssget "_:L" '((0 . "LINE"))))
(while (setq en (ssname ss 0))
(setq ed (entget en))
(setq p10 (cdr (assoc 10 ed)))
(setq p11 (cdr (assoc 11 ed)))
(setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
(setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11))))
;(setq d1d (/ d2d 12.))
;(setq d1c (fix (+ d1d 0.501)))
(setq c (getstring "\nWhat is the spacing? (24,16,12): "))
(if (= c "24")
(cond((<= d2d 118)(setq e "2x6"))
((and(>= d2d 118.01)(<= d2d 150))(setq e "2x8"))
((and(>= d2d 150.01)(<= d2d 177))(setq e "2x10"))
((and(>= d2d 177.01)(<= d2d 209))(setq e "2x12"))
((and(>= d2d 209.01)(<= d2d 500))(setq e "Change Spacing"))
);end cond
);end if
(if (= c "16")
(cond((<= d2d 144)(setq e "2x6"))
((and(>= d2d 144.01)(<= d2d 183))(setq e "2x8"))
((and(>= d2d 183.01)(<= d2d 217))(setq e "2x10"))
((and(>= d2d 217.01)(<= d2d 256))(setq e "2x12"))
((and(>= d2d 256.01)(<= d2d 500))(setq e "Change Spacing"))
);end cond
);end if
(if (= c "12")
(cond((<= d2d 167)(setq e "2x6"))
((and(>= d2d 167.01)(<= d2d 211))(setq e "2x8"))
((and(>= d2d 211.01)(<= d2d 251))(setq e "2x10"))
((and(>= d2d 251.01)(<= d2d 296))(setq e "2x12"))
((and(>= d2d 296.01)(<= d2d 500))(setq e "Change Spacing"))
);end cond
);end if
(defun radians->degrees (r)(cvunit r "radian" "degree"));end rad defun
;-------TEXT JUSTIFICATION----------------------------------------
(setq lan (angle p10 p11))
(setq ad (radians->degrees lan))
(if (and (> ad 90.1) (<= ad 270.1))
(progn
(setq ptemp p10
p10 p11
p11 ptemp
lan (angle p10 p11)
ad (radians->degrees lan))
);end progn
);end if
(setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))
(setq r3(entmake (list (cons 0 "TEXT")
(cons 8 (getvar "CLAYER"))
(cons 7 (getvar "TEXTSTYLE"))
(cons 40 (getvar "TEXTSIZE"))
(cons 41 0.80)
(cons 72 4)
(setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
;(getvar "TEXTSIZE")))))
(setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
(+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
(setq gg(cons 50 lan))
(setq rg(cons 1 (strcat e)))
);end list
);end entmake
);end setq r3
(ssdel en ss)));end and
(prin1)
);end defun 我现在明白了,因为某种原因,它给了我一个错误。
; 错误:错误的参数类型:stringp nil
但是当我运行我的另一个LISP时,然后运行这个LISP,它就可以工作了。
你知道为什么吗?
;Version 1.00
(defun c:cs (/)
(setq c (getstring "\nWhat is the spacing? (24,16,12): "))
(and (setq ss (ssget "_:L" '((0 . "LINE"))))
(while (setq en (ssname ss 0))
(setq ed (entget en))
(setq p10 (cdr (assoc 10 ed)))
(setq p11 (cdr (assoc 11 ed)))
(setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
(setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11))))
;(setq d1d (/ d2d 12.))
;(setq d1c (fix (+ d1d 0.501)))
(if (= c "24")
(cond((<= d2d 118)(setq e "2x6"))
((and(>= d2d 118.01)(<= d2d 150))(setq e "2x8"))
((and(>= d2d 150.01)(<= d2d 177))(setq e "2x10"))
((and(>= d2d 177.01)(<= d2d 209))(setq e "2x12"))
((and(>= d2d 209.01)(<= d2d 500))(setq e "Change Spacing"))
);end cond
);end if
(if (= c "16")
(cond((<= d2d 144)(setq e "2x6"))
((and(>= d2d 144.01)(<= d2d 183))(setq e "2x8"))
((and(>= d2d 183.01)(<= d2d 217))(setq e "2x10"))
((and(>= d2d 217.01)(<= d2d 256))(setq e "2x12"))
((and(>= d2d 256.01)(<= d2d 500))(setq e "Change Spacing"))
);end cond
);end if
(if (= c "12")
(cond((<= d2d 167)(setq e "2x6"))
((and(>= d2d 167.01)(<= d2d 211))(setq e "2x8"))
((and(>= d2d 211.01)(<= d2d 251))(setq e "2x10"))
((and(>= d2d 251.01)(<= d2d 296))(setq e "2x12"))
((and(>= d2d 296.01)(<= d2d 500))(setq e "Change Spacing"))
);end cond
);end if
(defun radians->degrees (r)(cvunit r "radian" "degree"));end rad defun
;-------TEXT JUSTIFICATION----------------------------------------
(setq lan (angle p10 p11))
(setq ad (radians->degrees lan))
(if (and (> ad 90.1) (<= ad 270.1))
(progn
(setq ptemp p10
p10 p11
p11 ptemp
lan (angle p10 p11)
ad (radians->degrees lan))
);end progn
);end if
(setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))
(setq r3(entmake (list (cons 0 "TEXT")
(cons 8 (getvar "CLAYER"))
(cons 7 (getvar "TEXTSTYLE"))
(cons 40 (getvar "TEXTSIZE"))
(cons 41 0.80)
(cons 72 4)
(setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
;(getvar "TEXTSIZE")))))
(setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
(+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
(setq gg(cons 50 lan))
(setq rg(cons 1 (strcat e)))
);end list
);end entmake
);end setq r3
(ssdel en ss)));end and
(prin1)
);end defun 宽度变量没有值,它返回nil,这将导致代码在命令行返回错误。
(setq hg (cons 11
(setq r2 (polar mpt
(dir lan (* 0.5 pi))
(+ (* 0.5 (atof width))
(* 0.8 (getvar "TEXTSIZE"))
)
)
)
)
)
并将变量本地化,如下所示。
(defun c:cs (/ A AD B C D2D DIR E ED EN FG GG HG LAN MPT P10 P11 PTEMP R2 R3 RG SS WIDTH)
你想完成什么? 正如Tharwat已经指出的那样,未分配宽度变量,因此当您尝试在评估中使用它时,它将生成错误。你说在使用了一个特定的例程之后,麻烦制造者一个才开始工作-你没有发布第二个例程的代码,但它有帮助的原因是你可能有一个同名的变量,所以当调用CS命令时,变量现在可以被评估。 删除宽度变量后,立即尝试此拔模
(defun c:cs(/弧度->度a ad b c d2d dir e ed en lan mpt p10 p11 ptemp ss)(defun弧度->度(r)(cvunit r“radian”“degree”)(if(and(progn(initget 7“12 16 24”)(setq c(getkword”\n间距是什么?(24,16,12):))(setq ss(ssget“:L”((0。“LINE”))))(progn(while(setq en(ssname ss 0))(setq ed(entget en))(setq mpt(mapcar)(λ(a b)(*(+a b)0.5))(setq p10(cdr(assoc 10 ed))(setq p11(cdr(assoc 11 ed))))(setq d2d(距离(cdr(反向p10))(cdr(反向p11)))(if(=c“24”)(cond((=d2d 118.01)(=d2d 150.01)(=d2d 177.01)(=d2d 209.01)( 我用了另一个Lisp程序的部分,这就是为什么在那里。我改了,效果很好。
塔尔瓦特,
我的目标是使用这个,尝试合并另一个lisp,这样我可以滑动很多行,让它用维度标记它们,并说出它们是什么。因此,任何等于相同结果的线都将用尺寸标注。从我的例子来看,这可能会有帮助。我还不擅长Lisp程序,所以我一步一步地做。
实例图纸
我说的是当前修改的lisp,我不知道你的第二个lisp,所以我猜不出第二个lisp做了什么。
页:
[1]