# Pattern not matching BoundaryMeshRegion

Mathematica 13.1 on Windows 10.

Can someone explain why the following does not match:

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

(* False *)

• mesh regions are atomic, which makes them opaque to the pattern matcher. If you use _BoundaryMeshRegion as a pattern it will work. Commented Sep 8, 2022 at 13:28
• does this work for you?If you prevent evaluation of the left side, then it does match MatchQ[Unevaluated@BoundaryMeshRegion[Cube[]], BoundaryMeshRegion[___]] gives True Commented Sep 8, 2022 at 13:32
• @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. Commented Sep 8, 2022 at 13:34
• 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 Commented Sep 8, 2022 at 13:46
• @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. Commented Sep 8, 2022 at 13:46

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 =
Message[Nucleus::atom]; $$Failed], h_Symbol :> {h}, h : {__Symbol} :> h, _ :> (Message[Nucleus::syms, head, 2];$$Failed)}]}, (If[!
MemberQ[Links[], $$AtomLink] || LinkReadyQ[$$AtomLink],
Quiet@LinkClose[$$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}],
Hold[body]]

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}]]


and the FullForm of the atom:

nuc= Nucleus[bmr];
FullForm[nuc]


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:

Activate[changed]