3dwannab 发表于 2022-7-5 15:00:42

自动选择上一个对象a

你好
 
我希望加载一个lsp文件,然后在另一个例程中通过(c:runthislispfile)调用它,将它们结合在一起。
 
问题是,它们会提示选择,所以我认为这会起作用:
(command "_P")
(while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
 
这可能吗?我很确定cmdactive技巧就是这样。
 
请参阅下面的代码和问题所在的注释:
(defun c:---BB (/) (progn (LOAD "3dwannab_ByBlock_Change_Entities") (C:BB)))

; Change all selected entities to ByBlock and layer 0 & more.

(defun c:BB ( / ss_1 )

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
        (setq ss_1 (last (ssgetfirst)))
        (if (not ss_1)
                (setq ss_1 (ssget '((0 . "~HATCH"))))
                )
        (if ss_1
                (progn

                        (command "._chprop" "_non" ss_1 "" "_LA" "0" "")
                        (command "._chprop" "_non" ss_1 "" "_LT" "BYBLOCK" "")
                        (command "._chprop" "_non" ss_1 "" "_LTS" "1" "")
                        (command "._chprop" "_non" ss_1 "" "_LW" "BYBLOCK" "")
                        (command "._chprop" "_non" ss_1 "" "_TR" "BYBLOCK" "")
                        (command "._chprop" "_non" ss_1 "" "_C" "BYBLOCK" "")

                        ;; How do I run the command for this lisp then select previous and run it automatically.
                        ;; Below doesn't work.
                        ;; This routine is for rounding off entities to the nearest 0.5mm.
                        (prompt "\nRUN the F5 command also to round off to 0.5mm ?\n")
                        (load "FX_Round_Numbers_0Point5")
                        (progn
                                (c:F5)
                                (command "_P")
                                (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
                                )

                        ;; How do I run the command for this lisp then select previous and run it automatically.
                        ;; Below doesn't work.
                        ;; This is the PSIMPLE command to fix polylines. Again it prompts for a selection here.
                        (prompt "\nRUN the PSIMPLE command also ?\n")
                        (load "PSimple")
                        (progn
                                (c:PSIMPLEV)
                                (command "_P")
                                (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
                                )

                        (setq ss_1 nil)
                        )
                (princ "\nUser Cancelled Command\n")
                )
        )

(*error* nil)
(princ)
)

(defun SS:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
        (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
        (princ (strcat "\n<< Error: " errmsg " >>\n"))
        )
(setvar 'cmdecho cmde)
(setvar 'osmode os)
(setvar 'orthomode orthom)
)

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

(vl-load-com)

(princ
(strcat
        "\n3dwannab_ByBlock_Change_Entities.lsp Loaded\n"
        "\nInvoke by typing 'BB'\n"
        )
)
(princ)

;;----------------------------------------------------------------------;;
;;                           End of File                              ;;
;;----------------------------------------------------------------------;;

tombu 发表于 2022-7-5 15:23:41

你有PSIMPLE的代码吗?它对预选的多段线有效吗?如果是这样
(sssetfirst nil (ssget "P"))应该有效。
 
另一种选择:http://forums.augi.com/showthread.php?81175-选择结果lisp修改#5

3dwannab 发表于 2022-7-5 15:57:12

 
含糖的我在别处需要这个。非常感谢。
 
PSIMPLE是一个惊人的惯例。去掉那些讨厌的非闭合多段线。正如你所见,我调用了输出结果的详细方法。
http://www.theswamp.org/index.php?topic=19865.msg244786#msg244786
 
工作代码:
(defun c:---BB (/) (progn (LOAD "3dwannab_ByBlock_Change_Entities") (C:BB)))

; Change all selected entities to ByBlock and layer 0 & more.

(defun c:BB ( / ss_1 e i )

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
        (setq ss_1 (last (ssgetfirst)))
        (if (not ss_1)
                (setq ss_1 (ssget '((0 . "~HATCH"))))
                )
        (if ss_1
                (progn

                        (repeat (setq i (sslength ss_1))
                                (setq i (1- i))
                                (if (= "HATCH" (cdr(assoc 0 (ENTGET (setq e (ssname ss_1 i))))))
                                        (SSDEL e SS_1 ))
                                )

                        (command "._chprop" "_non" ss_1 "" "_LA" "0" "")
                        (command "._chprop" "_non" ss_1 "" "_LT" "BYBLOCK" "")
                        (command "._chprop" "_non" ss_1 "" "_LTS" "1" "")
                        (command "._chprop" "_non" ss_1 "" "_LW" "BYBLOCK" "")
                        (command "._chprop" "_non" ss_1 "" "_TR" "BYBLOCK" "")
                        (command "._chprop" "_non" ss_1 "" "_C" "BYBLOCK" "")

                        ;; initget from LeeMac help pages
                        (initget "Yes No")
                        (setq ans
                                (cond
                                        (
                                                (getkword
                                                        (strcat "\nLoad FX_Round_Numbers_0Point5 and run ?\n: --------------------------------------------------------- :\nWill round off everything to the nearest 0.5\n: --------------------------------------------------------- :\n <"
                                                                (setq ans
                                                                        (cond ( ans ) ( "Yes" ))
                                                                        )
                                                                ">: "
                                                                )
                                                        )
                                                )
                                        ( ans )
                                        )
                                )

                        (cond
                                ((="Yes" ans)
                                        (progn
                                                (prompt "\nNow running the 0.5mm round off command also...\n-------------------------------------\n")
                                                (load "FX_Round_Numbers_0Point5")
                                                (sssetfirst nil (ssget "_P"))
                                                (c:F5)
                                                )
                                        )
                                ((= "No" ans)
                                        (princ (strcat "\n: --------------------------------------------------------- :\nFX_Round_Numbers_0Point5.lsp not performed.\n: --------------------------------------------------------- :\n"))(princ)
                                        )
                                )

                        (repeat (setq i (sslength ss_1))
                                (setq i (1- i))
                                (if (/= "LWPOLYLINE" (cdr(assoc 0 (ENTGET (setq e (ssname ss_1 i))))))
                                        (SSDEL e SS_1 ))
                                )

                        (if (> (sslength SS_1) 0)
                                (progn
                                        (prompt "\nNow running the PSIMPLEV command also...\n-------------------------------------\n")
                                        (load "PSimple")
                                        (sssetfirst nil (ssget "_P"))
                                        (c:PSIMPLEV)
                                        )
                                (progn
                                        (princ (strcat "\nNo LWPOLYLINEs' found.\n: --------------------------------------------------------- :\n"))(princ)
                                        )
                                )

                        (setq ss_1 nil)
                        (command "._regenall")
                        )
                (princ "\nUser Cancelled Command\n")
                )
        )

(*error* nil)
(princ)
)

(defun SS:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
        (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
        (princ (strcat "\n<< Error: " errmsg " >>\n"))
        )
(setvar 'cmdecho cmde)
(setvar 'osmode os)
(setvar 'orthomode orthom)
)

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

(vl-load-com)

(princ
(strcat
        "\n3dwannab_ByBlock_Change_Entities.lsp Loaded\n"
        "\nInvoke by typing 'BB'\n"
        )
)
(princ)

;;----------------------------------------------------------------------;;
;;                           End of File                              ;;
;;----------------------------------------------------------------------;;

3dwannab 发表于 2022-7-5 16:14:25

更新了上述代码。这将是编辑块时的救命稻草。我似乎把所有的时间都花在了区块编辑器上。。!!!
 
页: [1]
查看完整版本: 自动选择上一个对象a