MATLAB: How to pass the object name as a selectable property

classclass properties

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

Best Answer

You can, since hgtransform support dynamic properties, so you could do something like:
%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.