Author Topic: Dim text different colour for values / text..  (Read 2918 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
Dim text different colour for values / text..
« on: February 25, 2008, 08:42:22 AM »
Hi,

Here's one for all you VBAists out there!

I want to, if possible, be able to show up ALL dimensions in different colours dependant on whether they are showing true dim values or their text has been overridden..

Par example, if a dimension's text has been edited in any way, i want the text to be one colour, say BLUE, but...if the dimension is showing its true dimension value and nothing has been edited in the text override, then colour this text RED..

Can this be done and if so, can someone point me whatever direction i will need or start me off..

Cheers,

Paul
basepointdesignzltd..

XP Pro / AutoCAD 2008..
Pentium Core 2 Q6600 Quad Core
ASUS P5N-E SLI Motherboard
4GB DDR2 RAM
2 x SLI NVIDIA 8500GT SLi 1024MB DDR2 PCI-Express Graphics Cards

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dim text different colour for values / text..
« Reply #1 on: February 25, 2008, 09:08:35 AM »
Minimalist quick and dirty proof of concept code. Doesn't check for locked layers et al. Also, colors are reversed, red = override, blue = true.

Code: [Select]
Sub ColorByOveride()

    Dim block  As AcadBlock, _
        ent    As AcadEntity, _
        diment As AcadDimension
       
    For Each block In ThisDrawing.Blocks
        If block.IsLayout Then
            For Each ent In block
                If ent.ObjectName Like "AcDb*Dimension" Then
                    Set diment = ent
                    diment.TextColor = IIf(diment.TextOverride = "", acBlue, acRed)
                End If
            Next ent
        End If
    Next block

End Sub
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hardwired

  • Guest
Re: Dim text different colour for values / text..
« Reply #2 on: February 28, 2008, 10:15:27 AM »
Hey MP,

Thanks for that code, works a dream. Just need to try to add a few other factors, but not sure how to..

Want to check the TextOverride for the "<>" dimension value code and NOT colour these values, NOR colour any string value like "TBC" or "PANEL LENGTH" etc. Just any overridden numerical equivilent values, so for example.........

  • Unedited Dimensions (no TextOverride) would be WHITE (normal dimstyle colour) text..
  • Edited (Overriden) dimensions showing the textual value for the dimension value would be GREEN..
  • Dimensions overridden like "<> SHEET LENGTH" would be WHITE (normal dimstyle colour) text..
  • Dimensions overidden with text measuremant plus string value (like "2400 SHEET LENGTH") would be WHITE text for the string, but GREEN for the numbers..

I hope this makes sense, it does to me but it would, lol..



MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dim text different colour for values / text..
« Reply #3 on: February 29, 2008, 06:52:16 AM »
Share your code so we can have a look and point you in the right direction.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hardwired

  • Guest
Re: Dim text different colour for values / text..
« Reply #4 on: February 29, 2008, 07:26:11 AM »
Hi MP,

I have exactly what you gave me before, ok maybe a few minor tweaks but nothing mad for now..

Code: [Select]
Sub DimOverrideMarker()

Dim blockX As AcadBlock
Dim entX As AcadEntity
Dim dimentX As AcadDimension
   
For Each blockX In ThisDrawing.Blocks
    If blockX.IsLayout Then 'If its a layout..
        For Each entX In blockX
            If entX.ObjectName Like "AcDb*Dimension" Then
                Set dimentX = entX
                dimentX.TextColor = IIf(dimentX.TextOverride = "", acWhite, acGreen)
            End If
        Next entX
    End If
Next blockX

End Sub

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dim text different colour for values / text..
« Reply #5 on: February 29, 2008, 08:39:38 AM »
This code is to teach / illuminate, and is not anted up as a solution to your challenge. However, I do hope it will be a stepping stone to your solution ...

Code: [Select]
Option Explicit

Function [color=red]IsLike[/color](text As String, pattern As String) As Boolean

    [color=green]''   quick and dirty but should work[/color]

    If InStr(pattern, ",") > 0 Then
        Dim patterns() As String, _
            i          As Integer
        patterns = Split(pattern, ",")
        For i = 0 To UBound(patterns)
            If text Like patterns(i) Then
                IsLike = True
                Exit Function
            End If
        Next i
        IsLike = False
    Else
        IsLike = text Like pattern
    End If

End Function

Sub [color=red]ColorByOveride[/color]()

    Dim block    As AcadBlock, _
        ent      As AcadEntity, _
        diment   As AcadDimension, _
        override As String
       
    For Each block In ThisDrawing.Blocks
        If block.IsLayout Then
            For Each ent In block
                If ent.ObjectName Like "AcDb*Dimension" Then
               
                    Set diment = ent
                   
                    override = UCase$(diment.TextOverride)
                   
                    If override = "" Then
                   
                        '[color=green]'  Not overridden, so normal dimstyle colour should
                        ''  be "ByLayer" (acByLayer), not neccesarilly white.
                        ''  However, for this exervise I will force white so
                        ''  you can definitively see what dims met this test.[/color]
                       
                        diment.TextColor = acWhite
                       
                    ElseIf override Like "<> ?*" Then
                   
                        [color=green]''  You wanted white, but for the sake of differ-
                        ''  entiating the results I chose yellow.[/color]
                   
                        diment.TextColor = acYellow
                       
                    ElseIf IsNumeric(override) Then
                   
                        [color=green]''  Should be self explanatory.[/color]
                   
                        diment.TextColor = acGreen
                       
                    ElseIf [color=red]IsLike[/color](override, "# [A-Z]*,## [A-Z]*,### [A-Z]*,#### [A-Z]*") Then
                   
                        [color=green]''  You wanted white + green. I don't think you can
                        ''  specify different colors for each "word" in the
                        ''  override text. Your challenge as budding programmer
                        ''  is to prove me wrong.[/color]
                       
                        [color=green]''  Anyway, to differentiate your test results I chose
                        ''  to make dims that met this condition magenta.[/color]
                       
                        diment.TextColor = acMagenta
                       
                    Else
                   
                        [color=green]''  We failed to trap the override's characteristics
                        ''  so this is our default, color it red so you can
                        ''  differentiate.[/color]
                   
                        diment.TextColor = acRed
                       
                    End If
                   
                End If
            Next ent
        End If
    Next block

End Sub

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hardwired

  • Guest
Re: Dim text different colour for values / text..
« Reply #6 on: February 29, 2008, 11:13:11 AM »
MP, thats genious, works perfectly for my purposes, next round is on me..

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dim text different colour for values / text..
« Reply #7 on: February 29, 2008, 11:49:35 AM »
MP, thats genious, works perfectly for my purposes, next round is on me.

Glad to hear it's helping. Since you're buying I'll have a pan galactic gargle blaster; thanks.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Glenn R

  • Guest
Re: Dim text different colour for values / text..
« Reply #8 on: February 29, 2008, 03:22:01 PM »
Ah...Mr Douglas Adams...a trilogy in 4 parts...sadly missed. I'll buy you one at 'The Restaurant'... :evil:

Cheers,
Glenn.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dim text different colour for values / text..
« Reply #9 on: February 29, 2008, 04:01:23 PM »
And back at ya.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst