+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Junior Member
    Using
    AutoCAD 2010
    Join Date
    Oct 2015
    Posts
    18

    Default Title Block Attribute Colour Lisp help

    Registered forum members do not see this ad.

    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

  2. #2
    Senior Member
    Discipline
    Civil
    Hippe013's Discipline Details
    Occupation
    Survey Crew Chief / Civil Designer
    Discipline
    Civil
    Details
    Land Survey / Civil Engineering
    Using
    Civil 3D 2017
    Join Date
    Feb 2010
    Location
    North Dakota
    Posts
    350

    Default

    This is how I might approach this.

    Code:
    (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))
      )

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,959

    Default

    I would suggest perhaps:
    Code:
    (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)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,731

    Default

    Lee, What is the need of the last two IF functions as long as you can replace them with one AND function?

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,959

    Default

    Quote Originally Posted by Tharwat View Post
    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.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    739

    Default

    Heres my attempt, Phtephen:

    Code:
    (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!

  7. #7
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,731

    Default

    Quote Originally Posted by Lee Mac View Post
    Many ways to skin the cat.
    It must be too cute.

  8. #8
    Junior Member
    Using
    AutoCAD 2010
    Join Date
    Oct 2015
    Posts
    18

    Default

    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

  9. #9
    Junior Member
    Using
    AutoCAD 2010
    Join Date
    Oct 2015
    Posts
    18

    Default

    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

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,959

    Default

    Registered forum members do not see this ad.

    You're welcome!

    Aside, be careful of using (2 . "MyBlock") with dynamic blocks, as the block references will be anonymous.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Attribute in title block exists in BLock Editor but not in Project.
    By Pawnsurfer in forum AutoCAD Drawing Management & Output
    Replies: 17
    Last Post: 19th Feb 2015, 09:10 pm
  2. Changing Colour of Border and Title Block in about 50,000 layut tabs (Company Rebrand
    By Simple153 in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 4
    Last Post: 16th May 2013, 08:40 am
  3. Title Block Attribute Script
    By crmosoldier in forum AutoLISP, Visual LISP & DCL
    Replies: 30
    Last Post: 30th Dec 2011, 05:01 pm
  4. Attribute/Title Block Help
    By joshm3357 in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 16th Jun 2010, 05:16 pm
  5. Attribute Title Block
    By Herewegoagain in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 1st Jun 2009, 09:56 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts