Results 1 to 8 of 8

Thread: Auto-update hatch color using field/table value

  1. #1
    Member
    Join Date
    2020-11
    Posts
    3
    Login to Give a bone
    0

    Default Auto-update hatch color using field/table value

    Hi there,

    I am looking to change the hatch color based on a value.

    I have data-linked an Excel table to AutoCAD then use the cells of this table to auto-update fields in the drawing, if the Excel spreadsheet updates.

    Is it possible to use these table cells/field values (integers) to change the color of hatching?

    e.g.
    product is 3 years old so hatch is green,
    product is 10 years old so hatch is orange,
    product is 25 years old so hatch is red.

    Any time spent on this issue is greatly appreciated.

    Cheers,
    Greg

  2. #2
    Active Member
    Join Date
    2015-12
    Location
    Western Europe
    Posts
    57
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    You don't say how these are inter-connected. Is the hatch also in the table? Is it a block in the drawing or the table? Changing an objects color is simply changing it's color property. Changing the color base on an integer would require this to incorporate a condition or multiple if statements. Post an example drawing (preferably saved as AutoCAD 2012 or earlier for me) and I'm sure someone can help.

  3. #3
    Member
    Join Date
    2020-11
    Posts
    3
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    Hi dlanor,

    Thanks for the reply.

    This is part of my problem as I do not know how/if hatch and fields can be connected.

    The current set-up involves fields (which data-link text from a table) placed on top of a hatch - with no link between them defined.

  4. #4
    Active Member
    Join Date
    2015-12
    Location
    Western Europe
    Posts
    57
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    Quote Originally Posted by greg.winter793123 View Post
    Hi dlanor,

    Thanks for the reply.

    This is part of my problem as I do not know how/if hatch and fields can be connected.

    The current set-up involves fields (which data-link text from a table) placed on top of a hatch - with no link between them defined.
    Sorry but you've sort of lost me. You have a hatch object/entity, and inside the hatch boundary is a text/mtext containing a field related to an excel table?

  5. #5
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    426
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    This is like something asked for years ago but it had the advantage of a "KEY" in that there was a text on a layer and the hatch was found by using that text. It was land parcels.

    Need a dwg to see what is going on.

  6. #6
    Member
    Join Date
    2020-11
    Posts
    3
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    Quote Originally Posted by dlanor View Post
    You have a hatch object/entity, and inside the hatch boundary is a text/mtext containing a field related to an excel table?
    drawing_example.png

    For clarity:
    The above is an example of what my drawing contains. The '3' in the top right quadrant is a field that is linked to the '3' in the table.
    The green background is a solid hatch.

    Is there a way to link this '3' field to alter the hatch colour it sits upon.

    Again, many thanks for your time, it is greatly appreciated

    Cheers,
    Greg

    - - - Updated - - -

    Hi Al,

    Thanks for your reply!

    Please see my reply dlanor.

    Does this follow the lines of your thinking?

    Cheers!

    - - - Updated - - -

    Hi Mika,

    I am currently using AutoCAD 2020, but I also have AutoCAD Mechanical 2017 BR installed.

  7. #7
    Active Member
    Join Date
    2015-12
    Location
    Western Europe
    Posts
    57
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    Quote Originally Posted by greg.winter793123 View Post
    drawing_example.png

    For clarity:
    The above is an example of what my drawing contains. The '3' in the top right quadrant is a field that is linked to the '3' in the table.
    The green background is a solid hatch.

    Is there a way to link this '3' field to alter the hatch colour it sits upon.

    Again, many thanks for your time, it is greatly appreciated

    Cheers,
    Greg
    Without having an actual example drawing to disprove the fact, it should be possible. You have two entities, one inside the other, which can be matched. You can therefore extract the value of from the field and apply that to the hatch color.

  8. #8
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    426
    Login to Give a bone
    0

    Default Re: Auto-update hatch color using field/table value

    Like dlanor it looks like there is something to compare to and find.

    To avoid going around in circles with any code some one may post, need to know
    3=green
    4=red
    5= cyan
    and so on.

    Please provide the lookup values and a sample dwg simple as you have posted as a image.

    This is not real code for you but a bit of code I found may not work not tested.

    Code:
    (defun HATLOT (lotnum col / HATOBJ FPTS PT1 TPT )
    (SETQ OLDSNAP (GETVAR "OSMODE"))
    (SETVAR "OSMODE" 0)
    (setq lotfound (ssget "X" (LIST (CONS 0 "MTEXT")(CONS 1 lotnum)(CONS 8 "C-BLDG-NMBR"))))
    (SETQ TPT (ASSOC 10 (ENTGET (ssname lotfound 0))))
    (SETQ PT1 (LIST (NTH 1 TPT)(NTH 2 TPT)))
    (SETQ FPTS (LIST (POLAR PT1 1.57 2 ) PT1)) ; 2 is a dummy value just past text hole
    (SETQ HATOBJ (ENTGET (SSNAME (SSGET "f" FPTS '((0 . "HATCH"))) 0)))
    (ENTMOD (subst col (assoc 8 HATOBJ) HATOBJ))
    )
    ; this is where you would loop through the lots csv from excel number - color
    ;(while read csv
    (setq lotnum (getstring "\nEnter lot number")) ; read from file
    (SETQ COL (cons 8 "60% complete")) ; dummy line for testing make value read from file
    (HATLOT lotnum perc)
    ;) ; end while
    
    (setvar "osmode" oldsnap)
    (princ)
    Attached Images Attached Images

Similar Threads

  1. 2014: Auto Cad -2014 LT Attribute field value covert to Text globally
    By umesh.yadav419124 in forum AutoCAD Customization
    Replies: 0
    Last Post: 2013-09-14, 11:47 PM
  2. Replies: 0
    Last Post: 2013-07-26, 11:11 AM
  3. Replies: 7
    Last Post: 2012-10-17, 08:47 PM
  4. Replies: 1
    Last Post: 2006-12-12, 07:36 AM
  5. Populate Field value to custom sheet value
    By hugho in forum AutoCAD Fields
    Replies: 2
    Last Post: 2006-01-03, 06:24 PM

Tags for this Thread

Posting Permissions

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