找坡计算任意高程点标注命令

linxiaoyun 2024.4.11 7:42 114 0
结构设计 autolisp AutoCAD

找坡计算任意高程点标注命令——CAD二次开发

原理:在一个已知坡率(比)的单向找坡平面上,已知基准线及其高程,可以计算该平面任意一点的高程。通过计算点到基准线距离L,高差H=L*i,假设坡降为正,则计算点高程H1=基准线高程H0-H。

;计算结构找坡坐标
;输入基准线高程、坡度
;输入基准线
;点选位置生成坐标值
(defun C:ges( / originz poudu en pt0 pt1 pt2 pt3 L resultz ss tempH tempL tempPT) 
;Designed by 林霄云 2023年7月4日
;根据基准线高程、坡度计算结构找坡高程

(if (setq originz (nentsel "\n选择基准线高程,按空格输入:"))
(setq originz (atof (get-dxf 1 (car originz)))) ;换成实数
(setq originz (getreal "\n输入基准线高程:"))
);if
(princ (strcat "\n基准线高程为:" (rtos  originz 2 3)))
(initget "S")
(setq poudu (getreal 
				(strcat "\n输入坡度,初始高程在低位取负号,S输入水平距离和高差计算坡度,按空格可取上一次坡度[0.03/-0.03/0.05/-0.05/S]< " 
					(if  (null hnu:islope) "0.05" (rtos  hnu:islope 2 4)) " >:"))
)

(cond  ((null poudu ) (if  (null hnu:islope) (setq poudu 0.05) (setq poudu  hnu:islope )))
       ((or (= poudu "S" )(= poudu "s" ))
					(setq tempH (getreal "\n输入高差(mm),降为正,按空格通过选取两高程文字计算差值确定:"))
					(if (null tempH) 
					(setq tempH (* 1000 (- (atof (get-dxf 1 (car (nentsel "\n选择第一个高程文本(m):")))) 
										   (atof (get-dxf 1 (car (nentsel "\n选择下一个高程文本(m):")))))
										   ))
					);if
					(setq tempL (getreal "\n输入水平距离(mm),按空格通过点取两点计算距离确定:"))
					(if (null tempL)(setq tempL (distance (setq tempPT (getpoint "\n输入水平距离起点")) (getpoint tempPT "\n输入水平距离终点"))))
					(setq poudu (/ tempH tempL ))
					(princ (strcat "\n高差:" (rtos tempH 2 3) "\t水平距离:" (rtos tempL 2 3)))
					(princ (strcat "\n计算坡度为:" (rtos poudu 2 3)))
					)
					);cond
(if ( /= hnu:islope poudu)
	(progn
	(setq hnu:islope poudu)					
	(princ (strcat "\n坡度存储为:" (rtos  hnu:islope 2 4)))
	))
					
(princ "\n点选两点确定初始高程基准线:")

(setq pt1 (getpoint "\n点取基准线起始点,")
	  pt2 (getpoint pt1 "点取基准线终点。")
	  pt3 pt2)
	 
(while (setq pt0 (getpoint pt3 "\n计算点位置:"))  
(setq pt3 (PerToLine pt0  pt1 pt2))
(setq L (distance pt0 pt3))
(redraw)
(grdraw pt0 pt3 20 1)
(princ "\n计算点至基准线距离L=")
(princ L)
(setq resultz (- originz (* poudu L 0.001)))
(princ "\n计算坐标高程=")
(princ resultz)
(setq ss (elev-symbol (rtos resultz 2 3 ) pt0 ))
(command "_group" "c" "*" "" ss "")
);while
(princ)
)
(princ "\nges找坡计算高程点ges命令加载成功!\n根据基准线高程与坡度(比)计算基准线一侧任意点高程")
(princ "Designed by 林霄云 2023年7月4日")

操作:简单编写代码便可以实现自动计算并标注任意点的高程。值得注意的是,避免方向性的计算,简化为总是计算标注基准线一侧的高程点。考虑到输入便利性,对于坡率i,进行存储。同时坡率i支持多种方式输入,包括直接输入,也可以通过i=H/L计算确定,在计算确定i时,H和L也支持直接输入或从图中拾取输入。

概念原理及操作均简单,不再上动图演示。有需要的朋友可以联系我免费索取。

Last Modified·2024年4月11日 07:49

暂无评论

您尚未登录,请先才能评论。