Stl file pdegplot in App designer

Hi,
I am looking for a solution to find names of the faces after importing the stl file. pdegplot command does that but how can I use it in App Designer. I am trying the command but it throws different error. Looked for a solution but it isn't available.
Is there any other command where i can use it to see name faces in the App designer so that i can use it to apply BC.
Thanks,
Jigar

1 Comment

What error are you getting? Please share all the red text.

Sign in to comment.

 Accepted Answer

> pdegplot command does that but how can I use it in App Designer?
pdegplot does not have an input argument or property to specify the parent axes. This often poses a propblem in AppDesigner and uifigures in general since the default HandleVisible property in uifigures is 'off'. This prevents pdegplot from finding the axes within the uifigure resulting in the generation of a new figure external to the app.
I suppose this is the problem you're running into.
This workaround describes how to temporarily make the app's axes accessible and current so that the pdegplot will add content to the existing axes.
Here's a quick example. See the previous link for details.
% Mimick an app
app.UIFigure = uifigure();
app.UIAxes = uiaxes(app.UIFigure);
% Change handle visibility
origState = app.UIFigure.HandleVisibility;
handleVisCleanup = onCleanup(@()set(app.UIFigure,'HandleVisibility',origState));
app.UIFigure.HandleVisibility = 'on';
% Make axes current
set(groot, 'CurrentFigure', app.UIFigure)
set(app.UIFigure,'CurrentAxes',app.UIAxes)
% Plot pdegplot
g = [2 1 1 1 1 1 1 1 1 4 4;
-1 -0.6 -0.5 -0.4 -0.5 0.4 0.5 0.6 0.5 -1 0.17;
1 -0.5 -0.4 -0.5 -0.6 0.5 0.6 0.5 0.4 0.17 1;
0 -0.25 -0.35 -0.25 -0.15 -0.25 -0.35 -0.25 -0.15 0 -0.74;
0 -0.35 -0.25 -0.15 -0.25 -0.35 -0.25 -0.15 -0.25 -0.74 0;
0 0 0 0 0 0 0 0 0 1 1;
1 1 1 1 1 1 1 1 1 0 0;
0 -0.5 -0.5 -0.5 -0.5 0.5 0.5 0.5 0.5 0 0;
0 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 0 0;
0 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 1 1;
0 0 0 0 0 0 0 0 0 0.75 0.75;
0 0 0 0 0 0 0 0 0 0 0];
pdegplot(g)

10 Comments

The relevant doc page is found here: Display Graphics in App Designer
Thanks @Cris
Note that the solution I recommend takes two additional steps than the doc example "Use Functions with No Target Argument".
  1. It records and restores the original HandleVisible value rather than assuming it was "off".
  2. It programmatically makes the selected axes current. This is particularly useful when the app has more than one axes or if another figure+axes exists.
