乐筑天下

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

[编程交流] Getting to a block's attr

[复制链接]

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 09:56:41 | 显示全部楼层 |阅读模式
As my username indicates, I'm totally new to Lisp and AutoCAD.  I'm a former VB/VBA developer and I'm trying to transition to Lisp to automate some tasks that are done manually now.
 
I've managed to modify some code I found on a discussion site to accomplish what I set out to do, but I'd like to tweak it a bit more to make it easier for the user.
 
A bit of background.  The drawings that will use this routine will ALWAYS contain a block named Title (the Titleblock block), which will ALWAYS have an attribute named Jobno (the job number for the drawing).  
 
The attached Lisp routine allows the user to select the block, assigns the value of the Jobno attribute to a variable, and opens an Access database using the variable as a command line parameter to the Access database which gets some job number information from a SQL database.  Very straightforward, just what they needed.
 
But I would like to eliminate the step of having to select the block.  As I said, the block named Title will always be the block that will be used, there will always be only one of these in the drawing, and there will always be an attribute named Jobno.
 
How could my Lisp routine be modified to eliminate the Select and get the block object automatically?  Please be as detailed as possible, I'm learning as I go!
 
Thanks in advance for any help.
 
P.S.  I copied this code from somewhere and deleted most of what it did previously.  I realize I no longer need the parameters for the function, but just haven't removed them yet.
SonarLetter.LSP
回复

使用道具 举报

12

主题

119

帖子

107

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 10:09:36 | 显示全部楼层
Use this to select the block "TITLE" in the drawing
  1. (setq bEnt (sssetfirst nil (ssget "_x" '((0 . "INSERT") (2 . "Title")))))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:21:50 | 显示全部楼层
Maybe something like this if I understand you correctly:
 
  1. (defun c:test ( / ss attval ) (vl-load-com) (if   (and (setq ss (ssget "_X" '((0 . "INSERT") (2 . "Title") (66 . 1))))     (setq attval       (vl-some         (function           (lambda ( attrib )             (if (eq "JOBNO" (strcase (vla-get-TagString attrib)))               (vla-get-TextString attrib)             )           )         )         (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)       )     )   )   (startapp "C:\\Program Files\\Microsoft Office\\Office12\\MSACCESS.EXE V:\\GISIII\\AppTabs\\AcBin\\EDocument\\Sonarauto.mdb /cmd" attval) ) (princ))
回复

使用道具 举报

12

主题

119

帖子

107

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 10:34:47 | 显示全部楼层
 
When is your next teaching session, Lee???.....
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:49:54 | 显示全部楼层
 
lol anytime  If you have a question, just ask
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 11:06:24 | 显示全部楼层
Thank you both for the quick responses.
 
I tried the first suggestion, replacing this line of code
 
     (setq bEnt (car (entsel "\nSelect Block: ")))
 
with the suggested code
 
and got this error:
 
; error: bad argument type: lentityp (nil )
 
Then I ran the test function and it worked perfectly.  
 
But, Lee, would it be possible for you to modify your code to fit into my original routine?  Could you give me a statement that would replace the selection statement?
 
Thanks again.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-7 00:31 , Processed in 0.513170 second(s), 64 queries .

© 2020-2025 乐筑天下

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