本帖最后由 yanshengjiang 于 2024-7-18 16:10 编辑
混迹明经十余年,没有认真学习,至今都只能东拼西凑。
今天没事把以前用autolisp写的程序用VL函数重写了一次
- (defun c:tt(/ *error* _startundo _endundo acdoc ss i tt len s b h id)
- ;照搬 lee-mac的出错函数和undo标记,不知其所以然,也不知道对不对。
- (defun *error* (msg)
- (if acdoc
- (_endundo acdoc)
- )
- (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
- (princ (strcat "\n** Error: " msg " **"))
- )
- (princ)
- )
- (defun _startundo (doc)
- (_endundo doc)
- (vla-StartUndoMark doc)
- )
- (defun _endundo (doc)
- (while (= 8 (logand 8 (getvar 'UNDOCTL)))
- (vla-EndUndoMark doc)
- )
- )
- (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
-
- ;2024年7月18日 yanshengjiang 于g103.97695700,30.72349432
- (princ"\n南方cass高程点加常数or修改小数位数.建议先执行一次cass命令:根据注记修改高程。")
- ;(vl-catch-all-apply
- ; '(lambda()
- (setq ss(ssget '((2 . "gc200")(8 . "GCD")))
- i -1)
- (setq tt(getreal "\n输入要加的常数<负数表示减.如果只想改变位数那么直接回车+0 <0>"))
- (if(null tt)(setq tt 0))
- (setq len(getint "\n输入要保留的小数位数<2>"))
- (if(null len)(setq len 2))
- (_startundo acdoc)
- (repeat(sslength ss)
- (setq s(vlax-ename->vla-object(ssname ss(setq i(1+ i)))))
- ;高程点的一些操作,源自明经通道
- (if (= (vla-Get-ObjectName s) "AcDbBlockReference")
- (if (vla-Get-HasAttributes s)
- (progn
- (setq b(nth 0(vlax-safearray->list (vlax-variant-value(vla-GetAttributes s)))))
- (setq h(read(vla-get-TextString b))) ;高程点块的属性值 333.03
- (setq id(vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint s))));块的三维插入点 (10.9191 10.7323 333.032)
- (if(equal h (last id) 1e-1)(setq h(last id)));如果属性和Z值一样,就用z值来加减,防止损失毫米位精度
- (setq h(+ tt h))
- (setq id(list(car id)(cadr id) h))
- (vla-put-insertionpoint s (vlax-3D-point id)) ;改变块的插入点
- (vla-put-TextString b (rtos h 2 len))
- )
- )
- )
- )
- (_endundo acdoc)
- ; ))
- (prin1)
- )
|