• import and export freeform as XY in PPT ( PPT 2002 SP-2)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » import and export freeform as XY in PPT ( PPT 2002 SP-2)

    Author
    Topic
    #408325

    In PPT, I would like to import a freeform from a tabulated ASCII file. Example XY coordinates and ASCII file format:

    479913.344 7647915.000999999999999 7 1
    480081.844 7648068.000999999999999 7 1
    480273.313 7648175.500999999999999 7 1
    480510.719 7648336.000999999999999 7 1
    480112.469 7648305.500999999999999 7 1
    479691.219 7647769.500999999999999 7 1

    I also want to export or write the freeform into the same format. So that if I modify the shape, I can save it and export it.

    I figured out how to create the freeform (re-scaling and shifting in XY to plot it in the work area), playing with WordPad, Excel, and PPT.

    But I need help with the commands to read from an ASCII file, write to an ASCII file, and getting the XY coordinates for each of the vertices.

    Can anyone help?

    Thank you.

    Viewing 1 reply thread
    Author
    Replies
    • #861149

      You have at least two options for reading tab-delimited data from a text file: VB’s built-in file I/O commands, and the Scripting Library’s FileSystemObject and TextStream objects. You can find examples of both here in the Lounge.

      Once you have your text file open, you can read in a line at a time of text into a variable. However, you can make your life easier by reading it into a dynamic array. I think the array typically is of a string type, but that’s okay, you can convert the data as needed once you have it stored. So, for example, hacked together from memory:

      dim strArray() as String
      … ‘here you’re in a loop, until oStream EOF
      strArray = Split(oStream.ReadLine, vbTab)
      … ‘interate over your array to use the data and then loop

      Does this help?

      • #861157

        this is great help! blackteeth

        I’ll have to experiment with the code, and re-write my routines.

        in PPT 2002, how do I get the XY coordinates of each vertice of the freeform, so I can export to a new ASCII in case I edit my freeforms? something like…

        width selection.shape
        width shape
        for each vertice ………..?

        Thank you

        • #861262

          (Edited by jscher2000 on 06-Aug-04 16:47. Replaced picture.)

          Okay, first I had to figure out what a free form is. grin As you can see, I’m not a good artist. One hand-drawn semi-rectangle has a collection of 27 Nodes or 28 Vertices. It looks as though the Vertices collection is easier to work with if you don’t need the other information available in the Nodes collection.

          The values in these collections are in points (72 per inch), measured from 0,0 at the upper left of the slide. I’m not sure how that compares with the data you listed in your first post; those numbers are much, much larger. Are they in “twips” (units of screen display, something like 1440 to an inch)?

          I suggest you use a counter and a For loop from 1 to the size of the Vertices collection, and write out the two number with a tab in between. I don’t know what the other data elements in your data represent, but maybe this is enough to get you to the next step?

          As for the mechanics of identifying a particular shape on a slide, the first couple of shapes on a slide usually are placeholders for text (defined in the Master slide). I find the concept of the selection hard to work with in PowerPoint, so even I probably would comb through the Shapes looking for a FreeForm. Hopefully the PPT code gurus will have a better solution.

          • #861308

            Jefferson,

            How did you get all the properties of the object into local variables so you could view them like that?

            StuartR

          • #861309

            Jefferson,

            How did you get all the properties of the object into local variables so you could view them like that?

            StuartR

            • #861355

              The easy way would be, insert a procedure (if necessary) then set a breakpoint. Run sub. While in Break mode, view Locals Window. See attached pic. You can start at top of tree and drill down thru Application Object, ActivePresentation, Slides, Shapes, etc & view properties/values for each object in open project. NOTE: The code in this project is using an object variable (app) that references the current instance of PPT Application object. Though just about any object variable that references an object in active presentation should work, since just about every object (such as a Shape) has an Application property that returns a reference to the Application object, which you could then drill down thru in the Locals window. Of course, the object variable would have to be in scope when entering Break mode.

              HTH

            • #861415

              Mark,

              Thanks (to you and Jefferson) for the education.

              StuartR

            • #861807

              As a VB begginer, I am learning a lot here! cool

              I am trying to plot in power point some shapes or polygons I have in a map. The polygons have XY rectangular coordinates (Gauss Kruger). That’s why the numbers are so big. They are in meters, and I am mapping features that are km in size. So I re-scaled and shifted all of the nodes to fit them in the drawing area(with excel, but formulas are very easy to include in a ppt macro).

              I see that, ppt could have a limitation from the point of view of canvas size and point location accuracy, if I wanted to edit an object and export to a map. So I’ve modified my project to do the following:

              What I want to do now is plot a number of shapes from an ASCII file. Select some and delete. Write to an ASCII file the remaining shapes. So my workflow would be something like this:

              1. Read an ASCII file
              2. Locate Upperleft most and Lowerright most data points to define extent of “map” and scaling parameters to make the polygons fit the drawing area, without distortion or XY apect ratio change
              3. Create the shapes reading the point data in ASCII format. The last column in my ASCII table has an ID # for each polygon. Name the shapes with that ID.
              4. In ppt drawing area , select shapes and delete the ones I don’t need.
              4. Read the list of remaining shapes.
              5. Write a new ASCII file, including only the data (and shapes) that remains in the drawing area. In order not to loose the accuracy of the original XY’s, I would read the original ASCII data, locate the polygons by name and ID#
              6. Write to a new ASCII, re-numbering the shapes or polygons in the new ASCII file from 1 to n.

              Next goal: to create the shapes from several ASCII files and merge them into a new , single, ASCII.

              Why not do this in excel, in a spreadsheet? I want to be able to select the shapes in the drawing area, the way you do commonly in ppt (or any other drawing application). (Suggestions about doing this in excel only? that would be great too!)

              Piece of cake! With what you have taught me, I should be able to do this right away. cool

            • #861956

              Here’s a random thought: what if you draw the FreeForm “off slide” and then set the position to 0,0 (as on the Position tab of the Format>AutoShape dialog), lock the aspect ratio and reset the width and height to fit within your desired dimensions (as on the Size tab of that dialog). If PPT will allow it, it seems easier than doing all the math yourself. smile

            • #861983

              Because I will be importing several geographically referenced “freeforms” (polygons, > 50), I think I’d rather stick to doing the math while importing from the ASCII file. It should not be hard. Just getting X-Y min and max, slide size, setting a scaling factor, and one X-Y bulk shift for all of the polygons. I am not worried about that (I’ve set it up in excel already and made it work. With text concatenation in excel, I created most of the text macro that goes in ppt to create the polygons)

              My second thought was about doing this entirely with excel rather than ppt. Loading the data into a spreadsheet and using the autofilter sounds cool too. But I don’t know if I would be able to select the polygons from a chart or graph, and highlight them automatically on the spreadsheet (selecting the polygons with my mouse by defining a rectangle). This part sounds to be easier in ppt than excel.

            • #861984

              Because I will be importing several geographically referenced “freeforms” (polygons, > 50), I think I’d rather stick to doing the math while importing from the ASCII file. It should not be hard. Just getting X-Y min and max, slide size, setting a scaling factor, and one X-Y bulk shift for all of the polygons. I am not worried about that (I’ve set it up in excel already and made it work. With text concatenation in excel, I created most of the text macro that goes in ppt to create the polygons)

              My second thought was about doing this entirely with excel rather than ppt. Loading the data into a spreadsheet and using the autofilter sounds cool too. But I don’t know if I would be able to select the polygons from a chart or graph, and highlight them automatically on the spreadsheet (selecting the polygons with my mouse by defining a rectangle). This part sounds to be easier in ppt than excel.

            • #861957

              Here’s a random thought: what if you draw the FreeForm “off slide” and then set the position to 0,0 (as on the Position tab of the Format>AutoShape dialog), lock the aspect ratio and reset the width and height to fit within your desired dimensions (as on the Size tab of that dialog). If PPT will allow it, it seems easier than doing all the math yourself. smile

            • #861808

              As a VB begginer, I am learning a lot here! cool

              I am trying to plot in power point some shapes or polygons I have in a map. The polygons have XY rectangular coordinates (Gauss Kruger). That’s why the numbers are so big. They are in meters, and I am mapping features that are km in size. So I re-scaled and shifted all of the nodes to fit them in the drawing area(with excel, but formulas are very easy to include in a ppt macro).

              I see that, ppt could have a limitation from the point of view of canvas size and point location accuracy, if I wanted to edit an object and export to a map. So I’ve modified my project to do the following:

              What I want to do now is plot a number of shapes from an ASCII file. Select some and delete. Write to an ASCII file the remaining shapes. So my workflow would be something like this:

              1. Read an ASCII file
              2. Locate Upperleft most and Lowerright most data points to define extent of “map” and scaling parameters to make the polygons fit the drawing area, without distortion or XY apect ratio change
              3. Create the shapes reading the point data in ASCII format. The last column in my ASCII table has an ID # for each polygon. Name the shapes with that ID.
              4. In ppt drawing area , select shapes and delete the ones I don’t need.
              4. Read the list of remaining shapes.
              5. Write a new ASCII file, including only the data (and shapes) that remains in the drawing area. In order not to loose the accuracy of the original XY’s, I would read the original ASCII data, locate the polygons by name and ID#
              6. Write to a new ASCII, re-numbering the shapes or polygons in the new ASCII file from 1 to n.

              Next goal: to create the shapes from several ASCII files and merge them into a new , single, ASCII.

              Why not do this in excel, in a spreadsheet? I want to be able to select the shapes in the drawing area, the way you do commonly in ppt (or any other drawing application). (Suggestions about doing this in excel only? that would be great too!)

              Piece of cake! With what you have taught me, I should be able to do this right away. cool

            • #861416

              Mark,

              Thanks (to you and Jefferson) for the education.

              StuartR

            • #861405

              I generally blurt out a quickie temporary procedure similar to this:

              Sub SniffShape()
              dim shp as Shape
              Set shp = ActivePresentation.slides(1).shapes(3)
              stop
              set shp = nothing
              end sub

              When the procedure stops, I open the (undocked) Locals window and inspect the properties for the shp object. Mark’s approach makes more sense if you already have some real code you’re working on.

            • #861406

              I generally blurt out a quickie temporary procedure similar to this:

              Sub SniffShape()
              dim shp as Shape
              Set shp = ActivePresentation.slides(1).shapes(3)
              stop
              set shp = nothing
              end sub

              When the procedure stops, I open the (undocked) Locals window and inspect the properties for the shp object. Mark’s approach makes more sense if you already have some real code you’re working on.

        • #861263

          (Edited by jscher2000 on 06-Aug-04 16:47. Replaced picture.)

          Okay, first I had to figure out what a free form is. grin As you can see, I’m not a good artist. One hand-drawn semi-rectangle has a collection of 27 Nodes or 28 Vertices. It looks as though the Vertices collection is easier to work with if you don’t need the other information available in the Nodes collection.

          The values in these collections are in points (72 per inch), measured from 0,0 at the upper left of the slide. I’m not sure how that compares with the data you listed in your first post; those numbers are much, much larger. Are they in “twips” (units of screen display, something like 1440 to an inch)?

          I suggest you use a counter and a For loop from 1 to the size of the Vertices collection, and write out the two number with a tab in between. I don’t know what the other data elements in your data represent, but maybe this is enough to get you to the next step?

          As for the mechanics of identifying a particular shape on a slide, the first couple of shapes on a slide usually are placeholders for text (defined in the Master slide). I find the concept of the selection hard to work with in PowerPoint, so even I probably would comb through the Shapes looking for a FreeForm. Hopefully the PPT code gurus will have a better solution.

      • #861158

        this is great help! blackteeth

        I’ll have to experiment with the code, and re-write my routines.

        in PPT 2002, how do I get the XY coordinates of each vertice of the freeform, so I can export to a new ASCII in case I edit my freeforms? something like…

        width selection.shape
        width shape
        for each vertice ………..?

        Thank you

    • #861150

      You have at least two options for reading tab-delimited data from a text file: VB’s built-in file I/O commands, and the Scripting Library’s FileSystemObject and TextStream objects. You can find examples of both here in the Lounge.

      Once you have your text file open, you can read in a line at a time of text into a variable. However, you can make your life easier by reading it into a dynamic array. I think the array typically is of a string type, but that’s okay, you can convert the data as needed once you have it stored. So, for example, hacked together from memory:

      dim strArray() as String
      … ‘here you’re in a loop, until oStream EOF
      strArray = Split(oStream.ReadLine, vbTab)
      … ‘interate over your array to use the data and then loop

      Does this help?

    Viewing 1 reply thread
    Reply To: Reply #861157 in import and export freeform as XY in PPT ( PPT 2002 SP-2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel