OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-05-2009, 19:36
vindaa
Guest
 
Posts: n/a
Default Finding Angle

I have several lines in my drawing, how can i just click on the line and find its angle with refrence to universal X axis. The precision should be up to 3 digits (eg. 23.215º) is it possible. Using the dimension tool is a bit problem since several of my lines are close to each and so the linee snaps to wrong node.
Reply With Quote
  #2  
Old 08-05-2009, 21:23
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Angle

Select a single node and run this code, it will give you the angle. You might have to play with it a bit to get it to display the angle you want, for instance now it might give you -90 and such. But you should be able to get started with this.
Code:
Sub WhatIsMyAngle()
    Dim n As Node
    Dim sShape As Shape
    Dim segBefore As Segment
    Dim segAfter As Segment
    Dim da As Double
    
    Set sShape = ActiveShape
    
    If sShape Is Nothing Then
        MsgBox "Nothing selected", vbCritical
        Exit Sub
    End If
    
    If sShape.Type <> cdrCurveShape Then
        MsgBox "A curve object must be selected", vbCritical
        Exit Sub
    End If
    
    If sShape.Curve.Selection.Count <> 1 Then
        MsgBox "Only one node must be selected", vbCritical
        Exit Sub
    End If
    
    Set n = sShape.Curve.Selection(1)
    Set segBefore = n.PrevSegment
    Set segAfter = n.NextSegment

    If Not segBefore Is Nothing And Not segAfter Is Nothing Then
        da = segBefore.EndingControlPointAngle - segAfter.StartingControlPointAngle
        MsgBox Round(da, 3) & " degrees"
    End If
End Sub
Best of luck,

-Shelby
Reply With Quote
  #3  
Old 09-05-2009, 22:28
vindaa
Guest
 
Posts: n/a
Default Almost there

Thanks a lot
Actualy this is not what I was looking for but this too will be very very useful. And it does get me near to what I want.

All the lines in my drawing have only 2 nodes. So what I did is added an extra node and it works.
I changed
da = segBefore.EndingControlPointAngle - segAfter.StartingControlPointAngle
to
da = segBefore.EndingControlPointAngle - 0
so now it gives me angle with relation to x axis of the page. The only problem is when the angle is above 90 it displays it as negetive (like 92 is -88) so I need to add 180 to 'da' if the value of 'da' is negetive but I dont know how to do it.
I am ataching that file for ref
Thanks a lot
Attached Files
File Type: cdr thro.cdr (15.0 KB, 223 views)
Reply With Quote
  #4  
Old 10-05-2009, 12:07
aakkaarr aakkaarr is offline
Senior Member
 
Join Date: Jan 2009
Posts: 154
Default getting angle of line segment

you can use atn() function
atn(y/x)*180/3.142
where 'y' is height, 'x' is width of line as shown in the property bar
180/3.14 converts radian to degree
Reply With Quote
  #5  
Old 10-05-2009, 12:18
aakkaarr aakkaarr is offline
Senior Member
 
Join Date: Jan 2009
Posts: 154
Default getting angle

Private Function atan2(y As Double, x As Double) As Double
Dim y1 As Double
Dim a As Double
If x = 0 Then
a = 1.5707963267949 * Sgn(y)
Else
a = Atn(y / x)
y1 = IIf(y <> 0, y, 1)
If x < 0 Then a = a + 3.14159265358979 * Sgn(y1)
End If
atan2 = a
End Function

put these codes in form
then you can get y & x via command button or from globalselection change event
y is height, x is width of the line as shown in the property bar when you select the line
Reply With Quote
  #6  
Old 12-05-2009, 21:31
vindaa
Guest
 
Posts: n/a
Default crating form

Thanks Aakkaarr

mathematicall I like your idea, thanks a lot, but sice I am not a VB guy I dont know how to put the codes in a form, I will be glad if you can help me there

Also is there a link where I can learn it.
Reply With Quote
  #7  
Old 15-05-2009, 21:03
vindaa
Guest
 
Posts: n/a
Default It Works

He Shelbym it works nice it has stoped showning negetive angle. Thanks a lot
I just made small change
Sub WhatIsMyAngle()
Dim n As Node
Dim sShape As Shape
Dim segBefore As Segment
Dim segAfter As Segment
Dim da As Double

Set sShape = ActiveShape

If sShape Is Nothing Then
MsgBox "Nothing selected", vbCritical
Exit Sub
End If

Once again Thanks a lot

If sShape.Type <> cdrCurveShape Then
MsgBox "A curve object must be selected", vbCritical
Exit Sub
End If

If sShape.Curve.Selection.Count <> 1 Then
MsgBox "Only one node must be selected", vbCritical
Exit Sub
End If

Set n = sShape.Curve.Selection(1)
Set segBefore = n.PrevSegment
Set segAfter = n.NextSegment

If Not segBefore Is Nothing And Not segAfter Is Nothing Then
da = segBefore.EndingControlPointAngle - 0
da = 180 + segBefore.EndingControlPointAngle - 0

MsgBox Round(da, 3) & " degrees"
End If
End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Angle of adjacent segments m31uk3 CorelDRAW/Corel DESIGNER VBA 6 12-09-2012 08:45
Finding a text into a layer mateushenrico CorelDRAW/Corel DESIGNER VBA 3 10-09-2008 10:28
Rotation Angle norbert_ds CorelDRAW/Corel DESIGNER VBA 1 20-04-2007 02:39
Creating lines using angle, dimension and position Bobbejaan Code Critique 3 05-04-2007 07:22
[DrawX3 bug] interface display of fractional angle/size wOxxOm General 0 18-02-2006 14:00


All times are GMT -5. The time now is 13:15.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com