Custome Color set in script.

I have a script that I'm running against a graphic to change a number of things.. line width, style, etc. One thing I need to change is the object's color. I have a custom color set with custom names. I would like the script to be able to set the color to the custom color name rather than just looking at the color value.. ie. "1505656". I don't know how to access those color sets in VBA.

Thanks.

11 Replies

  • Under your object there will be animations that will have a generic name unless someone has renamed them (I did in the screen shot below) which contain the shared table name where you can see the object name in the left column of properties for the color table being used.

    So an example vba line to update this would be:

    afgRect113.SharedTableName = "User.Pump_DValve_Fill_Color_Tan"

    I seem to recall there being an issue with doing this however and getting the object to refresh until the animation value has changed.

  • If you are trying to change the colour of a property that is currently simply set by a colour value, then you will have to first add an animation object (the afgRect113 in the picture). Then you can set the SharedTableName property of this. It is possible to add animation objects through VBA. I can send you some notes on this.
  • In reply to Cedric Dawnhawk:

    I don't want to have animation, I just want to set the EdgeColor property. Currently, i have just used the generic number as follows:

    'edit lines
    For i = 1 To picCurrent.ContainedObjects.Count
    Set Shape = picCurrent.ContainedObjects.item(i)

    MyPos = InStr(1, Shape.Name, "line", 1)
    If (MyPos > 0) Then
    Shape.EdgeWidth = 2
    Shape.EdgeColor = 6974058
    End If
    Next i

    This is fine, but then when i open the property or click on the Color Toolbar button, it comes up with the generic system default color set. But, i have a color set where "Line_Process" = 6974058.

    I tried Matt's suggestion to get the name.. but adding the animation didn't show me anything under SharedTableName. That's still blank.
  • In reply to TreyB:

    You would set the Source to "Line_Process" and the SharedTableName maybe wouldn't change if I'm understanding what you are trying to do then. Here are the iFix view of the properties sent earlier

    Might be better to explain the overall end goal to fully understand what you are trying to do. Just keep in mind you will have to migrate this to DeltaV Live potentially in the near future.

  • In reply to Matt Stoner:

    Maybe i didn't explain the goal well enough. I have a bunch of graphics (like 45) that need to be converted to new standards. I've already got the dynamos all updated using a script I modified from Cedric. Aside from Dynamos, the old graphics have the wrong line widths and colors. They also use the wrong font and color and size for text. So, i have a script searching all objects by name and then updating the properties. It all works perfectly as described in the last comment, but the colors don't show up as they are part of the color set. They just show up with the generic default color set, since I'm only setting the color using the number value. So, i was hoping that there would be something like the following method:

    LineObject.EdgeColor = Application.ColorSet.POET_GS.Line_Process.. lol.. the right side of the equation is where i'm trying to find methods and syntax for. rather than just

    LineObject.EdgeColor = 6675102
  • In reply to TreyB:

    I should have read your initial post more carefully where you do refer to colour sets rather than colour tables, which is the usual way of setting custom colours.

    I didn't know a lot about how colour sets worked but after a bit of investigation it appears that If a colour property of an object is set using anything other than the default colour set, the property becomes ‘indirected’ and the name of the custom colour set and the name of the colour are stored in a list and the colour property is set to the numeric value defined in the custom color set.

    To set a colour from a custom colour set programmatically you need to use some of the (hidden) methods for manipulating the indirected information.

    So instead of:

    Shape.EdgeColor = 6974058

    you need two lines:

    Shape.SetupPropertyIndirection "EdgeColor", strTable, strEntry
    Shape.UpdateIndirectedProperties

    where strTable is the name of the table without the .ftb extension ("POET_GS"?) and strEntry is the name assigned to the colour you want ("Line_Process"?). These are case-sensitive. The first line sets up the information about the custom colour then the second updates the EdgeColor property with the numerical value of the colour from the custom colour set.

    I have some notes on the other indirected methods which may be of interest. These are hidden methods and some IFix documentation I have says they are "Reserved for internal purposes". However I have tried them out on my development system and they seem to work OK.

  • In reply to Cedric Dawnhawk:

    I should have read closer as well as I saw color set and thought color table.

    Looks like Cedric has the answer already.
  • In reply to Cedric Dawnhawk:

    That was perfect. exactly what i needed. I can't even Google these methods so they must be really hidden!
  • In reply to TreyB:

    Got there in the end.

    If you make sure you have a reference to eg Intellution FD 2D Text library, open the object browser in VBA (F2), select the library then the text object, then right click in the 'Members' window and select "Show Hidden Members" you will see all the hidden methods greyed out.
  • In reply to Cedric Dawnhawk:

    I have a follow up. Being able to set a custom color as we described is working great. . however, i have the case where I now need to identify IF the selected shape has an edge color that matches that selected color. Any suggestions?
  • In reply to TreyB:

    You need to use a couple of the other "hidden" methods.

    bIndirect = txtObject.IsPropertyIndirected(strProp)

    where bIndirect is a Boolean variable indicating if the property is "Indirected", txtObject is the shape you are testing and strProp is the name of the property, "EdgeColor" in your case.

    Then

    If bIndirect Then
         txtObject.GetIndirectedProperty strProp, strTable, strEntry
    End If

    where strTable and strEntry are variables that will be updated with the custom colour table name and the name of the custom colour. GetIndirectedProperty throws an error if the property is not indirect, so you must do the bIndirect test first.

    Then just test strTable and strEntry to see if they are the values you are looking for.

    I will email you directly the full notes I have about these methods so if anything else crops up you may be able to sort it.