Mathematica 13.1 on Windows 10.

Can someone explain why the following does not match:

MatchQ[BoundaryMeshRegion[Cube[]], BoundaryMeshRegion[__]]

(* False *)
  • 5
    $\begingroup$ mesh regions are atomic, which makes them opaque to the pattern matcher. If you use _BoundaryMeshRegion as a pattern it will work. $\endgroup$
    – Jason B.
    Commented Sep 8, 2022 at 13:28
  • $\begingroup$ does this work for you?If you prevent evaluation of the left side, then it does match MatchQ[Unevaluated@BoundaryMeshRegion[Cube[]], BoundaryMeshRegion[___]] gives True $\endgroup$
    – Nasser
    Commented Sep 8, 2022 at 13:32
  • 1
    $\begingroup$ @Nasser - when would you want to do that? Usually the issue is that you have an evaluated object, in this case a mesh region, and you want to write a pattern to match it. $\endgroup$
    – Jason B.
    Commented Sep 8, 2022 at 13:34
  • 1
    $\begingroup$ That is a good question - 'what is the right way to modify an existing mesh region?'. Here are the methods for accessing the innards of atoms. Carl's nucleus function is nice $\endgroup$
    – Jason B.
    Commented Sep 8, 2022 at 13:46
  • 1
    $\begingroup$ @JasonB. sometimes Unevaluated is needed in MathQ. Here is an example !Mathematica graphics this is from youtube.com/watch?v=H-rnezxOCA8 at time 50:57 so Tried on this example and it worked. $\endgroup$
    – Nasser
    Commented Sep 8, 2022 at 13:46

1 Answer 1


As was pointed out in the comments, the reason of the no-match is, that BoundaryMeshRegion is atomic.

My ultimate goal is to change the innards of a BoundaryMeshRegion or any other atomic object. Toward this aim, the function Nucleus from Carl Woll is a big step forward.

I give here a simple example how to change a BoundaryMeshRegion of a Rectangle:

First the function Nucleus from Carl Woll:

Nucleus[input_, head_ : Automatic] := 
 With[{atoms = 
    Replace[head, {Automatic :> 
       If[AtomQ[input], {Head[input]}, 
        Message[Nucleus::atom]; $Failed], h_Symbol :> {h}, 
      h : {__Symbol} :> 
       h, _ :> (Message[Nucleus::syms, head, 2]; $Failed)}]}, (If[! 
       MemberQ[Links[], $AtomLink] || LinkReadyQ[$AtomLink], 
     $AtomLink = LinkCreate[LinkMode -> Loopback]];
    LinkWrite[$AtomLink, input];
    inactiveBlock[atoms, LinkRead[$AtomLink]]) /; atoms =!= $Failed]

SetAttributes[inactiveBlock, HoldAll]
inactiveBlock[h_List, body_] := 
 Block @@ 
  Join[Apply[Set, Hold@Evaluate@Thread[{h, Inactive /@ h}], {2}], 

Nucleus::syms = 
  "Argument `1` at position `2` is expected to be a symbol or a list \
of symbols";
Nucleus::atom = "Unable to determine atomic symbol";

The BoundaryMeshRegion of some rectangle is:

bmr=BoundaryMeshRegion[Rectangle[{0, 0}]]

enter image description here

and the FullForm of the atom:

nuc= Nucleus[bmr];

enter image description here

We may now change the coordinate of the first vertex. Note that the real number are written with a tick:

changed= nuc /. {0.`, 0.`} -> {0.5, 0};

Finally we may re-activate the changed rectangle:


enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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