Trebuchet 发表于 2022-7-5 23:35:39

修订代码-尺寸e

我有以下代码:
 
(defun c:chrdim ()


(setq dl (list '("H" "hor") '("V" "vert") '("A" "aligned")))
(initget "h H v V a A")
(setq mode (strcase (getkword "Enter H, V or A for horiz, vert or aligned dimensions: ")))
(setq mode (cadr (assoc mode dl)))
(setq p1 (getpoint "\nSelect first point: "))
(while (eval 'p1)
    (setq p2 (getpoint "\nSelect second point: "))
    (setq p3 (getpoint "\nSelect dimension line location: "))
    (setq ns (getint "\nNumber of spaces?: "))
    (cond ((= mode "hor")
         (setq d (distance p1 (list (car p2) (cadr p1))))
          )
          ((= mode "vert")
         (setq d (distance p1 (list (car p1) (cadr p2))))
          )
          (T
         (setq d (distance p1 p2))
          )
    )
    (setq s (rtos (/ d ns) 4 3))
    (cond ((> (- d (* ns (distof s 4))) 0.1)
            (setq off "%%p")
         )
         ((> (- (* ns (distof s)) d) 0.1)
            (setq off "%%p")
         )
         (T (setq off ""))
   )
   (setq sdim (strcat (itoa ns) " EQ SP @ "
                        s off)                              
   )
   (command "dim" mode p1 p2 p3 sdim "e")
   (setq p1 (getpoint "\nSelect first point, return to exit: "))
)      
)   
取两点,求差,除以提供的空间数,得出结果。例如,用户在屏幕上选择两个相距35’的点,它们指定10个相等的空间,结果尺寸放置在它们选择的点上,即“10 EQ SP@3'-6”+/-”。
 
它会提示输入所需的等间距,但如果它可以根据最大间距自动提供等间距,那就更好了。可以硬编码或提示最大值。通常最大值是42”。如果默认值为42”,并且能够在需要时更改它,那就太好了。相等空间的数量始终必须是偶数。我有点不知道从哪里开始。有人能给点指导吗?

Trebuchet 发表于 2022-7-6 01:14:56

嗯,花了一些时间在这上面,并找到了答案。有些地方可能很丑陋,但如果有人好奇的话:
 
(defun c:cdim ()


(setq dl (list '("H" "hor") '("V" "vert") '("A" "aligned")))
(initget "h H v V a A")
(setq mode (strcase (getkword "Enter H, V or A for horiz, vert or aligned dimensions: ")))
(setq mode (cadr (assoc mode dl)))
(setq spacing
(cond
   ((getint (strcat "\nEnter default spacing <" (itoa(setq spacing(cond ( spacing ) ( 42 ))))
         ">: "))
   )
   ( spacing )
)
)
(setq p1 (getpoint "\nSelect first point: "))
    (while (eval 'p1)
    (setq p2 (getpoint "\nSelect second point: "))
    (setq p3 (getpoint "\nSelect dimension line location: "))
    (cond ((= mode "hor")
         (setq d (distance p1 (list (car p2) (cadr p1))))
          )
          ((= mode "vert")
         (setq d (distance p1 (list (car p1) (cadr p2))))
          )
          (T
         (setq d (distance p1 p2))
          )
    )
    (setq ns 2)
   (while (>= (/ d ns) spacing)
   (setq ns (1+ ns))
   (setq ns (1+ ns))
   )
    (setq s (rtos (/ d ns) 4 3))
    (cond ((> (- d (* ns (distof s 4))) 0.1)
            (setq off "%%p")
         )
         ((> (- (* ns (distof s)) d) 0.1)
            (setq off "%%p")
         )
         (T (setq off ""))
   )
   (setq sdim (strcat (itoa ns) " EQ SP @ "
                        s off)                              
   )
   (command "dim" mode p1 p2 p3 sdim "e")
   (setq p1 (getpoint "\nSelect first point, return to exit: "))
)      
)   
页: [1]
查看完整版本: 修订代码-尺寸e