Paul Mc Posted March 10, 2009 Share Posted March 10, 2009 Was wondering if someone can help me out with a little routine which would extract the value "elevation" from a selected block and create a point at the insertion of the particular block. I have a drawing with blocks showing the elevation of the ground at certain areas and I need to create a TIN of the ground. Any help would be greatly appreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 10, 2009 Share Posted March 10, 2009 Do you want to have to select every block, or have them selected automatically? (if automatically, could you provide the exact block name). Also, I am assuming that "elevation" is the attribute tag name? thanks Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 10, 2009 Share Posted March 10, 2009 Try this for starters (untested and written quickly): (defun c:ept (/ vlst ovar ss elst att zval pt ptlst) (setq vlst '("CMDECHO" "OSMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0 0)) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "[b][color=Red]BNAME[/color][/b]") (cons 66 1) (if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq elst (mapcar 'cadr (ssnamex ss))) (foreach ent elst (setq att (entnext ent)) (while (not (eq "SEQEND" (cdadr (entget att)))) (if (eq "ELEVATION" (cdr (assoc 2 (entget att)))) (setq zval (atof (cdr (assoc 1 (entget att)))))) (setq att (entnext att))) (setq pt (cdr (assoc 10 (entget ent))) ptlst (cons (subst zval (last pt) pt) ptlst))) (mapcar '(lambda (x) (command "_point" x)) ptlst)) (princ "\n<!> No Blocks Found <!>")) (mapcar 'setvar vlst ovar) (princ)) Make sure you put your block name in the highlighted part. Quote Link to comment Share on other sites More sharing options...
Paul Mc Posted March 11, 2009 Author Share Posted March 11, 2009 Thanks for the help. Unfortunately the script does not work. It will execute but ends right after it is run. Thanks again, Paul Quote Link to comment Share on other sites More sharing options...
CarlB Posted March 11, 2009 Share Posted March 11, 2009 Did you edit the routine from Lee, to put the name of the block in place of the red BNAME? Lee would have put the block name in there, but he's not such a good mind reader Quote Link to comment Share on other sites More sharing options...
eldon Posted March 11, 2009 Share Posted March 11, 2009 Have you got your Points set to a mode and size that shows up? Perhaps a PDMODE and PDSIZE could be incorporated into the routine. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 11, 2009 Share Posted March 11, 2009 With PDMODE incorporated. (defun c:ept (/ vlst ovar ss elst att zval pt ptlst) (setq vlst '("CMDECHO" "OSMODE" "PDMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0 0 3)) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "[color=Red][b]BNAME[/b][/color]") (cons 66 1)(if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq elst (mapcar 'cadr (ssnamex ss))) (foreach ent elst (setq att (entnext ent)) (while (not (eq "SEQEND" (cdadr (entget att)))) (if (eq "ELEVATION" (cdr (assoc 2 (entget att)))) (setq zval (atof (cdr (assoc 1 (entget att)))))) (setq att (entnext att))) (setq pt (cdr (assoc 10 (entget ent))) ptlst (cons (subst zval (last pt) pt) ptlst))) (mapcar '(lambda (x) (command "_point" x)) ptlst)) (princ "\n<!> No Blocks Found <!>")) (mapcar 'setvar vlst ovar) (princ)) Quote Link to comment Share on other sites More sharing options...
Hardeight Posted March 11, 2009 Share Posted March 11, 2009 AVALUE ;THE FUNCTION BELOW - Returns the value of an attribute;SYNTAX (SETQ VARIABLENAME (AVALUE BLOCKNAME "ATTRIBUTENAME")) (defun avalue (bname aname) (setq cnt 0) (setq ent bname) (while (= cnt 0) (setq ent (entnext ent)) (setq entl (entget ent)) (setq entn (cdr (assoc 2 entl))) (if (equal entn aname) (progn (setq cnt 1) (setq aval (cdr (assoc 1 entl))) );progn ); if ); while ); avalue NAVALUE;THE FUNCTION BELOW - Changes value of an attribute to a new value; SYNTAX (NAVALUE BLOCKNAME "ATTRIBUTETAG" NEWVALUE) (defun navalue (bname aname naval) (setq cnt 0) (setq ent bname) (while (= cnt 0) (setq ent (entnext ent)) (setq entl (entget ent)) (setq entn (cdr (assoc 2 entl))) (if (equal entn aname) (progn (setq cnt 1) (setq entl (subst (cons 1 naval) (assoc 1 entl) entl)) (entmod entl) );progn ); if ); while ); navalue Gets and replaces block attributes. Could be helpful. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 11, 2009 Share Posted March 11, 2009 Thank you for the code HardEight, but I think the OP wanted to put a point at the block insertion point, with z-coordinate taken from the block attribute, and didn't want to replace any attributes. Quote Link to comment Share on other sites More sharing options...
Hardeight Posted March 11, 2009 Share Posted March 11, 2009 Ok, I see, hmmm.. Well maybe he can easily get the Z point with AVALUE, (setq inspoint (avalue BNAME "ELEVATION)) of course, he would have to have his blocks sorted by the attribute he was trying to extract... I just love those little routines when trying to get info from blocks, so whenever i get a chance to use them I do 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.