pasteTo
Paste objects in clipboard to specified container object
Description
Examples
Copy and Paste by Grouping
Group state A
and copy its contents to chart ch
.
When you group a state, box, or graphical function, you can copy and paste all the
objects contained in the grouped object, as well as all the relationships among these
objects. This method is the simplest way of copying and pasting objects
programmatically. If a state is not grouped, copying the state does not copy any of its
contents.
Find the
Stateflow.State
object namedA
in chartch
.sA = find(ch,"-isa","Stateflow.State",Name="A");
Group state
A
and its contents by setting theIsGrouped
property forsA
totrue
. Save the previous setting of this property so you can revert to it later.prevGrouping = sA.IsGrouped; sA.IsGrouped = true;
Change the name of the state to
Copy_of_A
. Save the previous name so you can revert to it later.prevName = sA.Name; newName = "Copy_of_"+prevName; sA.Name = newName;
Access the clipboard object.
cb = sfclipboard;
Copy the grouped state to the clipboard.
copy(cb,sA);
Restore the state properties to their original settings.
sA.IsGrouped = prevGrouping; sA.Name = prevName;
Paste a copy of the objects from the clipboard to the chart.
pasteTo(cb,ch);
Adjust the state properties of the new state.
sNew = find(ch,"-isa","Stateflow.State",Name=newName); sNew.Position = sA.Position + [400 0 0 0]; sNew.IsGrouped = prevGrouping;
Copy and Paste Array of Objects
Copy states A1
and A2
, along with the transition
between them, to a new state in chart ch
. To preserve transition
connections and containment relationships between objects, copy all the connected
objects at once.
Find the
Stateflow.State
object namedA
in chartch
.sA = find(ch,"-isa","Stateflow.State",Name="A");
Add a new state called
B
. To enable pasting of other objects insideB
, convert the new state to a subchart.sB = Stateflow.State(ch); sB.Name = "B"; sB.Position = sA.Position + [400 0 0 0]; sB.IsSubchart = true;
Create an array called
objArray
that contains the states and transitions in stateA
. Use the functionsetdiff
to remove stateA
from the array of objects to copy.objArrayS = find(sA,"-isa","Stateflow.State"); objArrayS = setdiff(objArrayS,sA); objArrayT = find(sA,"-isa","Stateflow.Transition"); objArray = [objArrayS objArrayT];
Access the clipboard object.
cb = sfclipboard;
Copy the objects in
objArray
and paste them in subchartB
.copy(cb,objArray); pasteTo(cb,sB);
Revert
B
to a state.sB.IsSubchart = false; sB.IsGrouped = false;
Reposition the states and transitions in
B
.newStates = find(sB,"-isa","Stateflow.State"); newStates = setdiff(newStates,sB); newTransitions = find(sB,"-isa","Stateflow.Transition"); newOClocks = get(newTransitions,{"SourceOClock","DestinationOClock"}); for i = 1:numel(newStates) newStates(i).Position = newStates(i).Position + [25 35 0 0]; end set(newTransitions,{"SourceOClock","DestinationOClock"},newOClocks);
Input Arguments
clipboard
— Clipboard
Stateflow.Clipboard
object
Clipboard, specified as a Stateflow.Clipboard
object.
parent
— Parent for copied objects
Stateflow.Chart
object | Stateflow.State
object | Stateflow.Box
object | Stateflow.Function
object | ...
Parent for the copied objects, specified as a Stateflow® API object of one of these types:
If the objects in the clipboard are all graphical (states, boxes, functions, annotations, transitions, or junctions), this object must be a chart or subchart.
Tips
When you paste graphical objects, the new parent must be a chart or a subchart. To
convert a state, box, or graphical function to a subchart, set its
IsSubchart
property to true
. After pasting,
you can revert the parent by setting its IsSubchart
and
IsGrouped
properties to false
.
Version History
Introduced before R2006a
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)