乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 64|回复: 16

[编程交流] vlr-dwg-reactor or vlr-docmana

[复制链接]

17

主题

127

帖子

110

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 09:59:43 | 显示全部楼层 |阅读模式
Has anyone successfully used either of these two reactors to initiate some code right after a drawing has been opened? I have a lisp that allows the user to select a template to start a new drawing and this works fine. Once the template drawing is opened, I'd like to have a lisp that displays a dialog where the user can populate various drawing properties which are then stored in custom drawing fields.
 
Here's what I have so far:
 
The code to open the template file:
  1. (defun open_template ()   (load "open_reactor.lsp") ;; Loads the reactor lisp   (c:myreact) ;; Starts the reactor   (vla-activate (vla-add (vla-get-documents (vlax-get-acad-object) template_name)) ;; template_name is obtained in a different subroutine)
 
The reactor code from open_reactor.lsp:
  1. (defun c:myreact ()   (if myreact (vlr-remove myreact))   (setq myreact (vlr-dwg-reactor nil '((:vlr-endDwgOpen . DoAfterOpen))))   (vlr-set-notification myreact 'all-documents))(defun DoAfterOpen ( Caller CmdSet )   (c:load_dwg_props)   (clear_open_react))(defun clear_open_react ()   (if (and (myreact (vlr-added-p myreact))       (vlr-remove myreact)   ))
 
 
I've tried every relevant drawing opening reactor callback for vlr-dwg-reactor and when I couldn't get any of them to work correctly, I then read about vlr-docmanager-reactor and so I tried all the relevant callbacks for that reactor too. Still it never quite works.
 
The load_dwg_props.lsp does get executed for a few of the callbacks but it always executes before the template is completely opened and after entering all the data into the dialog box and clicking the "Update Drawing Data" button, a check of the drawing properties box shows no custom fields . Yet if I run the load_dwg_props.lsp immediately after the drawing finishes opening, all the custom fields are created.
 
So my question is this: Is there any way lisp-wise to accomplish what I'm trying to do? I've read enough to know I could use ObjectARX or VB.NET to do this but since I still don't know LISP that well, I am hesitant to begin learning something that has a much steeper learning curve.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:04:06 | 显示全部楼层
To execute code when a drawing is opened, it's far easier to use the ACADDOC.lsp
回复

使用道具 举报

17

主题

127

帖子

110

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 10:10:14 | 显示全部楼层
Lee,
 
I reread my post and now realize I wasn't clear enough.  In addition to having the load_dwg_props.lsp in my acaddoc.lsp so that it can be executed whenever it is called through c:load_dwg_props, I would also like to have this code executed automatically after the user selects a template to start a new drawing in a separate lisp.  In our templates we are using fields tied to custom drawing properties as the data for our titleblocks.  After opening a template, all fields show as "----" since the custom drawing property has not been loaded yet.  I was just thinking it would be nice if immediately after starting a new drawing from our template lisp the Load Drawing Properties routine start.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:11:43 | 显示全部楼层
Do you have the load_dwg_props loaded & executed in the ACADDOC.lsp?
 
When a user selects a template to start a new drawing, is the ACADDOC.lsp not loaded following this action?
 
Lee
回复

使用道具 举报

17

主题

127

帖子

110

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 10:17:04 | 显示全部楼层
 
Yes to both questions.  The only lisp I don't have loading automatically in my acaddoc.lsp is the open_reactor.lsp.  This is because I only want this to load immediately right before the selected template is opened in a new window.  Then immediately after the template has been opened, the reactor is cleared so that opening other drawings does not fire the reactor.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:21:11 | 显示全部楼层
 
So if the load_dwg_props LISP is set to execute from the ACADDOC.lsp, which is being loaded when the user selects a template to start a new drawing - surely this is accomplishing your goal and the reactor is not needed, no?
回复

使用道具 举报

17

主题

127

帖子

110

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 10:24:12 | 显示全部楼层
There are only two scenarios where I want the load_dwg_props.lsp to run:
 
1) Each time the user runs the new_project.lsp to begin a new drawing
2) The user types "load_dwg_props" in the command line.
 
If I add (c:load_dwg_props) to my acaddoc.lsp then the program runs every time a new drawing is started or every time an existing drawing is opened.  I was thinking the only way to get the load_dwg_props.lsp program to automatically run when a template is opened from the new_project.lsp was to use a reactor.  
 
I hope I'm being clearer.  When I post messages on any message board, I'm always worried that I will either sound stupid or lame
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:29:26 | 显示全部楼层
I'm just trying to offer an alternative route - I would try to avoid reactors where possible, it makes things simpler sometimes.
 
Perhaps use a test condition in the ACADDOC.lsp, i.e.
 
  1. (load "load_dwg_props" nil)(if (and c:load_dwg_props ) (c:load_dwg_props))
 
Lee
回复

使用道具 举报

17

主题

127

帖子

110

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 10:29:58 | 显示全部楼层
Suddenly the lightbulb is coming on
 
So I guess I could have the new_project.lsp set a value for a variable that when tests true in the acaddoc.lsp, the load_dwg_props.lsp gets executed.  Then I could have the load_dwg_props.lsp reset the value of the variable so that it tests false the next time any drawing is opened or started.  Then only the new_project.lsp will set the condition so that the load_dwg_props.lsp initializes.
 
I will play around with this concept and report back my findings.  As always Lee, thanks for your help!!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:33:49 | 显示全部楼层
 
You're welcome
 
I'm just providing the inspiration - you did all the work
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-7 00:34 , Processed in 1.439250 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表