LispNovice Posted January 5, 2011 Share Posted January 5, 2011 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 Quote Link to comment Share on other sites More sharing options...
JPlanera Posted January 5, 2011 Share Posted January 5, 2011 Use this to select the block "TITLE" in the drawing (setq bEnt (sssetfirst nil (ssget "_x" '((0 . "INSERT") (2 . "Title"))))) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2011 Share Posted January 5, 2011 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) ) Quote Link to comment Share on other sites More sharing options...
JPlanera Posted January 5, 2011 Share Posted January 5, 2011 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???..... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2011 Share Posted January 5, 2011 When is your next teaching session, Lee???..... lol anytime If you have a question, just ask Quote Link to comment Share on other sites More sharing options...
LispNovice Posted January 5, 2011 Author Share Posted January 5, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.