Jump to content

Getting to a block's attributes using the block name


LispNovice

Recommended Posts

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...