help, how can i get all the name of shape in a page including those in group?

Started by felong, April 07, 2010, 06:01:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

felong

hi all, how can i get all the name of shape in a page including those in group?
i am writing a tool in drawingctrl (activex mode), i need to fetch all shapes' charecters & names & ids , i can not fetch those in a group now.
help me! ???


AndyW

You will need to recurse through the shape collections for each shape on the page, e.g.

Public Sub listShapesOnPage()

    Dim vsoShape As Visio.Shape
   
    For Each vsoShape In Visio.ActivePage.Shapes
   
        Call listShapes(vsoShape, 0)

    Next
   
End Sub

Public Sub listShapes( _
    ByRef vsoShape As Visio.Shape, _
    ByVal intLevel As Integer)

    Dim vsoSubShape As Visio.Shape
   
    Debug.Print Space(intLevel * 4); vsoShape.Name, vsoShape.ID
   
    For Each vsoSubShape In vsoShape.Shapes
   
        Call listShapes(vsoSubShape, intLevel + 1)
       
    Next
   
End Sub

Live life with an open mind

felong

thanks for ur answer!
but i still want to ask a basic questions.
  how can i fetch the shapes in a shape grouped?
    iusing iterationmode/ containingshape prop cant fetch?
   
:'(

Quote from: AndyW on April 07, 2010, 07:05:41 AM
You will need to recurse through the shape collections for each shape on the page, e.g.

Public Sub listShapesOnPage()

    Dim vsoShape As Visio.Shape
   
    For Each vsoShape In Visio.ActivePage.Shapes
   
        Call listShapes(vsoShape, 0)

    Next
   
End Sub

Public Sub listShapes( _
    ByRef vsoShape As Visio.Shape, _
    ByVal intLevel As Integer)

    Dim vsoSubShape As Visio.Shape
   
    Debug.Print Space(intLevel * 4); vsoShape.Name, vsoShape.ID
   
    For Each vsoSubShape In vsoShape.Shapes
   
        Call listShapes(vsoSubShape, intLevel + 1)
       
    Next
   
End Sub



felong

that is to say, i can not get the info when i selected a subsharp of a group.
step:
1   select a subsharp of a group.
2    set its iterationmode to skipsuper & only sub.
3   USE  drawingctrl.window.selection.count , it return 0, it cant recognize that i had selected one.

ps
How to know a shape is a group?

thanks !!

meks

Hello felong,

Open the drawing explorer window to view all the shapes inside your drawing, even the grouped ones. You would know if the shape is in a group if it has collapsable + sign on the left side of the name, it just means that the master shape/ regualr shape has shapes inside too.

The drawing explorer window can be found in View Menu>>drawing explorer window. Expand all to see all the list of our shapes in your drawing.

Regards.

felong

hi meks

thank you, i dont know how to open drawing explorer window ,and i want to get it by code, not by visio itself.

can u tell me how can i fetch those by code?

Quote from: meks on April 07, 2010, 08:30:57 AM
Hello felong,

Open the drawing explorer window to view all the shapes inside your drawing, even the grouped ones. You would know if the shape is in a group if it has collapsable + sign on the left side of the name, it just means that the master shape/ regualr shape has shapes inside too.

The drawing explorer window can be found in View Menu>>drawing explorer window. Expand all to see all the list of our shapes in your drawing.

Regards.

Yacine

Felong, You're right. The selection object is empty, when the selection is a sub-shape.  ???
Public Sub listSubShapesOfSelection()
   Dim vsoShape As Visio.Shape
     If ActiveWindow.Selection.Count > 0 Then
   Set vsoShape = ActiveWindow.Selection.Item(1)
       Call listShapes(vsoShape, 0)
   End If
End Sub

Public Sub listShapes( _
   ByRef vsoShape As Visio.Shape, _
   ByVal intLevel As Integer)
   Dim vsoSubShape As Visio.Shape
   Debug.Print Space(intLevel * 4); vsoShape.Name, vsoShape.ID
   For Each vsoSubShape In vsoShape.Shapes
       Call listShapes(vsoSubShape, intLevel + 1)
   Next
End Sub
Yacine

Paul Herber

Quote from: Yacine on April 07, 2010, 08:38:49 AM
Felong, You're right. The selection object is empty, when the selection is a sub-shape.  ???

This is a right pain in the proverbial, I've found this in the past, the user can plainly see that a shape is selected but all software can see is an empty selection!
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

felong

thank u

