3dwannab 发表于 2022-7-5 13:20:57

Hatch_关闭。lsp-HAT脚本

你好
 
曾经对必须打开“图案填充”对话框才能从现有图案填充中获取固有的道具感到恼火,然后AutoCAD似乎认为图案填充也可以非关联!!!
 
这是我写的一个脚本,我想和大家分享。它只是使用addselected命令来填充选定对象,即使它们可能是非关联的,这将确保终身使用关联图案填充。。。。。。。。
 
它适用于您可以抛出的每种图案填充类型(Anno和背景),同时保留所有完全相同的属性。
我需要得到它,这样它将添加注释比例,但如果源图案填充是注释性的,脚本将为其设置标志。
 
 
现在请告诉我你认为或不认为这件事。
 
 
;; 函数语法
 
Hatch_Off或HOFF
 
;; 关于/注释
;; ABOUT / NOTES
;; - Hatches using ADDSELECTED command method, no more Hatch UI (EVER) to pick an existing HATCH.
;; - Automatically changes the HPASSOC variable to 1 then sets it back,
;;   upon error or exiting the command.
;; - First pick the HATCH you want then, select your LWPOLYLINES, CIRCLES or ELLIPSES to HATCH.
;;   This routine is made to only select closed LWPOLYLINES. An easy way to identify them.
;;   You can run a script called PSIMPLE to fix you entire drawing in one go. See here >>> http://www.theswamp.org/index.php?topic=19865.msg244786#msg244786
;; - If you want un-associative HATCH for some reason change '(setvar 'hpassoc 1)' to '0'.
;; - Automatically selects the newly created HATCH/es.
;; - Sends draworder of HATCH behind selected objects.
 
;; 完整代码

;; --------------------------=={ Hatch_Off }==----------------------------
;; -----------------------------------------------------------------------

;; AUTHOR & ADDITIONAL CODE
;; Author:                                        3dwannab, Copyright © 2018.
;; Error functions:                        LeeMac Help pages. www.lee-mac.com.

;; ABOUT / NOTES
;; - Hatches using ADDSELECTED command method, no more Hatch UI (EVER) to pick an existing HATCH.
;; - Automatically changes the HPASSOC variable to 1 then sets it back,
;;   upon error or exiting the command.
;; - First pick the HATCH you want then, select your LWPOLYLINES, CIRCLES or ELLIPSES to HATCH.
;;   This routine is made to only select closed LWPOLYLINES. An easy way to identify them.
;;   You can run a script called PSIMPLE to fix you entire drawing in one go. See here >>> http://www.theswamp.org/index.php?topic=19865.msg244786#msg244786
;; - If you want un-associative HATCH for some reason change '(setvar 'hpassoc 1)' to '0'.
;; - Automatically selects the newly created HATCH/es.
;; - Sends draworder of HATCH behind selected objects.

;; FUNCTION SYNTAX
;; Short-cut                                HOFF
;; Long-cut                                        Hatch_Off

;; VERSION                                        DATE                        INFO
;; Version 1.0                                26-07-2018                Initial release.
;; Version 1.01                                27-07-2018                var_hatch_bkgcolouradded to set the hatch background colour to none so that the addselected command doesn't use that instead of the original one picked.

;; TO DO LIST
;; Change the polylines to the current boundary attributes of selected hatch boundary.
;; Put all of the annotative scales to the newly created hatch.
;; If a hatch exists on the selected polylines then delete them and hatch with new.
;; Check if it works in different UCS modes. (NOT SURE)

;; -----------------------------------------------------------------------
;; ---------------------=={ Hatch_Off START }==---------------------------

(defun c:---LOAD_HATCH_OFF (/) (LOAD "Hatch_Off") (c:HOFF))

(defun c:HOFF () (c:Hatch_Off))

