vishwaskekane Posted November 29, 2021 Share Posted November 29, 2021 I am using the attached lisp to increment predefined value to East (attributes) Co-ordinates (Russian text and English text). after running this program I am getting the following error------ error: Automation Error. Calling method AddItems of interface IAcadSelectionSet failed also the lisp not working properly. also I need to increment predefined amount in East Co-ordinates, but it is not working properly. Can any one please help me come up with an automated method by attaching Lisp to edit text string with a constant number? Since I have drawings with a lot of coordinates needed to be changed and with the lisp. Test.dwg Increment_All_cords_.lsp Quote Link to comment Share on other sites More sharing options...
hosneyalaa Posted November 30, 2021 Share Posted November 30, 2021 Hi I don't understand what you want If you explain in a video Your text is mtext The Lisp asks for a text (defun c:RUSSCORD (/ ss str) (vl-load-com) (if (setq ss (ssget '((0 . "text") (1 . "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E.*")))); UNICODE FOR RUSSIAN NORTH (foreach str (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ) (vla-put-textstring str (strcat "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E. " (rtos (+ 20000 (atof (substr (vla-get-textstring str) 10))) 2 0)); 20000 IS THE VALUE THAT IS ADDED ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 1, 2021 Share Posted December 1, 2021 (edited) You have 2 blocks so know the name of the blocks you can just remove the alpha from the attribute add an amount to the numeric then recreate the string with correct prefix. I use a lee-mac function to return the numeric value from a string. ;;-------------------=={ Parse Numbers }==--------------------;;` ;; ;; ;; Parses a list of numerical values from a supplied string. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; Edited December 1, 2021 by BIGAL Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted December 1, 2021 Share Posted December 1, 2021 Also notice: the third block from the top has the East coordinate in the wrong attribute Quote Link to comment Share on other sites More sharing options...
vishwaskekane Posted December 1, 2021 Author Share Posted December 1, 2021 23 hours ago, hosneyalaa said: Hi I don't understand what you want If you explain in a video Your text is mtext The Lisp asks for a text (defun c:RUSSCORD (/ ss str) (vl-load-com) (if (setq ss (ssget '((0 . "text") (1 . "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E.*")))); UNICODE FOR RUSSIAN NORTH (foreach str (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ) (vla-put-textstring str (strcat "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E. " (rtos (+ 20000 (atof (substr (vla-get-textstring str) 10))) 2 0)); 20000 IS THE VALUE THAT IS ADDED ) ) ) (princ) ) ;;---------------------------------------RUSSIAN ATTRIBUTES CORDS------------------------------------------------- (defun c:ATTRUSSCORD ( / att str listofblocks listlen count att_tag blkname thestring chklen) (vl-load-com) (setq count 0) (setq listofblocks '( ("GLB_CONT_L" . "EAST_COORD") ("GLB_CONT_R" . "EAST_COORD") ("GLB_CONT_R1" . "EAST_COORD") ) ); alter this table to add or delete BLOCKS. 1st part is BLOCK, 2nd part is the TAG. (setq listlen (length listofblocks)); get the length of the list (while (<= count listlen) (setq blkname (car (nth count listofblocks))) (setq att_tag (cdr (nth count listofblocks))) (if blkname (ssget "X" (list '(0 . "INSERT") (cons 2 blkname) '(66 . 1)) )) (vlax-for item (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)) ) (foreach att (vlax-safearray->list (vlax-variant-value (vla-getattributes item)) ) (if (= att_tag (vla-get-tagstring att)) (progn (setq thestring (vla-get-textstring att)) (setq chklen (strlen thestring)) (if (> chklen 3); check if the characters are less than 3 i.e. blank space etc so no change (progn (setq str (strcat "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E. " (rtos (+ 20000 (atof (substr (vla-get-textstring att) 10))) 2 0))); 20000 IS THE VALUE THAT IS ADDED (vla-put-textstring att str) );progn );if );progn );if );foreach ) (setq count (+ 1 count)) );while );defun Quote Link to comment Share on other sites More sharing options...
vishwaskekane Posted December 1, 2021 Author Share Posted December 1, 2021 i am talking about this program Quote Link to comment Share on other sites More sharing options...
vishwaskekane Posted December 1, 2021 Author Share Posted December 1, 2021 3 hours ago, Emmanuel Delay said: Also notice: the third block from the top has the East coordinate in the wrong attribute Yes...Sorry for that... Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted December 1, 2021 Share Posted December 1, 2021 (edited) I can't help you with the coordinates who are in a wrong attribute. For the rest, this works. Command INE. This code assumes the coordinates are always integers. Are they? (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; http://www.lee-mac.com/attributefunctions.html ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:vl-getattributevalue ( blk tag ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) ;; Set Attribute Value - Lee Mac ;; Sets the value of the first attribute with the given tag found within the block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; val - [str] Attribute Value ;; Returns: [str] Attribute value if successful, else nil. (defun LM:vl-setattributevalue ( blk tag val ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val) ) ) (vlax-invoke blk 'getattributes) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; INcrement East (defun c:ine ( / blk val east i ss) (setq ss (ssget "_X" '((0 . "*INSERT") (66 . 1)))) (setq i 0) (repeat (sslength ss) (setq blk (ssname ss i)) (if (setq val (LM:vl-getattributevalue (vlax-ename->vla-object blk) "EAST_COORD")) ;; value of the attribute. (progn (setq east (substr val 11)) ;; the first 10 characters are fixed. (setq east (+ 2000 (atoi east))) ;; add 2000 (princ east) (LM:vl-setattributevalue (vlax-ename->vla-object blk) "EAST_COORD" (strcat "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E. " (itoa east) )) ;; set it back. hardcode that Russian text ) ) (if (setq val (LM:vl-getattributevalue (vlax-ename->vla-object blk) "CONTVAR2EASTCOORD")) ;; value of the attribute. (progn (setq east (substr val 4)) ;; the first 3 characters are fixed. (setq east (+ 2000 (atoi east))) ;; add 2000 (princ east) (LM:vl-setattributevalue (vlax-ename->vla-object blk) "CONTVAR2EASTCOORD" (strcat "E. " (itoa east) )) ;; set it back. hardcode that Russian text ) ) (setq i (+ i 1)) ) ) Edited December 1, 2021 by Emmanuel Delay 1 Quote Link to comment Share on other sites More sharing options...
vishwaskekane Posted December 1, 2021 Author Share Posted December 1, 2021 1 hour ago, Emmanuel Delay said: I can't help you with the coordinates who are in a wrong attribute. For the rest, this works. Command INE. This code assumes the coordinates are always integers. Are they? (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; http://www.lee-mac.com/attributefunctions.html ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:vl-getattributevalue ( blk tag ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) ;; Set Attribute Value - Lee Mac ;; Sets the value of the first attribute with the given tag found within the block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; val - [str] Attribute Value ;; Returns: [str] Attribute value if successful, else nil. (defun LM:vl-setattributevalue ( blk tag val ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val) ) ) (vlax-invoke blk 'getattributes) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; INcrement East (defun c:ine ( / blk val east i ss) (setq ss (ssget "_X" '((0 . "*INSERT") (66 . 1)))) (setq i 0) (repeat (sslength ss) (setq blk (ssname ss i)) (if (setq val (LM:vl-getattributevalue (vlax-ename->vla-object blk) "EAST_COORD")) ;; value of the attribute. (progn (setq east (substr val 11)) ;; the first 10 characters are fixed. (setq east (+ 2000 (atoi east))) ;; add 2000 (princ east) (LM:vl-setattributevalue (vlax-ename->vla-object blk) "EAST_COORD" (strcat "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E. " (itoa east) )) ;; set it back. hardcode that Russian text ) ) (if (setq val (LM:vl-getattributevalue (vlax-ename->vla-object blk) "CONTVAR2EASTCOORD")) ;; value of the attribute. (progn (setq east (substr val 4)) ;; the first 3 characters are fixed. (setq east (+ 2000 (atoi east))) ;; add 2000 (princ east) (LM:vl-setattributevalue (vlax-ename->vla-object blk) "CONTVAR2EASTCOORD" (strcat "E. " (itoa east) )) ;; set it back. hardcode that Russian text ) ) (setq i (+ i 1)) ) ) Thank you so much.... i will try this Quote Link to comment Share on other sites More sharing options...
vishwaskekane Posted December 1, 2021 Author Share Posted December 1, 2021 1 hour ago, Emmanuel Delay said: I can't help you with the coordinates who are in a wrong attribute. For the rest, this works. Command INE. This code assumes the coordinates are always integers. Are they? (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; http://www.lee-mac.com/attributefunctions.html ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:vl-getattributevalue ( blk tag ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) ;; Set Attribute Value - Lee Mac ;; Sets the value of the first attribute with the given tag found within the block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; val - [str] Attribute Value ;; Returns: [str] Attribute value if successful, else nil. (defun LM:vl-setattributevalue ( blk tag val ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val) ) ) (vlax-invoke blk 'getattributes) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; INcrement East (defun c:ine ( / blk val east i ss) (setq ss (ssget "_X" '((0 . "*INSERT") (66 . 1)))) (setq i 0) (repeat (sslength ss) (setq blk (ssname ss i)) (if (setq val (LM:vl-getattributevalue (vlax-ename->vla-object blk) "EAST_COORD")) ;; value of the attribute. (progn (setq east (substr val 11)) ;; the first 10 characters are fixed. (setq east (+ 2000 (atoi east))) ;; add 2000 (princ east) (LM:vl-setattributevalue (vlax-ename->vla-object blk) "EAST_COORD" (strcat "\U+0412\U+041E\U+0421\U+0422\U+041E\U+041A/E. " (itoa east) )) ;; set it back. hardcode that Russian text ) ) (if (setq val (LM:vl-getattributevalue (vlax-ename->vla-object blk) "CONTVAR2EASTCOORD")) ;; value of the attribute. (progn (setq east (substr val 4)) ;; the first 3 characters are fixed. (setq east (+ 2000 (atoi east))) ;; add 2000 (princ east) (LM:vl-setattributevalue (vlax-ename->vla-object blk) "CONTVAR2EASTCOORD" (strcat "E. " (itoa east) )) ;; set it back. hardcode that Russian text ) ) (setq i (+ i 1)) ) ) Thank you so much....its works 1 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.