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 05-04-2007, 02:49
norbert_ds
Guest
 
Posts: n/a
Default Length of a selected line

Hi all,

I have a selected line. What I need to do is reduce the length of the line by 3mm, its reference point beng centre.

Can any of you'll direct me to a thread here or any suggestions?

Cheers
Norbert
Reply With Quote
  #2  
Old 05-04-2007, 14:20
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

something like this:
Code:
function ChangeLineLen(L as shape, byval delta as double) as boolean
   dim length as double, ratio as double
   length=sqr(L.sizewidth^2+L.sizeheight^2)
   if length+delta=0 then exit function ' returns false - error: line would be reduced to singularity
   ratio=length/(length+delta)
   L.SetSize L.sizeWidth*ratio, L.sizeHeight*ratio
   ChangeLineLen=true
end function
Reply With Quote
  #3  
Old 06-04-2007, 03:36
norbert_ds
Guest
 
Posts: n/a
Default

Hi,

Thanks for you r response. I should have actually mentioned that I am not at all familiar with VBA and I am at the moment attempting it. I have not reached the stage where I can create functions and then call these functions.

Can you explain the same using a subroutine? I would appreciate if you could keep it simple or if you could provide each line with a comment? I know this is asking for too much but I would sincerely appreciate it and would enable me to understand the code rather than simply copying it and pasting it.

Thanking you in advance
Norbert
Reply With Quote
  #4  
Old 06-04-2007, 07:35
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

Code:
Sub ChangeLineLen()
   Static prevDelta As Double
   Dim L As Shape, delta As Double
   Dim length As Double, ratio As Double, s As String

   If ActiveShape Is Nothing Then Exit Sub

   ActiveDocument.Unit = cdrCentimeter
   ActiveDocument.ReferencePoint = cdrCenter
   
   Set L = ActiveShape
   length = Sqr(L.SizeWidth ^ 2 + L.SizeHeight ^ 2)

   
   s = InputBox("Current length: " + FormatNumber(length, 3), "Change line length by: ", CStr(prevDelta))
   If Not IsNumeric(s) Then Exit Sub
   delta = CDbl(s)
   prevDelta = delta

   If length + delta > 0 Then
      ratio = (length + delta) / length
      L.SetSize L.SizeWidth * ratio, L.SizeHeight * ratio
   End If
End Sub
This sub is ready to be put as a macro on toolbar / keyboard shortcut

:-) actually there's no big need to comment on this, at least I see none. However a few tips - to learn better what's happening use F8 to trace the code line by line and lookup values of variables etc (hover mouse over in VBA Editor). Also a great source of info is rightclick symbol and choose 'Definition' or F1 key is the saviour!
Reply With Quote
  #5  
Old 06-04-2007, 20:40
norbert_ds
Guest
 
Posts: n/a
Default

Thank you very very very much!

I sincerely appreciate this!

Cheers!
Norbert
Reply With Quote
  #6  
Old 15-04-2007, 20:23
norbert_ds
Guest
 
Posts: n/a
Default Length of Line

Hi,

In your code, suppose I don't want the input message box?

I simply want the length of the original selection to be reduced by 3mm.

Appreciate your help.

Thanks in advance.

Norbert
Reply With Quote
  #7  
Old 15-04-2007, 21:03
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default


Code:
Sub ChangeLineLenConst()
   const Delta# = -3
   Dim L As Shape, length#, ratio#

   If ActiveShape Is Nothing Then Exit Sub

   ActiveDocument.Unit = cdrMillimeter
   ActiveDocument.ReferencePoint = cdrCenter
   
   Set L = ActiveShape
   length = Sqr(L.SizeWidth ^ 2 + L.SizeHeight ^ 2)
   
   If length + delta > 0 Then
      ratio = (length + delta) / length
      L.SetSize L.SizeWidth * ratio, L.SizeHeight * ratio
   End If
End Sub

Last edited by wOxxOm; 15-04-2007 at 21:24.
Reply With Quote
  #8  
Old 15-04-2007, 21:21
norbert_ds
Guest
 
Posts: n/a
Default Nothing happenning

Hi!

Unfortunately this piece of code does nothing!

The line is left untouched!

Thanks
Norbert
Reply With Quote
  #9  
Old 15-04-2007, 21:25
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

poor me, that ought be millimeter and I wrote millimIter :-)
Reply With Quote
  #10  
Old 15-04-2007, 23:03
norbert_ds
Guest
 
Posts: n/a
Default Thank You

Thank you very much!!

This works like a charm.

Would you be able to explain something to me please?

I tried using Curve.Length in a message Box and it displayed the length of the line perfectly for both horizontal lines and vertical lines.

However when I tried a setSize Curve.length-3, it workied perfectly for horizontal lines but the vertical lines actually increased rather than decrease and not even by 3.

Appreciate your help!
Norbert
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
How to draw a double line in coreldraw? 4gold General 11 01-11-2005 18:39
Contour Cut Line for Digital prints GraphiXtreme New product ideas 2 26-08-2005 15:28
Reading Font Properties from selected text in CD9 sherman01 CorelDRAW/Corel DESIGNER VBA 2 24-11-2004 07:59
Length of line pragatipc SecuriDesign 1 18-08-2004 20:23
Calculate total length of line or path pmills New product ideas 2 08-12-2003 04:52


All times are GMT -5. The time now is 08:29.


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