(defun c:Hatch_Off ( /
*error*
ent_1
ent_1_vla
ent_1_data
sel_me
ss_1
tmp
var_cmde
var_hatch_ass
var_hatch_bkgcolour
var_os
)

(setq *error* LM:error)
(LM:startundo)

(setq var_cmde (getvar "cmdecho"))
(setq var_hatch_anno (getvar "hpannotative"))
(setq var_hatch_ass (getvar "hpassoc"))
(setq var_hatch_bkgcolour (getvar "hpbackgroundcolor"))
(setq var_os (getvar "osmode"))
(setvar 'cmdecho 0)
(setvar 'osmode 0)
(setvar 'hpbackgroundcolor ".")

(while
(not
        (and
                (setq
                        ent_1 (car (entsel "\nPlease select a HATCH to copy.\n: ------------------------------ :\n\nThen select any closed LWPOLYLINE's, CIRCLE's or ELLIPSE's.\n"))
                        ent_1_data (if ent_1 (entget ent_1))
                        )
                (= (cdr (assoc 0 ent_1_data)) "HATCH")
                (sssetfirst nil)
                (setq ent_1_vla (vlax-ename->vla-object ent_1))

                (progn
                        (setq ent_last (entlast)
                                sel_me (ssadd)
                                )
                        (while (setq tmp (entnext ent_last)) (setq ent_last tmp))

                        (princ "\nNow select your objects to be HOFF'ified !\n")

                        (setq ss_1 (ssget '(
                                (-4 . "<OR")
                                (-4 . "<AND") (0 . "LWPOLYLINE") (70 . 1) (-4 . "AND>")
                                (-4 . "<AND") (0 . "CIRCLE,ELLIPSE") (-4 . "AND>")
                                (-4 . "OR>")
                                )))

                        (if        (IsAnno-p (vlax-ename->vla-object ent_1))
                                (setvar 'hpannotative 1)
                                )
                        (setvar 'hpassoc 1)

                        (if ss_1
                                (progn
                                        (command "_.addselected" "_non" ent_1 "_S" ss_1 "" "" )
                                        (command "._draworder" (entlast) "" "_U" ss_1 "")
                                        (while (setq ent_last (entnext ent_last))
                                                (ssadd ent_last sel_me)
                                                )
                                        (sssetfirst nil sel_me)
                                        (princ (strcat "\nYou've been HOFF'd with < "(itoa (sslength ss_1)) (if (> (sslength ss_1) 1) " > objects" " object") " hatched.\n"))
                                        )
                                )
                        )(princ)
                        )
        )
)

(*error* nil)(princ)

)(princ)

;; -----------------------------------------------------------------------
;; ----------------------=={ Functions START }==--------------------------

(vl-load-com)

(defun IsAnno-p (ent / exd ano)
(vl-load-com)
(and (eq (vla-get-HasExtensionDictionary ent) :vlax-true)
        (setq exd (vla-GetExtensionDictionary ent)
                exd (vla-item exd "AcDbContextDataManager")
                ano (vla-item exd "ACDB_ANNOTATIONSCALES")
                )
        (not (zerop (vla-get-Count ano)))
        )
)

(defun LM:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
        (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
        (princ (strcat "\n<< Error: " errmsg " >>\n"))
        )
(setvar 'cmdecho var_cmde)
(setvar 'hpassoc var_hatch_ass)
(setvar 'osmode var_os)
(setvar 'hpannotative var_hatch_anno)
(setvar 'hpbackgroundcolor var_hatch_bkgcolour)
(princ (strcat "\nNo HOFF for you today !\n"))
) (princ)

(defun LM:startundo ()
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
) (princ)

;; -----------------------------------------------------------------------
;; -----------------------=={ Functions END }==-- ------------------------

(princ "\nHatch_Off loaded | Version 1.0 | by 3dwannab.\n")
(princ "\nType \"Hatch_Off\" OR \"HOFF\" to run.\n") (princ)

;; -----------------------------------------------------------------------
;; ----------------------=={ Hatch_Off END }==----------------------------
;; EOL

rlx 发表于 2022-7-5 13:55:48

我的工作主要是关于回路和端子连接图,所以我自己很少使用hatch,但它似乎很管用。我唯一想改变的是(这只是一个味道的问题,所以请随意2不同意)和它的外观,你给用户提示选择图案填充和对象谁想要在同一时间被图案填充。所以我的第一个想法是,我是先选择普林还是哈奇?当然,这只是第一次使用,下次你知道。。。对于一个办公室制茶师来说也不错:-)

3dwannab 发表于 2022-7-5 14:17:33

 
非常感谢。我赚的不仅仅是T!!
 
我只是有点理解Lisp程序。
 
我接受了你的建议,并添加了一个对象选择原则。
 
第一个entget提示输入图案填充,屏幕显示如下。
我想遵循获取和继承道具的工作流程。ssget不能在屏幕上显示AFAIK提示。
 

 
将上述代码更新为v1.01。如果设置了该变量,背景色将被覆盖的轻微错误。

3dwannab 发表于 2022-7-5 14:39:26

我试着让它与嵌套图案填充一起工作,这样我也可以选择那些图案填充,但我得到了错误。
 
这是我正在使用的代码片段。

(command "_.addselected" (car (nentsel))) "_S" pause "" "" )
 
页: [1]
查看完整版本: Hatch_关闭。lsp-HAT脚本