Stl file pdegplot in App designer
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.
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

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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
