I need your help in macros creation which will include two things:
1. PEN appears to be an active instrument in case of actuation
2. This instrument follows up my actions and in case I enter an 3 nodes some action activates. (and I need to get coordinates of nodes)
Sorry for my english
i'm not sure I understand what you wont...
1. Agreed (supposing that you are referring to 'Pen tool')...
2. Which instrument to follow your actions? A macro able to follow your mouse cursor keeping the 'Pen tool' and do something immediately after you created the third node, returning those three nodes coordinates?
You do not say anything...
If my supposition above is correct you can use the next event code:
[code]
Private nd As Long 'number of created nodes
Private Sub Document_ShapeDistort(ByVal Shape As Shape) Dim x1 As Double, x2 As Double, x3 As Double Dim y1 As Double, y2 As Double, y3 As Double On Error Resume Next 'in order to avoid error in case of shapes not being curves nd = Shape.Curve.Nodes.Count If Err.Number = 0 Then If nd Mod 3 = 0 Then x1 = Format(Shape.Curve.Nodes(nd - 2).PositionX, "00.00") x2 = Format(Shape.Curve.Nodes(nd - 1).PositionX, "00.00") x3 = Format(Shape.Curve.Nodes(nd).PositionX, "00.00") y1 = Format(Shape.Curve.Nodes(nd - 2).PositionY, "00.00") y2 = Format(Shape.Curve.Nodes(nd - 1).PositionY, "00.00") y3 = Format(Shape.Curve.Nodes(nd).PositionY, "00.00") Debug.Print nd, "event: " & x1 & ":" & y1 & " - " & x2 & ":" & y2 & " - " & x3 & ":" & y3 End If Else Err.Clear: On Error GoTo 0 End IfEnd Sub
[/code]
It will return:
3 event: 15.97:257.51 - 87.23:207.42 - 138.73:258.93 6 event: 168.37:150.27 - 137.32:119.23 - 23.02:182.73 9 event: 22.32:213.77 - -36.24:234.94 - -46.12:148.86 12 event: 37.84:129.1 - 79.47:61.37 - 39.96:48.67
P.S. Is there a way to post nice html code in that new appearance of the forum?
But my code does exactly what you are asking...
Instead of MsgBox it return the values in ImmediateWindow (Ctrl + G) being in VBE (Alt + F11). If the macro will issue a MsgBox during you use the Pen tool you will be interrupted.
If that is not a problem, please use the next code:
This is an event! You do not have to start any Macro. It will just run when you work with Pen tool...
And this code must be placed in ThisDocument: Alt + F11 to open IDE. On the left side identify the VBA Project of the document where you wont to try it, click the cross on the left side (for instance VBAProject (Untitled-1)), click on the cross of CorelDraw Xx Objects and after that double click on ThisDocument. Paste here the next code and just work with Pen tool on that document. At each three nodes created a MsgBox containing the coordinates will pop up...
isn't that what you wont?
What variant of Corel do you use? Up to X6 you can save the document with that code (tested). On X8 the document saved events do not work. It is also a possibility to bypass that writing the code on the fly but firstly confirm that this is what you need...
Firstly, please, use it on a new document! Untitled...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Option Explicit Private nd As Long 'number of created nodes Private Sub Document_ShapeDistort(ByVal Shape As Shape) Dim x1 As Double, x2 As Double, x3 As Double Dim y1 As Double, y2 As Double, y3 As Double On Error Resume Next 'in order to avoid error in case of shapes not being curves nd = Shape.Curve.Nodes.Count If Err.Number = 0 Then If nd Mod 3 = 0 Then x1 = Format(Shape.Curve.Nodes(nd - 2).PositionX, "0.00") x2 = Format(Shape.Curve.Nodes(nd - 1).PositionX, "0.00") x3 = Format(Shape.Curve.Nodes(nd).PositionX, "0.00") y1 = Format(Shape.Curve.Nodes(nd - 2).PositionY, "0.00") y2 = Format(Shape.Curve.Nodes(nd - 1).PositionY, "0.00") y3 = Format(Shape.Curve.Nodes(nd).PositionY, "0.00") MsgBox x1 & ":" & y1 & vbCrLf & x2 & ":" & y2 & vbCrLf & x3 & ":" & y3 End If Else Err.Clear: On Error GoTo 0 End If End Sub
it's fantastic. the first time didn't work, and I do not understand what you need to do with it. But it's not quite the same.
I need something like: ActiveTool = cdrToolDrawBezier '(Bezier tool, I can't find the Pen Tool) and after drawing three points ie I need the action involving the coordinates of these points.
I confess I'm very confused...
1. I do not need such a code. I did it for you in order you to understand how to trigger the third node creation during its drawing... To be 'the same' with what? With your hidden thoughts...? Please specify what you need.
2. The code acts independent of the tool! It works similar for Besier, too. It works for all curves and Besier tool also creates curves... And Pen tool can be found in the same place like Besier tool. You just should pres the little arrow bottom right and choose it...
2 bis. What version of CorelDRAW do you use? I asked you before about that... At least in X6, X7 and X8 it is the same. I created the code in X8.
3. Do you need the code to draw that nodes or you manually will draw them and the code must do something at the third one?
When you need something please explain exactly what you need! Nobody likes Sisyphus work... As a general piece of advice: I took it like a challenge but if you need something else and you do not know how to explain what you need my spare of patience is not infinite... And it is not a matter of English, I'm afraid.
Algorithm my macros:
1. Run macros
2. Macros set active tool as "Pen tool" (or bezier)
3. Macros wait event. Event is 3 nodes, which I drew
4. When I drew 3 nodes, a trigger is invoked, for example "mesageBox"
5. Script stopped
Version 18 (x8)
1 - 2. When a macro runs you cannot work with any tool, except some special circumstances... Only events are triggered by some modifications done by the user. What I posted was an Event. Which is triggered when you modify a shape. In our case when you add nodes. Only to activate the Pen tool or Besier tool with a macro is not useful I think, because it is much easier to press the arrow followed by clicking on the tool icon than looking for the macro and running it.
3. Macro cannot wait for an event. Only defined Events can wait for an action. So, you draw the curve, not the macro. Finally I could understand that...
4. The event is able to trigger the three nodes creation and does something. As you could see...
5. No. The event doesn't stop. Only if you want it to act for some specific times. In this case you have to create a private variable which is incremented at each event action (let's say the MsgBox) and not acting after that specific number is achieved. But this does not mean the event stops. It only stops sending messages...
The important idea would be what do you intend to do with that coordinates? I kept asking about your (global) need but you delivered only small slices. Maybe somebody here points you in the right or in a better direction... Without explaining the hole context it is difficult to follow you and understand your need. Do you just play with that in order to learn or you really have a need/project involving that behavior?