jonthan313 发表于 2022-7-5 18:54:16

选择矩形(多段线)和

我可以用lisp打印到PNG,但在这个过程中,我必须拖动一个矩形窗口来显示我要在其中绘制的内容。(为工作做截图)。我希望能够在顶点内键入命令-->选择多段线-->打印。有没有办法获得两(2)个顶点,左上角和右下角,保存坐标并在plot lisp期间将其放回?
 
非常感谢。

Lee Mac 发表于 2022-7-5 19:00:48

欢迎来到CADTutor jonthan
 
以下示例将提示用户选择LWPolyline对象,并返回顶点范围的左下角和右上角坐标(对于矩形多段线,这对应于左下角和右上角顶点):
您可以从程序中调用上述函数,并将函数返回的点分配给程序中存储绘图窗口点的变量。

jonthan313 发表于 2022-7-5 19:01:24

感谢您的快速回复。我会试试看,如果成功了就告诉你。

jonthan313 发表于 2022-7-5 19:05:23

所以它给了我正确的点,但是我怎么能把这些坐标分配给变量呢?

Lee Mac 发表于 2022-7-5 19:09:14

 
为变量分配函数返回的点,例如:
(if (setq lst (getwindowpoints))
   (setq pt1 (carlst)
         pt2 (cadr lst)
   )
)或:
(mapcar 'set '(pt1 pt2) (getwindowpoints))

jonthan313 发表于 2022-7-5 19:12:43

请跟我说,因为我是新手,仍在学习如何编写Lisp程序,但我不知道在哪里插入代码,你分配的变量。你能帮帮我吗?

Lee Mac 发表于 2022-7-5 19:14:52

您需要发布现有代码。

jonthan313 发表于 2022-7-5 19:20:12

很抱歉,关于如何
正确地编码,它只是一个脚本而不是lisp。我想去掉这两个暂停,并自动从代码中选取点。我需要帮助将你的代码实现到我的代码中。
(defun C:HMI ()

(command "-plot"

;Detailed plot configuration?
"Yes"

;Enter Layout Name
"Model"

;Enter an output device name
"PublishToWeb PNG.pc3"

;Enter Paper Size (User Defined)
"HMI"

;Enter Drawing Orientation
"L"

;Plot Upside Down?
"No"

;Enter Plot Area
"Window"

;Pause the lisp for users input of points
pause
pause

;Enter Plot Scale
"Fit"

;Enter plot offset
"center"

;Plot with Style
"yes"

;Enter plot style table name (none)
"."

;Plot with lineweights?
"yes"

;Enter Shade Plot Settings
"As Displayed"

;Creating plot file and saving
pause

;Save Changes to page setup
"no"

;Proceed with plot
"yes")
)

Lee Mac 发表于 2022-7-5 19:24:04

请尝试以下操作:
(defun c:hmi ( / lst )
   (if (setq lst (getwindowpoints))
       (command
         "_.-plot"
         "_Yes"; Detailed plot configuration?
         "Model" ; Enter Layout Name
         "PublishToWeb PNG.pc3" ; Enter an output device name
         "HMI" ; Enter Paper Size (User Defined)
         "_L"; Enter Drawing Orientation
         "_N"; Plot Upside Down?
         "_W"; Enter Plot Area
         "_non" (carlst)
         "_non" (cadr lst)
         "_F"; Enter Plot Scale
         "_C"; Enter plot offset
         "_Y"; Plot with Style
         "."   ; Enter plot style table name (none)
         "_Y"; Plot with lineweights?
         "As Displayed" ; Enter Shade Plot Settings
         "\\"; Creating plot file and saving
         "_N"; Save Changes to page setup
         "_Y"; Proceed with plot
       )
   )
   (princ)
)

(defun getwindowpoints ( / ent )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect Polyline: ")))
         (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (= 'ename (type ent))
                   (if (/= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
                     (princ "\nPlease select an LWPolyline.")
                   )
               )
         )
       )
   )
   (if ent
       (   (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max)))
         (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))
       )
   )
)
(princ)

jonthan313 发表于 2022-7-5 19:25:07

非常感谢李,你是最棒的!也许我要求的太多了,但是否可以选择多个矩形多段线并用不同的名称分别保存它们?
页: [1] 2
查看完整版本: 选择矩形(多段线)和