Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Determine if an expression is a valid front end object
ResourceFunction["FrontEndObjectQ"][expr,t] requires expr to be a valid front end object of type t. |
| NotebookObject[…] | a currently open notebook |
| CellObject[…] | a cell in an open notebook |
| BoxObject[…] | a particular box in a cell |
| $FrontEnd | an object representing global settings for the front end |
| NotebookObject | checks if expr is a valid NotebookObject |
| CellObject | checks if expr is a valid CellObject |
| BoxObject | checks if expr is a valid BoxObject |
| patt | checks if expr matches the given pattern and is a valid front end object |
| "type" | checks if expr is a valid front end object of the named type |
| {t1,…,tn} | checks if expr is a valid front end object and has type matching one of the ti |
| "Notebook" or "NotebookObject" | NotebookObject |
| "Cell" or "CellObject" | CellObject |
| "Box" or "BoxObject" | BoxObject |
A NotebookObject that corresponds to a currently open notebook is a valid front end object:
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
If the notebook is closed, it's no longer valid:
| In[3]:= |
| In[4]:= |
| Out[4]= |
Test if a CellObject is valid:
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
If the cell is deleted, it's no longer valid:
| In[7]:= |
| In[8]:= |
| Out[8]= |
FrontEndObjectQ also works with BoxObject:
| In[9]:= |
| Out[9]= |
| In[10]:= |
| Out[10]= |
Delete one of the boxes:
| In[11]:= |
Now only one of the boxes is valid:
| In[12]:= |
| Out[12]= |
Test for a valid cell object:
| In[13]:= |
| Out[13]= |
| In[14]:= |
| Out[14]= |
Accept only cells and boxes:
| In[15]:= |
| Out[15]= |
| In[16]:= |
| Out[16]= |
Use a named type:
| In[17]:= |
| Out[17]= |
Use a pattern:
| In[18]:= |
| Out[18]= |
When a front end is available, $FrontEnd corresponds to a valid front end object:
| In[19]:= |
| Out[19]= |
When evaluated in a standalone kernel, $FrontEnd does not correspond to a valid front end object:
| In[20]:= |
| Out[20]= |
The full form of a valid cell object is CellObject[id], where id is an integer that corresponds to a serial number that is unique to that cell for the front end session:
| In[21]:= |
| Out[21]= |
| In[22]:= |
| Out[22]= |
| In[23]:= |
| Out[23]= |
Not all expressions of the form CellObject[id] are valid front end objects:
| In[24]:= |
| Out[24]= |
| In[25]:= |
| Out[25]= |
| In[26]:= |
| Out[26]= |
The full form of a valid box object is BoxObject[id], where id is an integer that corresponds to a serial number that is unique to that box structure for the front end session:
| In[27]:= |
| Out[27]= |
| In[28]:= |
| Out[28]= |
| In[29]:= |
| Out[29]= |
Not all expressions of the form BoxObject[id] are valid front end objects:
| In[30]:= |
| Out[30]= |
| In[31]:= |
| Out[31]= |
| In[32]:= |
| Out[32]= |
$FrontEndSession and $DefaultFrontEnd are symbols that represent particular front end states and are valid front end objects:
| In[33]:= |
| Out[33]= |
| In[34]:= |
| Out[34]= |
| In[35]:= |
| Out[35]= |
These have options just like many other front end objects:
| In[36]:= |
| In[37]:= |
If a cell is overwritten with another cell, it will be represented by a new CellObject:
| In[38]:= |
| In[39]:= |
| Out[39]= |
Overwrite the cell with an identical copy:
| In[40]:= |
The new cell has replaced the old one:
| In[41]:= |
| Out[41]= |
| In[42]:= |
| Out[42]= |
Check the serial numbers:
| In[43]:= |
| Out[43]= |
To preserve cell objects, overwrite the contents of cells instead of the cells themselves:
| In[44]:= |
| In[45]:= |
| In[46]:= |
| Out[46]= |
| In[47]:= |
| Out[47]= |
Get a random BoxObject:
| In[48]:= |
| Out[48]= |
| In[49]:= |
| Out[40]= |
View the box contents:
| In[50]:= |
| Out[50]= |
Find the enclosing cell:
| In[51]:= |
| Out[51]= |
View the cell contents:
| In[52]:= |
| Out[52]= |
Get the notebook that contains the cell:
| In[53]:= |
| Out[53]= |
Get the front end that owns the notebook:
| In[54]:= |
| Out[54]= |
These are all valid front end objects:
| In[55]:= |
| Out[55]= |
This work is licensed under a Creative Commons Attribution 4.0 International License