PDA

View Full Version : Freeform Nodes



Tiger Chen
07-08-2006, 02:10 AM
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


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!

mdmackillop
07-08-2006, 02:23 AM
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.

Tiger Chen
07-08-2006, 05:32 AM
oh, thanks for reminding. This is a good tool.

OBP
07-08-2006, 08:04 AM
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

MountainVogu
07-09-2006, 09:46 PM
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


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

Tiger Chen
07-10-2006, 12:48 AM
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.

MountainVogu
07-10-2006, 02:21 PM
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