Hi all,
It's been a while since I've posted as I started a new job using AutoCAD but by showing the power of CorelDraws API to my new employer I am back again!... with more questions!
I've Hit a block with probably a quite simple (but fun) problem but for the life of me an elegant and robust solution eludes me!
In short I want to analyse the a curve, recording the perpendicular angle at a series of points along it.
Then give each recorded point a value between 0-180 based on how much it deviates from my target angle.
Currently It only works correctly when the angle is 0, please see below for the stripped down block of code and an image of its current output to get things moving.
All suggestions and ideas welcome.
Thanks in advance
Sub PerpLines() ActiveDocument.Unit = cdrMillimeter Dim S As Shape Set S = ActiveShape Dim Sp As SubPath Set Sp = S.Curve.SubPaths.First Dim P As Shape Dim L As Long: L = 1 Dim step As Long: step = 10 Dim curLength As Double: curLength = 0 Dim sLength As Double: sLength = Sp.Length Dim X As Double, Y As Double, A As Double Dim R As Double Dim targA As Double: targA = 90 Dim aDif As Double Do While curLength < sLength - step curLength = curLength + step Sp.GetPointPositionAt X, Y, curLength, cdrAbsoluteSegmentOffset A = Sp.GetPerpendicularAt(curLength, cdrAbsoluteSegmentOffset) Set P = ActiveLayer.CreateLineSegment(X, Y, X + step, Y) P.Outline.EndArrow = ArrowHeads(1) P.Outline.Width = 1 P.SetRotationCenter X, Y P.Rotate A
If A < 0 Then aDif = A + 360 Else aDif = A End If R = (255) * (Abs(A) / 180) P.Outline.Color.RGBAssign CLng(R), 50, 50 P.Name = CStr(aDif) L = L + 1 Set P = Nothing Loop End Sub
Since I'm not seeing all of the code, I don't know if you are already doing what I am about to suggest, but...
If I change something such as ActiveDocument.Unit for convenience in a macro, then I also use ActiveDocument.SaveSettings at the start of the macro, and ActiveDocument.RestoreSettings at the end.If I don't, then I'm changing the units for the document - and that may affect other macros that the user may use later.Instead of changing ActiveDocument.Unit (and then changing it back later), I sometimes use ActiveDocument.ToUnits and/or ActiveDocument.FromUnits to do the conversions in the macro.
That'll do the trick! Thank you.
I had barred myself from using if statements for this one... like you say there may be some clever clogs way of doing it but it's beyond me! I've been pushing myself to not muddle through things but tbh you're solutions is more than elegant enough. So I'll use that.
And Thanks for the advice on the units I'll keep that in mind.