Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Background: Consider the following graphics directive.

    EdgeForm[
     Directive[Thickness[Large], 
     Dashing[{Small, Small}], 
     Opacity[0.1`], 
     RGBColor[0, 0, 1]]]

In a Manipulate I want to interactively change Thickness, Dashing, Opacity and Color of the edges of Polygons in a pattern. So, for each of them I will have to create a control. The EdgeForm is stored in Excel =as is=. So I will need to extract the values which will become the starting values for the controls out of the EdgeForm above, i.e.:

    Large, 
    {Small, Small}, 
    0.1, 
    RBGColor [0,0,1]

for the four controls respectively.

My strategy was to ToString[EdgeForm[ ...everything ] and then do string manipulations on them but that turned out to become a lot of ( messy, still not working ) code. Considering this is Mathematica ( I thought that ) there must be a simple way to get the values out of that EdgeForm.

Question: How to change the EdgeForm above to {Large, {Small, Small}, 0.1, RBGColor [0,0,1] }. Needless to say that the values change per pattern, i.e. Tiny, Large, etc.

share|improve this question
2  
You can use list manipulation functions on any expression, not merely Lists. You can do anything with that EdgeForm that you can do with a List, e.g. take a Part of it, Replace something inside, etc. It seems to me that you asked this question because you were not aware of this. –  Szabolcs Apr 20 '12 at 15:19
    
Yes..., the paradigm issue. I will try a few things. –  ndroock1 Apr 20 '12 at 15:24
    
OMG. That was in fact the answer. It's good that I asked anyway. Thanks. –  ndroock1 Apr 20 '12 at 15:26
add comment

1 Answer

up vote 5 down vote accepted

As @Szabolcs points out in the comments, you can always use Part or Replace regardless what head your expression has. I personally prefer ReplaceAll in cases such as this because I find it easier to tell what I intended with my code when I dig it up months or years later.

ef = 
  EdgeForm[Directive[Thickness[Large], Dashing[{Small, Small}], 
    Opacity[0.1`], RGBColor[0, 0, 1]]];

ef /. 
 EdgeForm[Directive[Thickness[t_], Dashing[d_], Opacity[o_], 
    col_]] :> {t, d, o, col}

==> {Large, {Small, Small}, 0.1, RGBColor[0, 0, 1]}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.