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 件のコメント
Cris LaPierre
2024 年 5 月 17 日
What error are you getting? Please share all the red text.
採用された回答
> 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 件のコメント
Cris LaPierre
2024 年 5 月 17 日
The relevant doc page is found here: Display Graphics in App Designer
Adam Danz
2024 年 5 月 17 日
Thanks @Cris
Note that the solution I recommend takes two additional steps than the doc example "Use Functions with No Target Argument".
- It records and restores the original HandleVisible value rather than assuming it was "off".
- 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.
Jigar
2024 年 5 月 17 日
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.
Adam Danz
2024 年 5 月 17 日
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
Cris LaPierre
2024 年 5 月 18 日
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

Jigar
2024 年 5 月 18 日
Thanks so much, it is working. It seems i cannot use pde as property and use it in other function.
Cris LaPierre
2024 年 5 月 18 日
編集済み: Cris LaPierre
2024 年 5 月 20 日
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.
editing
I take my words back. It is working with an app property. Thanks for all the help!
Adam Danz
2024 年 5 月 20 日
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Geometry and Mesh についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
