Lee Chu Chu Posted July 21, 2014 Posted July 21, 2014 So I have a lisp program that draws some attributes. I want to be able to write a lisp program that will change the value of the selected attributes and I want the CCTNUMBERS to be in chronological order. I want the lisp to be able to take the smallest number and puts it in on the attribute that is to the most left of the selected window and the largest number to be on the right. Any ideas on how I can write this lisp? I don't even know how to be able to grab the respective attribute information let alone change it. Help please. This is what I have: This is what I want: Quote
Lee Chu Chu Posted July 21, 2014 Author Posted July 21, 2014 These are a couple of Lee Mac's lisp programs that might be helpful for me but I have no idea how this will help in my situation plus I don't have much understanding of the code he wrote: ;; Set Attribute Values - Lee Mac ;; Sets attributes with tags found in the association list to their associated values. ;; blk - [vla] VLA Block Reference Object ;; lst - [lst] Association list of ((<tag> . <value>) ... ) ;; Returns: nil (defun LM:vl-setattributevalues ( blk lst / itm ) (foreach att (vlax-invoke blk 'getattributes) (if (setq itm (assoc (vla-get-tagstring att) lst)) (vla-put-textstring att (cdr itm)) ) ) ) ;; Get Attributes - Lee Mac ;; Returns an association list of attributes present in the supplied block. ;; blk - [vla] VLA Block Reference Object ;; Returns: [lst] Association list of ((<Tag> . <Value>) ... ) (defun LM:vl-getattributes ( blk ) (mapcar '(lambda ( att ) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke blk 'getattributes) ) ) Acknowledgements to Lee Mac. Quote
pBe Posted July 21, 2014 Posted July 21, 2014 (edited) Modified Code (Defun c:demo (/ alphanum data ss i sym Lwn Lwnv pref data) ;;; Demo for Lee Chu Chu by pBe ;;; ;;; 31July2014 ;;; (defun alphanum (fun str) (vl-list->string (fun '(lambda (v) (<= 48 v 57) ) (vl-string->list str ) ) ) ) (if (setq data nil ss (ssget "_:L" '((2 . "Block1,Block2,Block3"))) ) (progn (initget 1 "LTR TTB") (setq opt (getkword "\nChoose option [Left to Right/Top to Bottom]: ") ) (repeat (setq i (sslength ss)) (setq data (cons (vl-some '(lambda (at) (if (eq "TAGName" (vla-get-tagstring at)) ;<-- the target tagstring (list (atoi (alphanum vl-remove-if-not (vla-get-textstring at) ) ) (vla-get-textstring at) (vlax-get at 'Insertionpoint) at ) ) ) (vlax-invoke (vlax-ename->vla-object (ssname ss (setq i (1- i))) ) 'GetAttributes ) ) data ) ) ) (and data (setq sym (if (eq opt "LTR") (lambda (a b) (< (caaddr a) (caaddr b))) (lambda (a b) (> (cadr (caddr a)) (cadr (caddr b)))) ) ) (setq data (vl-sort data 'sym)) (setq Lwn (apply 'min (mapcar 'car data))) (setq Lwnv (cond ((getint (strcat "\nLowest number is " (itoa Lwn) " ,Enter to accept/Type new Value: " ) ) ) (Lwn) ) ) (setq pref (alphanum vl-remove-if (cadr (assoc Lwn data))) ) (setq data (mapcar 'cdr data) ) (mapcar '(lambda (c) (vla-put-textstring (last c) (strcat pref (itoa Lwnv)) ) (setq Lwnv (1+ Lwnv)) ) data ) ) ) ) (princ) ) (vl-load-com) Edited July 23, 2014 by pBe Quote
Lee Chu Chu Posted July 21, 2014 Author Posted July 21, 2014 (edited) In the commandline when it tells me to select objects, no matter what objects I select, even the block reference, it keeps telling me that 0 objects have been selected. So there is a slight bug there. Also, could someone leave more comments in the above code for me so that I can understand more fundamentally what is going on in the code? Also, looking at Lee Mac's code, I don't understand by the "LM:" syntax. Edited July 22, 2014 by Lee Chu Chu Quote
BIGAL Posted July 22, 2014 Posted July 22, 2014 LM: Lee has created a Lisp Defun this is a group of code in a programing sense a FUNCTION you can have multiple functions in a program where repeat steps are required using the same code repeatedly, the other reason for using a defun is to wrap the variables locally into the function and not become global variables which may be seen by other functions as a variable to use. Me my defun's AH:defun1 this helps identify who wrote it Also if you use C:mydefun you can type mydefun on the keyboard to run it. Quote
pBe Posted July 22, 2014 Posted July 22, 2014 In the commandline when it tells me to select objects, no matter what objects I select, even the block reference, it keeps telling me that 0 objects have been selected. So there is a slight bug there. If you are referring to the code at post #3, Its not really a bug Lee Chu chu, it just not seeing the block i specified on the code "BlockName", YOU need to change that to your attribute block name to make it work, we can however remove the name altogether if needed to make the code more generic. Also notice that its targeting a specific TAG name "CCTNUMBERS", i'm not even sure about that as well. ...Also, could someone leave more comments in the above code for me so that I can understand more fundamentally what is going on in the code? Tell you what, post a sample drawing file [where i can test the code] , then i'll revised the code and throw in some comments for you. Quote
Lee Chu Chu Posted July 23, 2014 Author Posted July 23, 2014 Oh ok. I understand now that I have to change that around. Sorry I just don't have much understanding of the code and plus I kinda wanted to edit the code you supplied to suit my needs so thats why I asked you to leave some comments for me. It works now when I put in the one attribute name however, is it possible to select more than one type of attribute. eg, I want to be able to select all 4 of these attributes. "CIRCLE1" "CIRCLE2" "CIRCLE3" "CIRCLE4". Also I noticed that when it tries to reorder the numbers around, if the number was missing in within the selection ie, numbers jump around from 2,5,4,6., it isnt able to put in the missing 3 but instead just rearranges those in order (output: 2,4,5,6. expected output:2,3,4,5). Quote
pBe Posted July 23, 2014 Posted July 23, 2014 It works now when I put in the one attribute name however, is it possible to select more than one type of attribute. eg, I want to be able to select all 4 of these attributes. "CIRCLE1" "CIRCLE2" "CIRCLE3" "CIRCLE4" Are those block names oR TAG names? Also I noticed that when it tries to reorder the numbers around, if the number was missing in within the selection ie, numbers jump around from 2,5,4,6., it isnt able to put in the missing 3 but instead just rearranges those in order (output: 2,4,5,6. expected output:2,3,4,5). So you're basically saying find the lowest number and change the rest to follow that value? if you select a block with P5 P2 P3 P6, the desired result is P2 P3 P4 P5 ? Quote
Lee Chu Chu Posted July 23, 2014 Author Posted July 23, 2014 Tell you what, post a sample drawing file [where i can test the code] , then i'll revised the code and throw in some comments for you. Is it possible if I could send you a sample .dwg file via a private message? Quote
Lee Chu Chu Posted July 23, 2014 Author Posted July 23, 2014 Are those block names oR TAG names? So you're basically saying find the lowest number and change the rest to follow that value? if you select a block with P5 P2 P3 P6, the desired result is P2 P3 P4 P5 ? I think they are BLOCK NAMES. And yes, I think its better if it picks out the lowest number and change the rest to make it ordered. Quote
pBe Posted July 23, 2014 Posted July 23, 2014 I think they are BLOCK NAMES. And yes, I think its better if it picks out the lowest number and change the rest to make it ordered. That can be arrange Lee Chu Chu. 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.