Hi @Adam Danz and @Cris LaPierre, thanks for your inputs. Below is the error I encountered while executing the code:
Error using pdeigeom
Index in position 1 exceeds array bounds.
Error in pdegplot>plotTwoDGeometry (line 113)
d=pdeigeom(g,1:nbs);
Error in pdegplot (line 100)
hh = plotTwoDGeometry(g, plotVertexLabels, plotEdgeLabels, plotSubLabels);
Error in app1/UpdateButtonPushed (line 100)
createGeometryPlot(app);
I tried with your Matlab code:
function createGeometryPlot(app)
% Mimick an app
app.UIFigure = uifigure();
app.UIAxes = uiaxes(app.UIFigure);
% Change handle visibility
origState = app.UIFigure.HandleVisibility;
handleVisCleanup = onCleanup(@()set(app.UIFigure,'HandleVisibility',origState));
app.UIFigure.HandleVisibility = 'on';
% Make axes current
set(groot, 'CurrentFigure', app.UIFigure)
set(app.UIFigure,'CurrentAxes',app.UIAxes)
% Plot the geometry using pdegplot
pdegplot(app.smodel, 'FaceLabels', 'on', 'FaceAlpha', 0.5);
end
what did I miss? Also I am using R2022a. Thanks again for your inputs.
Let's get some more information about app.smodel.
What is it?
class(app.smodel)
How was it created?
Can you share the reproduction steps so we can create it?
Sharing properties and methods that i have created.
properties (Access = private)
new_x % Description
new_y
new_z
range_z
stlFile
smodel
end
methods (Access = public)
function results = func(app)
app.smodel = createpde('structural','static-solid');
importGeometry(app.smodel,app.stlFile);
face_in_geom = ;
end
function createGeometryPlot(app)
% Mimick an app
app.UIFigure = uifigure();
app.UIAxes = uiaxes(app.UIFigure);
% Change handle visibility
origState = app.UIFigure.HandleVisibility;
handleVisCleanup = onCleanup(@()set(app.UIFigure,'HandleVisibility',origState));
app.UIFigure.HandleVisibility = 'on';
% Make axes current
set(groot, 'CurrentFigure', app.UIFigure)
set(app.UIFigure,'CurrentAxes',app.UIAxes)
% Plot the geometry using pdegplot
pdegplot(app.smodel,"FaceLabels","on","FaceAlpha",0.5);
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: FileuploadButton
function FileuploadButtonPushed(app, event)
[filename, pathname] = uigetfile({'*.stl'},'File Selector');
if ~isequal(filename,0)
app.stlFile = fullfile(pathname,filename);
%app.stepFile = fullfile(pathname,filename);
[F,~] = stlread(app.stlFile);
% Do something with F and V
x=F.Points(:,1);
y=F.Points(:,2);
z=F.Points(:,end);
min_x=min(x);
min_y=min(y);
min_z=min(z);
app.new_x = x-min_x;
app.new_y = y-min_y;
app.new_z = z-min_z;
Max_point_z = max(app.new_z);
Max_point_x = max(app.new_x);
Max_point_y = max(app.new_y);
app.FileNameLabel.Text = filename;
app.SummaryTextArea.Value = sprintf(['File uploaded successfully!\nMax_point in z direction = %f \n' ...
'Max_point in x direction = %f \nMax_point in y direction = %f \nPlease click on Update button'],...
Max_point_z,Max_point_x,Max_point_y);
app.SummaryTextArea.FontColor = 'b';
app.FileuploadButton.BackgroundColor = [0.98,0.88,0.85];
app.UpdateButton.BackgroundColor = [0.86,0.95,0.82];
app.UpdateButton.Enable = "on";
else
app.SummaryTextArea.Value = 'File upload failed.';
app.SummaryTextArea.FontColor = 'r';
app.FileuploadButton.BackgroundColor = [0.86,0.95,0.82];
app.UpdateButton.BackgroundColor = [0.98,0.88,0.85];
app.FileNameLabel.Text = "File Name";
app.UpdateButton.Enable = "off";
return;
end
end
% Button pushed function: UpdateButton
function UpdateButtonPushed(app, event)
%pdeplot3D(app.smodel,"ElementLabels","on","FaceAlpha",0.5);
%app.UIFigure.HandleVisibility = 'callback';
createGeometryPlot(app);
%app.UIFigure.HandleVisibility = 'off';
end
end
Using Adam's solution, I created the following callback function in app designer that loaded and displayed an STL file in an axes component in my app.
function FileUploadButtonPushed(app, event)
[filename, pathname] = uigetfile({'*.stl'},'File Selector');
app.stlFile = fullfile(pathname,filename);
model = createpde;
importGeometry(model,fullfile(pathname,filename));
% Change handle visibility
origState = app.UIFigure.HandleVisibility;
handleVisCleanup = onCleanup(@()set(app.UIFigure,'HandleVisibility',origState));
app.UIFigure.HandleVisibility = 'on';
set(groot, 'CurrentFigure', app.UIFigure)
set(app.UIFigure,'CurrentAxes',app.UIAxes)
pdegplot(model,"FaceLabels","on")
end
My blank canvas looks like this
When I launch the app and select an stl file, it looks like this
Thanks so much, it is working. It seems i cannot use pde as property and use it in other function.
Cris LaPierre
Cris LaPierre on 18 May 2024
Edited: Cris LaPierre on 20 May 2024
Could you provide more details about what you mean? You have no variable named pde, and pdeplot is a function, not a property.
In the code I shared, you could make model an app property, and use that in other functions.
Jigar
Jigar on 19 May 2024
Edited: Jigar on 19 May 2024
editing
I take my words back. It is working with an app property. Thanks for all the help!
Glad that it all worked out, thanks for the demo @Cris LaPierre!

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Asked:

on 17 May 2024

Edited:

on 20 May 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!