SunnyTurtle 发表于 2022-7-6 07:21:16

用于输出的2D级lisp

曾经想要斜坡坡度的尺寸。(在二维/平面中绘制时)
我有,所以我创建了这个lisp来节省手动计算和创建一些文本的时间。
; Grade   
;      
;by Robert Condon   
; 13/9/12   
;      
;      
;To use: Select two points from left to
;right and it will give you the
;grade between the points
;      
;      
;      

(defun c:grd ()

(setq p1 (getpoint "\n1st point of Grade:"))

(setq p1X (car p1))

(setq p1Y (cadr p1))

(setq p2 (getpoint "\n2nd point of Grade:"))

(setq p2X (car p2))

(setq p2Y (cadr p2))

(setq rise (- p2Y p1Y))

(setq run (- p2X p1X))

(setq textposY (float
(if(> (+ p1Y p2Y) 0)
    (/ (+ p1Y p2Y) 2 )
    (setq textdisp 0)
      )))

(setq textposX (float(/ (+ p1X p2X) 2 )))

(setq textpos (list textposX textposY 0.0))

(setq trot (angle p1 p2))
(if (> rise 0)
(progn
   (setq rise1a (/ run rise)
)
   (setq rise1 (rtos(/ run rise)
)
   )
)
)
(if (< rise 0)
(progn
   (setq rise1a (/ run rise)
)
   (setq rise1 (rtos(/ run rise)
)
   )
)
)
(if (> run 0)
(setq grade (rtos(* 100 (/ rise run))
)
   )
)
(if (< run 0)
(setq grade (rtos(* 100 (/ rise run))
)
   )
)

(if (>= 9.999 rise1a)
(setq textdisp (strcat "\\pxsa1.4286;" rise1 ":1"))
(setq textdisp (strcat "\\pxsa1.4286;" grade "%"))
)
(if (progn (> 1 rise1a)(< 0 rise1a)
)
(setq textdisp (strcat "\\pxsa1.4286;" "1:" (rtos(* rise1a 100)
) ))
      )
(if (progn (< -1 rise1a)(> 0 rise1a)
)
(setq textdisp (strcat "\\pxsa1.4286;" "1:" (rtos(* rise1a 100)
) ))
      )

(if (= rise 0)
    (progn (setq textdisp "")(princ "\nGrade is flat"))
   )

(if (= run 0)
    (progn (setq textdisp "")(princ "\nGrade is vertical")
      )
   )

;(setq text size (getint "Text size: "))

(entmake (list
   '(0 . "MTEXT")
   '(100 . "AcDbEntity")
   '(67 . 0)
   '(410 . "Model")
   '(100 . "AcDbMText")
   (cons 10 textpos)
   '(40 . 0.5)
   '(41 . 0)
   '(71 .
   '(72 . 5)
   (cons 1 textdisp)
   '(7 . "ISO3098B")
   '(210 0.0 0.0 1.0)
   '(11 1.0 0.0 0.0)
   '(42 . 0.833333)
   '(43 . 4.66667)
   (cons 50 trot)
   '(73 .
   '(44 . 1.0)))
(princ)
)

MSasu 发表于 2022-7-6 07:32:27

第一眼看到两条评论:
[列表]
[*]不确定这是什么“\\pxsa1.4286;”代码的意思是,请验证在显示时似乎被解析为链接(在高级编辑器中有一个“自动解析文本中的链接”选项,您可能想要禁用)。
[*]当选择第二个点作为视觉辅助点时,我想要一条动态线,并且与内置命令兼容:
[/列表]
(setq p2 (getpoint p1 "\n2nd point of Grade:"))

SunnyTurtle 发表于 2022-7-6 07:50:45

这将从插入点偏移文本1.4286。如果你愿意的话,这只是我为periouse lisp删除继承的东西。
 
 
 
 
谢谢你的代码我不知道该怎么做谢谢

BIGAL 发表于 2022-7-6 07:54:28

如果这有助于选择两个点,则Civ3d可以选择坡度标签。

SunnyTurtle 发表于 2022-7-6 08:06:51

 
是,但用于处理MX或12D的2D输出
 
在这方面做了一些工作,以消除我遇到的一些错误
; Grade   
;      
;by Robert Condon   
; 29/10/12   
;      
;      
;To use: Select two points from left to
;right and it will give you the
;grade between the points
;      
;      
;      

(defun c:grd ()

(setq p1 (getpoint "\n1st point of Grade:"))

(setq p1X (car p1))

(setq p1Y (cadr p1))

(setq p2 (getpoint p1 "\n2nd point of Grade:"))

(setq p2X (car p2))

(setq p2Y (cadr p2))

(setq rise (- p2Y p1Y))

(setq run (- p2X p1X))

(setq textposY (float
(if(> (+ p1Y p2Y) 0)
    (/ (+ p1Y p2Y) 2 )
    (setq textdisp 0)
      )))

(setq textposX (float(/ (+ p1X p2X) 2 )))

(setq textpos (list textposX textposY 0.0))

(setq trot (angle p1 p2))
(if (> rise 0)
(progn
   (setq rise1a (/ run rise)
)
   (setq rise1 (rtos(/ run rise)
)
   )
)
)
(if (< rise 0)
(progn
   (setq rise1a (/ run rise)
)
   (setq rise1 (rtos(/ run rise)
)
   )
)
)
(if (> run 0)
(progn
(setq grade (rtos(* 100 (/ rise run))
)
   )
(setq gradeA (* 100 (/ rise run))))
)

(if (< run 0)
(progn
(setq grade (rtos(* 100 (/ rise run))
)
   )
(setq gradeA (* 100 (/ rise run))))
)

(if (cond (< 10 gradeA)(> -10 gradeA))
(setq textdisp (strcat "\\pxsa1.4286;" rise1 ":1"))
)

(if (= nil (< 10 gradeA)(> -10 gradeA))
(setq textdisp (strcat "\\pxsa1.4286;" grade "%"))
)

(if (and(< 100 gradeA)(< 0 gradeA))

(setq textdisp (strcat "\\pxsa1.4286;" "1:" (rtos(* rise1a 100)
) ))
      )
(if (and(> -100 gradeA)(> 0 gradeA))

(setq textdisp (strcat "\\pxsa1.4286;" "1:" (rtos(* rise1a 100)
) ))
      )

(if (= rise 0)
    (progn (setq textdisp "")(princ "ERROR\nGrade is flat"))
   )

(if (= run 0)
    (progn (setq textdisp "")(princ "ERROR\nGrade is vertical")
      )
   )

;(setq text size (getint "Text size: "))

(entmake (list
   '(0 . "MTEXT")
   '(100 . "AcDbEntity")
   '(67 . 0)
   '(410 . "Model")
   '(100 . "AcDbMText")
   (cons 10 textpos)
   '(40 . 0.5)
   '(41 . 0)
   '(71 .
   '(72 . 5)
   (cons 1 textdisp)
   '(7 . "ISO3098B")
   '(210 0.0 0.0 1.0)
   '(11 1.0 0.0 0.0)
   '(42 . 0.833333)
   '(43 . 4.66667)
   (cons 50 trot)
   '(73 .
   '(44 . 1.0)))
(princ)
)

MSasu 发表于 2022-7-6 08:19:09

我注意到这个分配:
良好的编程实践是确保除法运算的至少一部分是实数(双精度),以避免得到舍入结果:
4
(我知道坐标来自GETPOINT ar实数)

SunnyTurtle 发表于 2022-7-6 08:29:21

谢谢你的建议,我会考虑的。但在这种情况下,这并不重要,因为它只需要粗糙
页: [1]
查看完整版本: 用于输出的2D级lisp