cabltv1 Posted January 28, 2009 Share Posted January 28, 2009 Please help. I need an AutoCAD VBA routine that can do the following: 1) Pick an existing block to get it's coordinates. 2) Pick another block and put the first block's coordinates into the picked block's attribute with the tag "PT1". Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 Welcome to CADTutor cabltv1, hope you like it here. This thread may get more replies in the VBA/AutoLISP customisation forum - see if you can get a moderator to move it for you. But - DO NOT DUPLICATE this thread in that forum - get this one moved. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 The actual request shouldn't be too difficult - I'll see what I can do for ya Quote Link to comment Share on other sites More sharing options...
Tiger Posted January 28, 2009 Share Posted January 28, 2009 Your wish is my command Cabltv - is this something that you need to do often or is it a one time thing? Sounds to me like it could be done via exporting the coordinates to Excel and ..then...I'm lost... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 With this you can do one block after another: (defun c:attpt (/ pBlk dBlk ptBlk aEnt aEntLst) (while (and (setq pBlk (car (entsel "\nSelect Block to Retrieve Coordinates > "))) (setq dBlk (car (entsel "\nSelect Destination Block > "))) (= (cdr (assoc 0 (entget pBlk))) "INSERT" (cdr (assoc 0 (entget dBlk)))) (= (cdr (assoc 66 (entget dBlk))) 1)) (setq ptBlk (cdr (assoc 10 (entget pBlk))) aEnt (entnext dBlk)) (while (/= "SEQEND" (cdr (assoc 0 (setq aEntLst (entget aEnt))))) (if (= "PT1" (cdr (assoc 2 aEntLst))) (progn (setq aEntLst (subst (cons 1 (strcat (rtos (car ptBlk) 2 2) "," (rtos (cadr ptBlk) 2 2) "," (rtos (caddr ptBlk) 2 2))) (assoc 1 aEntLst) aEntLst)) (entmod aEntLst))) (setq aEnt (entnext aEnt)))) (command "_regenall") (princ)) Quote Link to comment Share on other sites More sharing options...
cabltv1 Posted January 28, 2009 Author Share Posted January 28, 2009 Thanks Lee. That did the trick! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 No Probs, glad it worked for you If you have any more questions, just ask Quote Link to comment Share on other sites More sharing options...
cabltv1 Posted January 28, 2009 Author Share Posted January 28, 2009 There is one other thing. It works great but I need the function to stop after picking the second block with the "PT1" attribute without having to hit the escape key. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 I'll modify it, but you shouldn't have to hit Esc, just either right-click or hit enter. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 28, 2009 Share Posted January 28, 2009 Here ya go buddy: (defun c:attpt (/ pBlk dBlk ptBlk aEnt aEntLst) (if (and (setq pBlk (car (entsel "\nSelect Block to Retrieve Coordinates > "))) (setq dBlk (car (entsel "\nSelect Destination Block > "))) (= (cdr (assoc 0 (entget pBlk))) "INSERT" (cdr (assoc 0 (entget dBlk)))) (= (cdr (assoc 66 (entget dBlk))) 1)) (progn (setq ptBlk (cdr (assoc 10 (entget pBlk))) aEnt (entnext dBlk)) (while (/= "SEQEND" (cdr (assoc 0 (setq aEntLst (entget aEnt))))) (if (= "SIZE" (cdr (assoc 2 aEntLst))) (progn (setq aEntLst (subst (cons 1 (strcat (rtos (car ptBlk) 2 2) "," (rtos (cadr ptBlk) 2 2) "," (rtos (caddr ptBlk) 2 2))) (assoc 1 aEntLst) aEntLst)) (entmod aEntLst))) (setq aEnt (entnext aEnt))) (command "_regenall"))) (princ)) Quote Link to comment Share on other sites More sharing options...
cabltv1 Posted January 28, 2009 Author Share Posted January 28, 2009 Thanks. I really appreciate your effort. I see your are a "Super Member". What exactly does that mean? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 29, 2009 Share Posted January 29, 2009 I see your are a "Super Member". What exactly does that mean? Only that I have submitted more than 500 posts. See here to understand more: http://www.cadtutor.net/forum/memberlist.php?&order=DESC&sort=posts&pp=30 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.