How to pass the object name as a selectable property?
2 views (last 30 days)
Show older comments
Hi all,
I have started to use some hgtransform objects and started to group them. The idea is to build generic configurable graphical objects.
here is an axample of what I am doing:
Step 1: create the main assembly containing parts,:
ASSEMBLY = hgtransform();ASSEMBLY.Tag = 'ASSEMBLY';
PART1 = hgtransform('Parent',ASSEMBLY); PART1.Tag = 'PART1';
PART2 = hgtransform('PARENT',ASSEMBLY);PART1.Tag = 'PART2';
[cx,cy,cz]=cylinder([0.1 0.1]); % get coordinates from cylinder function
C1=surface(cz,cy,cx,'FaceColor','red','EdgeColor','none','FaceAlpha',.2,'Parent',PART1); % create a surface and assign the surface to the PART1
C1.Tag ='CYLINDER'
% PART1 contains a cylinder with a lovely red color
copyobj(PART1,PART2); %PART2 contains a cylinder with a lovely red color
%% Translate the PART2 to avoid graphic overlap
set(PART2,'Matrix', makehgtform('translate',[1 0 0]))
Step 2: change the color of the :
ASSEMBLY.Children(1).Children.FaceColor = 'blue';
As my Assembly object is containing more and more hgtransform objects, I would like to have a more usable way to compute Step2 by invoking the Tag. I would like to have my code to look like :
ASSEMBLY.PART1.Children.FaceColor = 'blue';
Or even better
ASSEMBLY.PART1.CYLINDER.FaceColor = 'blue';
What would be the most elegant way to do it without rewritting a class object ?
kind regards
Sylvain
0 Comments
Accepted Answer
Guillaume
on 21 Jan 2020
Edited: Guillaume
on 22 Jan 2020
%create the properties:
ASSEMBLY.addprop('PART1');
ASSEMBLY.addprop('PART2');
PART1.addprop('CYLINDER');
%assign a value to the properties:
ASSEMBLY.PART1 = PART1;
ASSEMBLY.PART2 = PART2;
PART1.CYLINDER = C1;
%now you can do:
ASSEMBLY.PART1.CYLINDER.FaceColor = 'blue';
It's a bit clunky however and note that dynamic properties are not copied with copyobj.
2 Comments
Guillaume
on 22 Jan 2020
edited. One annoying thing about matlab is that there's no consistent capitalisation of function names. Some functions have their second word capitalised, others don't.
More Answers (0)
See Also
Categories
Find more on Object Containers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!