i cant follow ur direction completly for i am using another tool.
and i cant find the method "IN" to see if the subshape in a selected group.

for example, i write some code to Print the subshapes in a shape (or a group),BUT IT DIDNT WORK!

could u tell me how can i do this?
thanks!

----------------------------------
In Delphi 7 code
----------------------------------
procedure TForm1.Button6Click(Sender: TObject);
var i,j:integer;
    s,ss,sstatus:string;
    sl:TStringList;
    sel:IVSelection;
    shp:IVShape;
begin
     DrawingControl1.Window.Selection.IterationMode:=visSelModeSkipSuper+visSelModeOnlySub;
     if DrawingControl1.Window.Selection.Count > 0 then
     begin
         sl:=TStringList.Create;
          sel:=DrawingControl1.Window.Selection;

         for i:=1 to sel.Count do
         begin
          for j:=1 to sel.Item.ContainingShape.Shapes.Count do
          begin
              shp:= sel.Item.ContainingShape.Shapes.Item[j];
              ss:=' sID:'+inttostr(shp.ID)+'; sName:'+shp.NameU+'; Char:'+shp.Characters.Text+#13;
          end;
              if sel.ItemStatus=visSelIsSuperItem then sstatus:='SelIsSuperItem';
              if sel.ItemStatus=visSelIsPrimaryItem then sstatus:='SelIsPrimaryItem';
              if sel.ItemStatus=visSelIsSubItem then sstatus:='SelIsSubItem';

              s:=
              inttostr(sel.Item.ID)+
              ' >> '+ sel.Item.Name+
              ' >> '+ sel.Item.Characters.Text+
              ' >> '+sstatus+
              ' >>Has SubShapes --'+ ss;
              sl.Add(s);

         end;
         memo1.Lines.Assign(sl);
         sl.Free;
     end
end;



Quote from: Yacine on April 07, 2010, 08:38:49 AM
Felong, You're right. The selection object is empty, when the selection is a sub-shape.  ???
Public Sub listSubShapesOfSelection()
   Dim vsoShape As Visio.Shape
     If ActiveWindow.Selection.Count > 0 Then
   Set vsoShape = ActiveWindow.Selection.Item(1)
       Call listShapes(vsoShape, 0)
   End If
End Sub

Public Sub listShapes( _
   ByRef vsoShape As Visio.Shape, _
   ByVal intLevel As Integer)
   Dim vsoSubShape As Visio.Shape
   Debug.Print Space(intLevel * 4); vsoShape.Name, vsoShape.ID
   For Each vsoSubShape In vsoShape.Shapes
       Call listShapes(vsoSubShape, intLevel + 1)
   Next
End Sub


felong

i just found a BAD idea that i ungroup all the shapes, so i can fetch the info.
but it is a so bad idea, so bad! :'(

Quote from: Paul Herber on April 07, 2010, 08:45:26 AM
Quote from: Yacine on April 07, 2010, 08:38:49 AM
Felong, You're right. The selection object is empty, when the selection is a sub-shape.  ???

This is a right pain in the proverbial, I've found this in the past, the user can plainly see that a shape is selected but all software can see is an empty selection!


Yacine

A very bad idea indead: even if you would "duplicate - ungroup - process - regroup - delete", you DON'T KNOW what to handle. The software is not telling you, what the user selected!

By the way, why not use VBA, until you get the basic process running? Wouldn't it be easier? VBA comes along with Visio.

And for the drawing explorer, you'll find it under the View menu.
Yacine

Paul Herber

Quote from: felong on April 07, 2010, 08:56:47 AM
i just found a BAD idea that i ungroup all the shapes, so i can fetch the info.
but it is a so bad idea, so bad! :'(
Bad, bad, so bad!
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

felong

hi all
How to know a shape is a group through DrawingCtrl?
How to know how many shapes in that group?
How to fetch each of them one by one?
i am a greenhand, thank you so much! :'(

felong

i want do something with a large number of visio files, with file management , viewing visio file, search one or more info in all files.
position the element(shape) in my program.
so i select another tool i am good at.

ps, i should get the GROUP INFO by code, not with UI. of visio.

Quote from: Yacine on April 07, 2010, 09:03:15 AM
A very bad idea indead: even if you would "duplicate - ungroup - process - regroup - delete", you DON'T KNOW what to handle. The software is not telling you, what the user selected!

By the way, why not use VBA, until you get the basic process running? Wouldn't it be easier? VBA comes along with Visio.

And for the drawing explorer, you'll find it under the View menu.