Cylis0509 发表于 2022-7-5 19:06:18

 
Satishrajdev,
 
所以我试着应用你的方法,它似乎对我不起作用,我百分之百肯定,因为我做得不对。
 
您将看到,我已经注释掉了请求radius的原始代码,并尝试了您的方法。我显然做得不对。。。
 

;;; JMPR.lsp
;;;
;;; Description
;;; Jumper will auto-create the radius jump for pipe crossings.
;;;
;;; Author: Lee Mac (CADTutor)
;;; Date: 03/25/10
;;;
;;; Revision: 1
;;; Revision Date: 10/30/15
;;; Description - Modified by David Prontnicki
;;; Added the ability to select your radius at the beginning of the command.
;;; Changed interface verbage
;;;
;;; Command: JMPR
;;; -----------------------------------------------------------------------------;

(defun c:jmpr (/ *error* A AENT B1 B2 BDISA BDISB BENT DOC ENT OV P1 P2 UFLAG VL O W)

;(setq bDis (getreal "\n Enter new value for Jump Radius: ")) ; Modified by David Prontnicki

(setq bDisa bDisb)
(setq bDisb (getreal (strcat "\n Enter new value for Jump Radius "
                (if (not bDisa)
                  ": "
                  (strcat "<" (itoa bDisa) ">: ")
                )
        )
)
)
(if (and (not bDisb) bDisa)
(setq bDisb bDisa)
)

(defun *error* (msg)
   (and uFlag (vla-EndUndoMark doc))
   (and ov(mapcar (function setvar) vl ov))
   (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
                (princ (strcat "\n** Error: " msg " **"))))
   (princ))

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
       vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl))
(setvar "PEDITACCEPT" 1)

(while (and (setq uFlag (not (vla-StartUndoMark doc)))
             (mapcar   (function setvar) (cdr vl) '(0 32))
             (setq p1(getpoint "\nPick the crossing intersection: ")) ; Modified by David Prontnicki
             (setq ent (entsel "\nSelect the line to break: "))) ; Modified by David Prontnicki

   (setq p2 (osnap (cadr ent) "_nea")
         b1 (polar p1 (setq a (angle p1 p2)) bDisb)
         b2 (polar p1 (+ pi a) bDisb))
   
   (setvar "OSMODE" 0)
   (command "_.break" b1 b2)
   (setq bEnt (entlast))
   (if (> a (/ pi 2.))
   (command "_.arc" b2 "_E" b1 "_A" 180.)
   (command "_.arc" b1 "_E" b2 "_A" 180.))
   (setq aEnt (entlast))

   (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent))))))
   (progn
       (setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent))))
       (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "")
       (vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w)))

   (setq uFlag (vla-EndUndoMark doc)))

(*error* nil)
(princ))

 
提前谢谢!

Lee Mac 发表于 2022-7-5 19:10:37

 
原因是您已将符号“bDis”声明为局部变量,因此该变量的范围仅限于c:jmpr函数;因此,每次计算c:jmpr函数时,“bDis”符号的一个新值被推送到堆栈上。
 
还要注意的是,变量“bDis”在提供给getreal函数的第一个有效输入之后将变成double,因此,itoa函数将失败-这应该是rtos。

Lee Mac 发表于 2022-7-5 19:17:33

FWIW,这里有另一种写它的方法,它可能更容易理解,变量“bDis”仍然是局部的:
(if (null myglobalvariable)
   (setq myglobalvariable 1.0)
)
(if (setq bDis (getreal (strcat "\nJump Radius <" (rtos myglobalvariable) ">: ")))
   (setq myglobalvariable bDis)
   (setq bDis myglobalvariable)
)

Cylis0509 发表于 2022-7-5 19:17:50

 
李·麦克,
 
你就是那个男人!谢谢你,也谢谢你解释它背后的理论。这意味着很多,真的帮助我学习。非常感谢。

satishrajdev 发表于 2022-7-5 19:24:25

 
我使用了GETINT,所以我使用了一个函数将整数转换为字符串。从GETREAL中,您将得到实数,从将其转换为字符串中,您必须使用RTOS。
 
如果您保留任何输入以供将来参考,那么您不应该像李先生提到的那样将其本地化。
(/ *error* A AENT B1 B2 BDISA BDISB BENT DOC ENT OV P1 P2 UFLAG VL O W)
 
您的代码在此处更新:-
;;; JMPR.lsp
;;;
;;; Description
;;; Jumper will auto-create the radius jump for pipe crossings.
;;;
;;; Author: Lee Mac (CADTutor)
;;; Date: 03/25/10
;;;
;;; Revision: 1
;;; Revision Date: 10/30/15
;;; Description - Modified by David Prontnicki
;;; Added the ability to select your radius at the beginning of the command.
;;; Changed interface verbage
;;;
;;; Command: JMPR
;;; -----------------------------------------------------------------------------;

(defun c:jmpr (/ *error* A AENT        B1 B2 BDIS BENT        DOC ENT        OV P1 P2 UFLAG
       VL O W)

;(setq bDis (getreal "\n Enter new value for Jump Radius: ")) ; Modified by David Prontnicki

(setq        bDis (getreal (strcat "\n Enter new value for Jump Radius "
                      (if (not (setq bDisa bDis))
                        ": "
                        (strcat "<" (rtos bDisa) ">: ")
                      )
              )
   )
)
(if (and (not bDis) bDisa)
   (setq bDis bDisa)
)

(defun *error* (msg)
   (and uFlag (vla-EndUndoMark doc))
   (and ov (mapcar (function setvar) vl ov))
   (and msg
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
   (princ (strcat "\n** Error: " msg " **"))
)
   )
   (princ)
)

(setq        doc (vla-get-ActiveDocument (vlax-get-acad-object))
vl'("PEDITACCEPT" "CMDECHO" "OSMODE")
ov(mapcar (function getvar) vl)
)
(setvar "PEDITACCEPT" 1)

(while (and (setq uFlag (not (vla-StartUndoMark doc)))
      (mapcar (function setvar) (cdr vl) '(0 32))
      (setq p1 (getpoint "\nPick the crossing intersection: "))
                                ; Modified by David Prontnicki
      (setq ent (entsel "\nSelect the line to break: "))
)                                ; Modified by David Prontnicki

   (setq p2 (osnap (cadr ent) "_nea")
b1 (polar p1 (setq a (angle p1 p2)) bDis)
b2 (polar p1 (+ pi a) bDis)
   )

   (setvar "OSMODE" 0)
   (command "_.break" b1 b2)
   (setq bEnt (entlast))
   (if        (> a (/ pi 2.))
   (command "_.arc" b2 "_E" b1 "_A" 180.)
   (command "_.arc" b1 "_E" b2 "_A" 180.)
   )
   (setq aEnt (entlast))

   (if        (eq "LWPOLYLINE"
    (cdr (assoc 0 (entget (setq ent (car ent)))))
)
   (progn
(setq w        (vla-get-ConstantWidth
          (setq o (vlax-ename->vla-object ent))
        )
)
(command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "")
(vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w)
   )
   )

   (setq uFlag (vla-EndUndoMark doc))
)

(*error* nil)
(princ)
)

Lee Mac 发表于 2022-7-5 19:27:28

 
非常欢迎你Cylis0509,很乐意帮忙。
页: 1 [2]
查看完整版本: 记住用户输入以备将来使用