LispNovice 发表于 2022-7-6 09:56:41

Getting to a block's attr

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

JPlanera 发表于 2022-7-6 10:09:36

Use this to select the block "TITLE" in the drawing

(setq bEnt (sssetfirst nil (ssget "_x" '((0 . "INSERT") (2 . "Title")))))

Lee Mac 发表于 2022-7-6 10:21:50

Maybe something like this if I understand you correctly:
 

(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))

JPlanera 发表于 2022-7-6 10:34:47

 
When is your next teaching session, Lee???.....

Lee Mac 发表于 2022-7-6 10:49:54

 
lol anytimeIf you have a question, just ask

LispNovice 发表于 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.
页: [1]
查看完整版本: Getting to a block's attr