4
$\begingroup$

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.

$\endgroup$
3
  • 2
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Apr 20 '12 at 15:19
  • $\begingroup$ Yes..., the paradigm issue. I will try a few things. $\endgroup$ Apr 20 '12 at 15:24
  • $\begingroup$ OMG. That was in fact the answer. It's good that I asked anyway. Thanks. $\endgroup$ Apr 20 '12 at 15:26
5
$\begingroup$

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]}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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