Steven P Posted January 6, 2017 Share Posted January 6, 2017 Good afternoon, I am writing a simple LISP routine that I can run and will check / change drawing layers, colours etc to the client requirements. Saves me missing something as I go through the drawings. For the title block they want it all on layer "Title", but to have different colours for different texts. So title description might be in Yellow, drawing number might be Red. My idea for this is to modify the block attributes to the colours needed. I am looking at adding a line or 2 to my LISP to modify the colours of the text. I have tried using -attedit, which is OK, but seams to want a user input to select the block attributes to modify. Any help would be great. All the title blocks are the same, I know the block name and attribute names (MyBlock, Title_1, Title_2... Number, Project) Ideally looking for something like (command (MyBlock, Title_1, Color, "1")) to set Title_1 to Red. Sounds easy, and I am pretty sure it is I just need a bit of help. Thanks Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 6, 2017 Share Posted January 6, 2017 This is how I might approach this. (setq blk (vlax-ename->vla-object (car (entsel "\nSelect Block: ")))) (setq atts (vlax-safearray->list (vlax-variant-value (vlax-invoke-method blk 'GetAttributes)) )) (setq cnt 0) (repeat (length atts) (setq att (nth cnt atts)) (cond ((= (vlax-get-property att 'TagString) "TITLE_1")(vlax-put-property att 'Color acred)) ((= (vlax-get-property att 'TagString) "TITLE_2")(vlax-put-property att 'Color acgreen)) ((= (vlax-get-property att 'TagString) "TITLE_3")(vlax-put-property att 'Color acblue)) ) (setq cnt (+ cnt 1)) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 6, 2017 Share Posted January 6, 2017 I would suggest perhaps: (defun c:attcol ( / col lst sel ) ;; Tags/Colours (setq lst '(("TITLE_1" . 1) ("TITLE_2" . 2) ("NUMBER" . 3) ("TAG1" . 4) ("TAG2" . 5))) (if (setq sel (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1)))) (foreach att (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'getattributes) (if (setq col (cdr (assoc (strcase (vla-get-tagstring att)) lst))) (if (vlax-write-enabled-p att) (vla-put-color att col)) ) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 6, 2017 Share Posted January 6, 2017 Lee, What is the need of the last two IF functions as long as you can replace them with one AND function? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 6, 2017 Share Posted January 6, 2017 Lee, What is the need of the last two IF functions as long as you can replace them with one AND function? Many ways to skin the cat. Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 6, 2017 Share Posted January 6, 2017 Heres my attempt, Phtephen: (defun C:test ( / Lst SS e grp enx ) (setq Lst ; adjust for personal needs '( ; assoc list of (<TagName> . <Index Color>) ; note: <TagName> is case sensitive ("AttTag1" . 1) ("AttTag2" . 2) ("AttTag3" . 3) ("AttTag3" . 4) ) ) (and (not (prompt "\nPick the titleblock: ")) (setq SS (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1)))) (setq e (ssname SS 0)) (while (/= "SEQEND" (cdr (assoc 0 (entget (setq e (entnext e)))))) (and (setq grp (assoc (cdr (assoc 2 (setq enx (entget e)))) Lst)) (entmod (append (vl-remove-if '(lambda (x) (member (car x) '(62 420 430))) enx) (list (cons 62 (cdr grp))))) ) ) ) (princ) ) EDIT: Damn, Lee was faster! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 6, 2017 Share Posted January 6, 2017 Many ways to skin the cat. It must be too cute. Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 6, 2017 Author Share Posted January 6, 2017 Thanks, I only got chance to try the first one before I left work for the weekend - it works well, having said that, I am going to try the other 2 methods on Monday. I can see how having the array in Lees' would be neater if there was a lot of attributes to change (I think I have to update 11), If I was anticipating needing to use this frequently or in a large project I would look at how to specify the block to use within the LISP routine (saves a few secomds) - leading to perhaps having it modify all the drawings in a folder. Thanks so far Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 9, 2017 Author Share Posted January 9, 2017 Monday morning and I tried the other 2 solutions - they work well. Quiet morning so I hunted out: (ssget "x" '((0 . "INSERT")(2 . "MyBlock"))) to replace (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1))) since I am only updating 1 block with the same name in each drawing. Now with the one command I know all the layers are correctly setup, the colours in this block are as they should be and using a couple of other LISPs the page setups etc are all right, exactly as I want. Until next time, thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 9, 2017 Share Posted January 9, 2017 You're welcome! Aside, be careful of using (2 . "MyBlock") with dynamic blocks, as the block references will be anonymous. Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 25, 2017 Author Share Posted January 25, 2017 First off an apology for going back to an older thread where there was a couple of great answers. I wanted to updated a series of drawings to include the file name into a block tag "DWG_NO" and "FILE_NAME", and also to change "REV". Picking Lees LISP above with a slight modification I reckoned that would work: (defun c:FileName ( / col lst sel filename fn dwgn) ;;Uses list to update text in a block ;;get drawing filename (setq fn (strcat (getvar "Dwgprefix")(getvar "dwgname"))) ;;drawing name (setq dwgn (cadr (fnsplitl fn))) ;;drawing name ;; create lst (Tag No, Drawing No.) (setq lst '(("DWG_NO" . dwgn) ("A1-DWG-NO" . dwgn) )) ;; To later increase this list with other tags, such as revision ;;insert list values into block tags (if (setq sel (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1)))) ;select attribute (foreach att (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'getattributes) (if (setq col (cdr (assoc (strcase (vla-get-tagstring att)) lst))) (if (vlax-write-enabled-p att) (vla-put-textstring att dwgn)) ;;new line I added to make this work ; (if (vlax-write-enabled-p att) (vla-put-textstring att col)) ;;I want this to work but why not? ) ) ) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; So now I get dwgn to be the file name, I want to put that into a list in the line (setq lst '(("DWG_NO" . dwgn) ("A1-DWG-NO" . dwgn) )) and from there to use this list to update the block tags using the line removed for now: (if (vlax-write-enabled-p att) (vla-put-textstring att col)) Hope that makes sense. This didn't work and I am not sure why. I put in the line above ((if (vlax-write-enabled-p att) (vla-put-textstring att dwgn))) just forcing drawing number and ignoring what is in lst... again hope I am explaining this well enough. This worked and I did what I needed to do, however out of curiosity why isn't the first idea working? So where I think this goes wrong is to save the value of dwgn into lst - can you do that? Cheers Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 25, 2017 Author Share Posted January 25, 2017 Sorry - not sure why the code didn't go in between code tags! Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 25, 2017 Share Posted January 25, 2017 Sorry - not sure why the code didn't go in between code tags! Just highlight the code and press the [#] button next to the smiley. When you use such variables inside a list, you must evaluate it by using the list function, and cons to construct a dotted pair(s): (setq lst (list (cons "DWG_NO" dwgn) (cons "A1-DWG-NO" dwgn) )) The result will have the same structure as an assoc (dotted pair) list. Some additional info. Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 25, 2017 Author Share Posted January 25, 2017 Thanks, I knew it must be something simple, what I want works like a dream now. 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.