Remove Shapes from a Part

My question is that
I have drawn my nodeTemplate with some nodes
Now on the top of that I am adding a part
for example :

$scope.myDiagram.add($scope.gj(go.Part, {layerName: “lines”, name: “linePart”},

$scope.gj(go.Shape, {
position: new go.Point(x,y),
geometry: verticalLine
}),

I am adding multiple shapes inside this part.
Now my question is what is the best way to remove some shapes that are already drawn.
Is there a way to remove shapes same as we remove parts using removeParts() function?
Can I iterate through all the shapes inside a part and remove some of them say by name?

A little help over here will be appreciated

Thanks

Sure, call methods on Panel such as http://gojs.net/latest/api/symbols/panel.html#remove or http://gojs.net/latest/api/symbols/panel.html#removeAt.

Panel.elements lets you iterate over all of them. But remember that you cannot continue iterating over a collection after modifying the collection by removing (or adding) elements. Either iterate over a copy of the collection or collect the elements to be removed and remove them all afterwards.

Thanks @walter
I tried it but It didn’t worked for me
I am iterating through parts then after I get the right Part I am iterating through elements of that part and then trying to remove it. But it is not working.

I am not using any Panel so have no idea how to iterate through Panel.elements

$scope.removeLines = function () {
$scope.myDiagram.startTransaction(“remove Lines”);
var it = $scope.myDiagram.parts;
var collectionOfParts = [];
while (it.next()) {
if (it.value.name === “linesPart”) {
var ele = it.value.elements;
while (ele.next()) {
if (ele.value.name === “vLeftTop”) {
collectionOfParts.push(ele.value);
// $scope.myDiagram.parts.remove(ele.value);
}
}
}
}
_.forEach(collectionOfParts, function (element) {
$scope.myDiagram.remove(element);
// });
$scope.myDiagram.commitTransaction(“Add lines”);
$scope.myDiagram.requestUpdate();
};

Sharing a part of my my node template for clear understanding
I am adding my part later after drawing this template.
I hope you got my point

scope.myDiagram.nodeTemplate =
scope.gj(go.Node, “Spot”, {background: “DarkGray”}, // Part instead of Node, assuming no Links!
/** TODO: Stay in the Fixed area :Singh**/
// {dragComputation: stayInFixedArea},
// get the size from the model data

                        new go.Binding("desiredSize", "size", go.Size.parse),
                        // get and set the position in the model data
                        new go.Binding("position", "pos", go.Point.parse).makeTwoWay(go.Point.stringify),
                        // temporarily put selected nodes in Foreground layer
                        new go.Binding("layerName", "isSelected", function (s) {
                            return s ? "Foreground" : "";
                        }).ofObject(),
                        scope.gj(go.Shape, "Rectangle",
                            {
                                strokeWidth: 0                                 

                            },  // avoid extra thickness from the stroke
                            new go.Binding("fill", "color"),
                            new go.Binding("margin", "bleedOffset")
						),

                        ......................................................

The Part class inherits from the Panel class, http://gojs.net/latest/api/symbols/Part.html. (Hence, as do the Node and Link classes.)