(defun c:alignspace(/ ss2 p1 p2 p3 p4 flag flag2 a)(acet-error-init(list(list"cmdecho"0"regenmode"1"ucsfollow"0)T))(cond((not(equal 0(getvar"tilemode")))(princ"\n  不允许使用该命令,除非 TILEMODE 设置为 0  "))((and(setq flag(acet-viewport-next-pickable))(car flag))(progn(command"_.mspace")(if(not(equal(car flag)(getvar"cvport")))(progn(princ"\n在透视视图中不允许点击...")(princ"\n切换到下一可用模型空间视口")(setvar"cvport"(car flag))))(while(not flag2)(if(setq p1(getpoint"\n在模型空间里第一对齐点: "))(progn(setq p2(getpoint p1"\n在模型空间里第二点或<回车> 不选取: "))(setq p1(trans p1 1 0))(if p2(setq p2(trans p2 1 0)))))(if(and p1(equal p1 p2))(princ"\n*无效* 不能为相同的点。")(setq flag2 T)))(if p1(progn(command"_.pspace")(setq flag2 nil)(while(not flag2)(if p2(setq a"\n图纸空间的第一对齐点: ")(setq a"\n图纸空间的对齐点: "))(if(and(setq p3(getpoint a))p2)(setq p4(getpoint p3"\n图纸空间的第二对齐点: ")))(if(and p3(equal p3 p4))(princ"\n*无效* 不能为相同的点。")(setq flag2 T)))
(setq flag2 nil)(command"_.mspace")(if(and(setq ss2(ssget"_x"'((0 . "VIEWPORT")(67 . 1))))(=(sslength ss2)2))(setq flag2 T))(while(not flag2)(getstring"\n切换到要对齐的视口或按回车键继续。")(if(equal(getvar"cvport")(car(setq flag(acet-viewport-next-pickable))))(setq flag2 T)(progn(princ"\n*错误*")(princ(strcat"\n不能使用已经关闭的视口"" 或含有透视图的视口.")))))(if(or(and p1(not p2)p3(not p4))(and p1 p2 p3 p4))(alignspace p1 p2 p3 p4))))))((cadr flag)(princ(cadr flag))))(acet-error-restore)(princ))(defun alignspace(p1 p2 p3 p4 / vp a b c d na vplocked)(if(= 1(getvar"cvport"))(command"_.mspace"))(setq na(acet-currentviewport-ename)vplocked(acet-viewport-lock-set na nil))(command"_.pspace")(setq p3(trans p3 1 3))(if p4(setq p4(trans p4 1 3)))(command"_.mspace")(acet-ucs-cmd(list"_view"))(setq p1(trans p1 0 1))(if p2(setq p2(trans p2 0 1)))(if(not p2)(progn(setq vp(acet-currentviewport-ename)vp(entget vp)vp(cdr(assoc 41 vp))a(/ vp(getvar"viewsize"))))
(setq p2(list(car p2)(cadr p2)(caddr p1))p4(list(car p4)(cadr p4)(caddr p3))a(/(distance p3 p4)(distance p1 p2))))(setq c(trans p3 3 2)c(trans c 2 1))(if p4(setq d(trans p4 3 2)d(trans d 2 1)))(if(and p2 p4(not(equal(angle p1 p2)(angle c d)0.0001)))(progn(acet-ucs-cmd(list"_z"(*(-(angle p1 p2)(angle c d))(/ 180.0 pi))))(command"_.plan""_c")(acet-ucs-cmd(list"_p"))))(if(and p2 p4)(command"_.zoom"(strcat(rtos a 2 6)"xp")))(setq b(trans p3 3 2)b(trans b 2 1))(command"_.-pan"p1 b)(acet-ucs-cmd(list"_p"))(if vplocked(acet-viewport-lock-set na T))(if(and p2 p4(or(not(equal(caddr p1)(caddr p2)0.0001))(not(equal(caddr c)(caddr d)0.0001))))(progn(princ"\n警告: 选取的点不平行视图")(princ"\n命令结果可能不明显")))(princ"\n图纸空间 = 模型空间")(princ(strcat"\n"(substr"             "1(max(- 11(strlen(rtos 1.0)))0))(rtos 1.0)" = "(rtos(/ 1.0 a))))(princ(strcat"\n当前缩放因子 = "(rtos a)"xp")))(princ)
