2
$\begingroup$

Consider examplary a MeshRegion-Object

test = MeshRegion[{{0, 0}, {1, 0}, {2,1/2}, {2, -1/2}}, {Line[{1, 2}], Line[{2, 3}],Line[{3, 4}],Line[{4, 2}]}];

Looking inside test I get

??test
(*Global`test
 MeshRegion[...]*)

To extract the arguments of MeshRegion I usually try

test /. MeshRegion->List

which doesn't work in this example?

What might be the reason? Is there a workaround? Thanks

$\endgroup$
  • 1
    $\begingroup$ hint: AtomQ[test] gives True. $\endgroup$ – kglr Jan 15 at 7:40
  • $\begingroup$ maybe MeshCoordinates[test]and MeshCells[test, 1] or MeshCells[test, All]? $\endgroup$ – kglr Jan 15 at 7:48
  • $\begingroup$ @kglr Thanks, that would return the "input arguments". My goal is to pick everything inside the MeshRegion[...]-expression which ??test returns. $\endgroup$ – Ulrich Neumann Jan 15 at 7:53
  • 2
    $\begingroup$ Well, you shouldn't. MeshRegion is atomic. The "input form" may not even correspond accurately to the internal representation (though I believe in this case it does). Use the documented API if you need guarantees and protection from breakage in special cases or future/past versions. All that said, check out my community wiki answer (or Carl's Nucleus) in the QA I linked above. $\endgroup$ – Szabolcs Jan 15 at 8:50
  • $\begingroup$ Ulricht,do you have some insight on this from chat? $\endgroup$ – user21 Feb 18 at 7:45
1
$\begingroup$

Maybe

ReleaseHold[ToExpression[ToBoxes[InputForm[test]][[1, 1]], StandardForm, Hold] /. 
  MeshRegion -> List]

{{{0., 0.}, {1., 0.}, {2., 0.5}, {2., -0.5}}, {Line[{{1, 2}, {2, 3}, {3, 4}, {4, 2}}]}}

Or

ReleaseHold[MakeExpression[ToBoxes[InputForm[test]][[1, 1]], StandardForm] /. 
  MeshRegion -> List]

{{{0., 0.}, {1., 0.}, {2., 0.5}, {2., -0.5}}, {Line[{{1, 2}, {2, 3}, {3, 4}, {4, 2}}]}}

$\endgroup$

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