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
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.
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.
Re: Auto-update hatch color using field/table value
Quote:
Originally Posted by
greg.winter793123
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?
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.
1 Attachment(s)
Re: Auto-update hatch color using field/table value
Quote:
Originally Posted by
dlanor
You have a hatch object/entity, and inside the hatch boundary is a text/mtext containing a field related to an excel table?
Attachment 108502
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.
Re: Auto-update hatch color using field/table value
Quote:
Originally Posted by
greg.winter793123
Attachment 108502
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.
1 Attachment(s)
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)
2 Attachment(s)
Re: Auto-update hatch color using field/table value
Hi all,
I have attached an example drawing and sample data similar to that being used.
The ideal outcome is to have the hatch color change based on the values in each column, with definitions present in the Excel spreadsheet (if required).
Many thanks and again, your time is VERY much appreciated!
Greg
Re: Auto-update hatch color using field/table value
Its confusing, what are the colours to be ? There are 4 values with a background, do the numbers change colour, do the background change colour, you need a better example point to what should happen, how to work out colour range, lots of questions.