获得拉伸的测量结果

问题描述 投票:0回答:1

我正在创建一个算法来帮助我将盒子扩大到正确的大小,如是。

inteded result

我做了一个代码,要求两个点作为新的深度,并测量它们。然后减去块的原始深度(0.51),然后要求边拉伸。

(defun mystretchh ( dis / pt1 pt2 sel )
    (while
        (and
            (setq pt1 (getpoint "\nFirst point of selection window: "))
            (setq pt2 (getcorner pt1 "\nSecond point of selection window: "))
            (not (setq sel (ssget "_C" pt1 pt2)))
        )
        (princ "\nNo objects where found in the selection window.")
    )
    (if sel
        (progn
            (command "_.stretch" sel "" "_non" '(0 0) "_non" (list dis 0))
            t
        )
    )
)
(defun c:test (/ a x c p)
;ungroup
(command "pickstyle" 0)
;variables
(initget (+ 1 2 4))
(setq p (getpoint "\nSelect first point: "))
(setq c (getpoint "\nSelect second point: "))
(command "_.dist" p c)
(setq x (rtos (getvar 'distance) 2 3))


    ;calculate distance to stretch
    (setq a (- x 0.51))


    ;stretch
    (mystretchh a)

    ;regroup
    (command "pickstyle" 1)
    (print "Module modified.")
    (princ)
)

我有两个问题。

  1. 拉伸是反向的,我试过用负值,但没有用。
  2. 它报告了一个语法错误,但我找不到它。

我已经有半年没碰AutoLISP了--也许你们中有人能在一瞬间找到问题。

lisp autocad stretch autocad-plugin autolisp
1个回答
1
投票

你可以计算两点之间的距离,用标准的 distance 函数,而不是调用 DIST 命令,然后再检索 DISTANCE 系统变量。

因此,这。

(command "_.dist" p c)
(setq x (rtos (getvar 'distance) 2 3))

可以变成:

(setq x (rtos (distance p c) 2 3))

但是,你收到的是一个语法错误 因为你把距离转换成了一个字符串,使用的是 rtos,然后你试图在这里对字符串进行运算。

(setq a (- x 0.51))

没有必要将距离转换为字符串 所以这些表达式可以变成:

(setq a (- (distance p c) 0.51))

你可能还想检查一下 (distance p c) 大于 0.51 以避免意外的结果。

要确定适当的方向,因为您当前的代码只能沿 x 轴延伸,您需要检查点的 x 坐标是否是 p 比点的大 c.

© www.soinside.com 2019 - 2024. All rights reserved.