明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1445|回复: 3

如何能在Lisp打开的图形中获取操作权

[复制链接]
发表于 2009-6-15 22:18:00 | 显示全部楼层 |阅读模式

请教各位大侠:

目的:在A图形中运行Lisp程序,用程序打开B图形并在B图形中操作,保存后关闭B图形,返回A图形继续操作,直至程序运行结束。

问题:程序打开B图形后,接着的程序操作均在A图形中,如何能让程序的操作在B图形中?

 楼主| 发表于 2009-6-15 23:21:00 | 显示全部楼层

我的源程序如下,请指正:

;;打开B图
(defun OpenFile (FilePath Activate / oFile)
(vl-load-com)
  (if (findfile FilePath)
    (if (vl-file-systime FilePath)
      (if (vl-catch-all-error-p
              (setq oFile
                 (vl-catch-all-apply
                   'vla-open
                      (list
                         (vla-get-Documents
                            (vlax-get-acad-object)
                         )
                         FilePath
                      );end-->list
                 );end-->vl-catch-all-apply
              );end-->setq oFile
          );end-->vl-catch-all-error-p
          (alert
             (strcat FilePath " :文件不能够打开!")
          )
          (if Activate
              (vla-Activate oFile))
      ); end if
      (alert;vl-file-systime,此时FilePath为nil
          (strcat FilePath
                     " :已经打开,请关闭文件!\n"
                     "如果文件未打开,则文件可能受保护或已损坏!")
      )
    ); end if
    (alert;findfile = nil
      (strcat FilePath " :文件没有找到!")
    )
  ); end if
  oFile
); end of OpenFile


;;删除B图中的所以文字
(defun Delete-Text (/ ENT I S SS Z)
  (if (setq ss (ssget "x" (list (cons 0 "TEXT"))))
    (progn
      (setq z (sslength ss))
      (setq i 0)
      (repeat z
 (setq s (ssname ss i))
 (entdel s)
 (setq i (1+ i))
      )
    )
  )
  (princ)
);;defun Delete-Text end

;;获取B图的文件名
(defun B-Name(/ ss ent zh)
  (setq ss (ssget "w" '(35 228) '(72.5 264)))
  (setq ent (entget (ssname ss 0)))
  (setq z (cdr (assoc 1 ent)));;;;;;; z = B
  (setq B-name (getvar "dwgprefix"))
  (setq B-name (strcat zh-name z ".dwg"));;; B-name = D:\USER\B.dwg
);;defun B-Name end

;;主函数

(defun c:oFile ()
  (B-Name)
  (OpenFile B-name T)
  (if (findfile B-name)
      (progn
         (Delete-Text)
      )
  )
  (princ)
);;主函数 end

发表于 2009-6-15 23:53:00 | 显示全部楼层
想法不错,我也正想编一个这样的
发表于 2009-7-7 14:57:00 | 显示全部楼层
呵呵——————-强啦
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-2 15:21 , Processed in 0.163546 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表