Consulting

Results 1 to 7 of 7

Thread: Freeform Nodes

  1. #1

    Freeform Nodes

    [VBA]
    With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 209.25, 170.25)
    .AddNodes msoSegmentCurve, msoEditingAuto, 333.75, 138#
    .AddNodes msoSegmentCurve, msoEditingAuto, 458.25, 189.75
    .AddNodes msoSegmentCurve, msoEditingAuto, 551.25, 306.75
    .AddNodes msoSegmentCurve, msoEditingAuto, 252.75, 318#
    .ConvertToShape.Select
    End With
    [/VBA]

    The code above is what I recorded by drawing a freeform. There are totally 5 nodes in the freeform.
    When I right click on the freeform, it contains 5 nodes.

    However, I count the nodes by using the statement below:
    MsgBox ActiveSheet.Shapes("Free1").Nodes.Count

    I got a message:13.

    Do you know why? Thanks!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Tiger,
    When you post code, please select it and click the VBA button to format it as shown.
    regards
    MD
    BTW, I liked the clock.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    oh, thanks for reminding. This is a good tool.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    I do not know for certain bu perhaps it is because the nodes actually run form (less decimal points)
    209 to 170
    170 to 333
    333 to 138
    138 to 458
    458 to 189
    189 to 551
    551 to 306
    306 to 252
    252 to 318
    318 to 333

  5. #5
    Its because your segment sections are msosegmentcurves. Can't really explain what MS did with this but if you use msosegmentlines you obviosly get straight lines between points and there will be the same number of "visible" points as in the .count property.

    In your example you have 5 points but two of what i call "Control" points for each internal visible point and 1 for each of the end points when you make each segment an msosegmentcurves and hey hey 13 points in all.

    I presume its to do with the control anchor points that are created when you set the segmenttype to curve see graphic at the bottom

    [vba]
    Dim node As ShapeNode
    Dim NodeIndex As Long
    'create graphic with msosegmentlines
    With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 209.25, 170.25)
    .AddNodes msoSegmentLine, msoEditingAuto, 333.75, 138#
    .AddNodes msoSegmentLine, msoEditingAuto, 458.25, 189.75
    .AddNodes msoSegmentLine, msoEditingAuto, 551.25, 306.75
    .AddNodes msoSegmentLine, msoEditingAuto, 252.75, 318#
    .ConvertToShape.Select
    End With
    NodeIndex = 1
    'Change each segmentline to a curve
    For Each node In ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Nodes
    Selection.ShapeRange.Nodes.SetSegmentType NodeIndex, msoSegmentCurve
    'increment by 3 to account to control nodes
    NodeIndex = NodeIndex + 3
    Next
    [/vba]
    Last edited by MountainVogu; 07-09-2006 at 09:59 PM.

  6. #6
    Thanks! This is an exciting finding!

    We can use segmenttype property to find out the segment type. If it is msosegmentline (0), actual nodes = x;

    if it is msosegmentcurve, actual nodes = 2 + 2 + (x-2)*3

    X is the nodes we can see directly.

  7. #7
    No problem glad to help.

    remember when setting the position of an actual point the 2 control points will also move by the same amount in both x and y planes.

    But when setting the position of a control point it will pivot the plane between the points around the actual point.

    Best thing to do is have a play by recording a macro and looking and what it does, it will also clearly show you which point is being manipulated.

    .ShapeRange.Nodes.SetPosition nodeindex, xpos,ypos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •