sakinen Posted June 28, 2009 Posted June 28, 2009 I started to develop a lisp but i realized it's a little out of ma league so i need some help. This is the desired work flow. I need to insert a specific block named roomtag. This block has an attribute named roomnumber. When i insert this block i need to be prompted to select the room number. Room number can be text, mtext or another attribute. When selected, values of this entities should become roomnumber attribute value. Any ideas? Quote
flowerrobot Posted June 28, 2009 Posted June 28, 2009 Sorry for my ignorance, Isnt what you are asking coming defult? Or do you have alot of attributes and only want to be able to edit that one? (defun c:pen () (defun attget (ss1 / en edata) (if ss1 (progn (setq en (ssname ss1 0)) (setq edata (entget en)) (setq blockdata nil) (setq edata (entget (entnext (cdr (assoc -1 edata))))) (while (not(= (cdr (assoc 0 edata)) "SEQEND")) (setq blockdata (cons (cons (cdr (assoc 2 edata)) (cdr (assoc 1 edata))) blockdata)) (setq edata (entget (entnext (cdr (assoc -1 edata))))) ) ) (progn (alert "Their is no block") (exit) ) ) ) (defun attput (ss1 / en edata) (setq en (ssname ss1 0)) (setq edata (entget en)) (setq edata (entget (entnext (cdr (assoc -1 edata))))) (while (not(= (cdr (assoc 0 edata)) "SEQEND")) (entmod (subst (cons 1 (cdr (assoc (cdr (assoc 2 edata)) blockdata)))(assoc 1 edata) edata)) (setq edata (entget (entnext (cdr (assoc -1 edata))))) ) ) (setq InPoint (getpoint "\nSelect insetion point :")) (Setq TheString (getstring "\nWhat is the room number :")) (setq TheScale (getint "What is the scale of insertion? :")) (setvar "attdia" 0) ;What is the one that turns it off completly? (command "_.Insert" "roomtag" InPoint TheScale TheScale 0) (setq TheEntity (ssget (entlast))) (attget TheEntity) (setq blockdata (subst (cons "roomnumber" TheString) (assoc "roomnumber" blockdata) blockdata)) (attput TheEntity) (princ Block Created) (princ) ) Quote
sakinen Posted June 28, 2009 Author Posted June 28, 2009 Sorry for my ignorance, Isnt what you are asking coming defult? Or do you have alot of attributes and only want to be able to edit that one? I have two attributes but i want to update only one. Quote
sakinen Posted June 28, 2009 Author Posted June 28, 2009 Maybe i did not explain what "select" means. When i'm prompted for room number i want to select text, mtext or some other attribute to get the value for my roomnumber attribute. Quote
flowerrobot Posted June 28, 2009 Posted June 28, 2009 Ahh i see now, Sorry carnt help now the bus is calling me , Neither will the code above be any use This should help you along the way (will get the text out) Nm = entity data (cdr (assoc 1 (entget NM))) Quote
Lee Mac Posted June 29, 2009 Posted June 29, 2009 Try this mate: (defun c:RmNo (/ doc spc str pt Blk gr dat ent) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc)) str "") (if (or (tblsearch "BLOCK" "roomtag") (findfile "roomtag.dwg")) (if (setq pt (getpoint "\nSpecify Point for Block: ")) (progn (setq Blk (vla-insertblock spc (vlax-3D-point pt) "roomtag.dwg" 1. 1. 1. 0.)) (princ "\nSelect or Specify Room Number: ") (vl-catch-all-apply (function (lambda ( ) (while (progn (setq gr (grread t 15 2) dat (cadr gr)) (cond ((and (= 3 (car gr)) (listp dat)) (if (setq ent (car (nentselp dat))) (if (vl-position (cdr (assoc 0 (entget ent))) '("TEXT" "MTEXT" "ATTRIB")) (progn (setq str (vla-get-TextString (vlax-ename->vla-object ent))) nil) (princ "\n** Invalid Object Selected **")) (princ "\n** Nothing Selected **"))) ((= 2 (car gr)) (cond ((<= 32 dat 126) (princ (chr dat)) (setq str (strcat str (chr dat)))) ((= 8 dat) (and (< 0 (strlen str)) (princ (strcat (chr (chr 32) (chr )) (setq str (substr str 1 (1- (strlen str)))))) ((= dat 13) nil))) ((= 25 (car gr)) nil) (t t))))))) (foreach att (append (if (not (vl-catch-all-error-p (setq atArr (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value (vla-GetAttributes Blk))))))) atArr) (if (not (vl-catch-all-error-p (setq caArr (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value (vla-GetConstantAttributes Blk))))))) caArr)) (if (eq "ROOMNUMBER" (strcase (vla-get-TagString att))) (vla-put-TextString att str)))) (princ "\n<< No Point Specified >>")) (princ "\n<< Block Not Found >>")) (princ)) Quote
sakinen Posted June 29, 2009 Author Posted June 29, 2009 Try this mate: (defun c:RmNo (/ doc spc str pt Blk gr dat ent) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc)) str "") (if (or (tblsearch "BLOCK" "roomtag") (findfile "roomtag.dwg")) (if (setq pt (getpoint "\nSpecify Point for Block: ")) (progn (setq Blk (vla-insertblock spc (vlax-3D-point pt) "roomtag.dwg" 1. 1. 1. 0.)) (princ "\nSelect or Specify Room Number: ") (vl-catch-all-apply (function (lambda ( ) (while (progn (setq gr (grread t 15 2) dat (cadr gr)) (cond ((and (= 3 (car gr)) (listp dat)) (if (setq ent (car (nentselp dat))) (if (vl-position (cdr (assoc 0 (entget ent))) '("TEXT" "MTEXT" "ATTRIB")) (progn (setq str (vla-get-TextString (vlax-ename->vla-object ent))) nil) (princ "\n** Invalid Object Selected **")) (princ "\n** Nothing Selected **"))) ((= 2 (car gr)) (cond ((<= 32 dat 126) (princ (chr dat)) (setq str (strcat str (chr dat)))) ((= 8 dat) (and (< 0 (strlen str)) (princ (strcat (chr (chr 32) (chr )) (setq str (substr str 1 (1- (strlen str)))))) ((= dat 13) nil))) ((= 25 (car gr)) nil) (t t))))))) (foreach att (append (if (not (vl-catch-all-error-p (setq atArr (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value (vla-GetAttributes Blk))))))) atArr) (if (not (vl-catch-all-error-p (setq caArr (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value (vla-GetConstantAttributes Blk))))))) caArr)) (if (eq "ROOMNUMBER" (strcase (vla-get-TagString att))) (vla-put-TextString att str)))) (princ "\n<< No Point Specified >>")) (princ "\n<< Block Not Found >>")) (princ)) I tried it but i get this message Specify Point for Block: Block roomtag references itself ; error: Automation Error. Self reference I put the roomtag.dwg file with roomtag block in a folder which i put in a support folders in options. Maybe i'm wrong. Quote
Lee Mac Posted June 30, 2009 Posted June 30, 2009 I tried it but i get this message I put the roomtag.dwg file with roomtag block in a folder which i put in a support folders in options. Maybe i'm wrong. If the roomtag.dwg contains a roomtag block - then there will be a self reference issue. You could open the roomtag.dwg, explode the block within it, and then WBLOCK it to make the block - a much better way to approach things. Quote
sakinen Posted June 30, 2009 Author Posted June 30, 2009 Thanks man. Works like a charm! You rule....!!! This is way out my lisp league. Quote
Lee Mac Posted June 30, 2009 Posted June 30, 2009 Thanks man. Works like a charm! You rule....!!! This is way out my lisp league. Happy to help dude - don't worry, its only practice Quote
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.