The documentation for the tree nodes and the tree node manager is basically non existent! It seems that it offers some powerful functionality but a decent understand of what it does and how it works alludes me. I am going to investigate it and experiment as much i can; findings to follow. In the mean time if anyone has any examples or knowledge of the matter a post would be much appreciated!
The only links of any use I can find are:
Some nice but limited examples: https://forum.oberonplace.com/showthread.php?t=6823
Wiki Page on the tree data structure: https://en.wikipedia.org/wiki/Tree_(data_structure) (Not sure how relevant this is)
My goal is to make a function that reduces the undo steps on long operations by moving the shapes to a temp document, doing its thing then bringing the shapes back to the original
document and replacing the original shapes with the processed ones. Effectively making a undo with 1000's of steps into one shape swap. I think their might be value in tree nodes, the tree node manger and virtual shapes.
Thanks
No worries! I felt bad calling you for help but these are desperate times [:|] I have reached my end with trying to figure out how to get it to work. It just seems that using tree nodes to pass from one document to another isn't possible!
Just to reiterate I want a function i can call to pass a shaperange onto a new document. Process the shapes then return the shaperange back to the original document replacing the original shaperange with the new one. The ultimate goal is so on operations where there is potentially 10,000's of events; you only get one undo on the document that is instant.
My current feeling is it has to be two functions; one for starting the process and another for returning it... sadly the returning part (using the treenodes) is becoming unstable when the switch is undone. If i use undo once or twice then try to close the document Corel crashes.
I know it could done with copy and pasting but the clipboard is apparently sacred in our office and importing is too slow. Given how elegant and quick the .CreateDocumentFrom is I just need a reliable way of returning the shapes.
The Macro in question is for applying Inside and out fillets to shapes mainly for making the paths suitable for machining. Code below and .Gms attached. Any help or even suggestions would be wonderful. Getting this to work could be really useful for a lot of heavy process macros so no need for PMs.
Many thanks, Howard
GMS Link: https://www.dropbox.com/s/gslhilbpngjtttd/Toolpath.gms?dl=0
Option Explicit Private InsideRad As Double, OutsideRad As Double Private sr As ShapeRange, sr2 As New ShapeRange Private PreviewB As Boolean Private Sub UserForm_Initialize() Set sr = ActiveSelectionRange SizeInTB.Value = 0 SizeOutTB.Value = 0 EventsEnabled = False ActiveDocument.BeginCommandGroup "Tool path Rads" End Sub Private Sub OutsideSB_SpinUp() SizeOutTB.Value = SizeOutTB + 0.1 End Sub Private Sub OutsideSB_SpinDown() SizeOutTB.Value = SizeOutTB - 0.1 End Sub Private Sub InsideSB_SpinUp() SizeInTB.Value = SizeInTB + 0.1 End Sub Private Sub InsideSB_SpinDown() SizeInTB.Value = SizeInTB - 0.1 End Sub Private Sub ZeroIn_Click() SizeInTB.Value = 0 End Sub Private Sub ZeroOut_Click() SizeOutTB.Value = 0 End Sub Private Sub SizeInTB_Change() If Not IsNumeric(SizeInTB.Value) Or SizeInTB.Value < 0 Then Beep SizeInTB.Value = 0 Else If Not sr2 Is Nothing Or Not sr2.Shapes.Count = 0 Then sr2.Delete: Set sr2 = Nothing InsideRad = SizeInTB.Value PreviewB = True RadCornersPreview End If End Sub Private Sub SizeOutTB_Change() If Not IsNumeric(SizeOutTB.Value) Or SizeOutTB.Value < 0 Then Beep SizeOutTB.Value = 0 Else If Not sr2 Is Nothing Or Not sr2.Shapes.Count = 0 Then sr2.Delete: Set sr2 = Nothing OutsideRad = SizeOutTB.Value PreviewB = True RadCornersPreview End If End Sub Private Sub AcceptCP_Click() If Not sr2 Is Nothing Or Not sr2.Shapes.Count = 0 Then sr2.Delete PreviewB = False RadCornersPreview sr.CreateSelection Set sr = Nothing Set sr2 = Nothing ActiveDocument.EndCommandGroup Unload Me End Sub Private Sub CanCB_Click() If Not sr2 Is Nothing Or Not sr2.Shapes.Count = 0 Then sr2.Delete sr.CreateSelection Set sr = Nothing Set sr2 = Nothing ActiveDocument.EndCommandGroup Unload Me End Sub Sub RadCornersPreview() 'Set Nodes that control points lie in 180 degrees of each to smooth if cusped On Error GoTo ENDED Optimization = True ActiveDocument.SaveSettings ActiveDocument.PreserveSelection = False Dim N As Node, InsideNR As New NodeRange, OutsideNR As New NodeRange, AllNR As NodeRange Dim s As Shape, Seg1 As Segment, Seg2 As Segment Dim Spath As SubPath Dim i As Long, SC As Long, J As Long Dim ADif As Double If PreviewB = True Then sr2 Else Set sr2 = sr End If For Each s In sr2.Shapes If PreviewB = True Then s.OrderToFront s.Fill.ApplyNoFill s.Outline.Color.CMYKAssign 0, 60, 20, 20 s.Outline.SetProperties 1 s.Fill.UniformColor.CMYKAssign 5, 5, 5, 5 End If If s.Type <> cdrCurveShape Then s.ConvertToCurves For Each Spath In s.Curve.SubPaths SC = Spath.Segments.Count i = 1 Do While i < SC + 1 If i < SC Then Set Seg1 = Spath.Segments(i) Set Seg2 = Spath.Segments(i + 1) Set N = Spath.Nodes(i + 1) ElseIf i = SC Then Set Seg1 = Spath.Segments.Last Set Seg2 = Spath.Segments.First Set N = Spath.Nodes.First End If ADif = Seg1.EndingControlPointAngle - Seg2.StartingControlPointAngle If ADif < 0 Then ADif = 360 + ADif If ADif <= 180 Then If InsideRad > 0 Then N.Fillet InsideRad, True Else If OutsideRad > 0 Then N.Fillet OutsideRad, True End If Set N = Nothing: Set Seg1 = Nothing: Set Seg2 = Nothing J = Abs(Spath.Segments.Count - SC) i = i + J + 1 SC = Spath.Nodes.Count Set N = Nothing Loop Next Spath Set Spath = Nothing Next s If PreviewB = True Then Set sr2 = ActiveDocument.LogCreateShapeRange(sr2) ENDED: Set s = Nothing EventsEnabled = False ActiveDocument.PreserveSelection = True ActiveDocument.RestoreSettings Optimization = False ActiveWindow.Refresh Application.Refresh End Sub
Hi Howard,
If you're looking for an immediate solution, consider ecut 6 - it's a commercial macro that has tons of features, including the function you seem to be looking for. We call it "smart fillet".
Jeff