cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Macro using right mouseclick to exit - what am I doing wrong?

TimSharp
6-Contributor

Macro using right mouseclick to exit - what am I doing wrong?

We often do wiring diagrams.

We add cuttout loops where wires cross, so my macro places a pre-drawn cuttout loop at the point picked by left mouse click.

It then repeats until right mouse click, when it's supposed to exit.

The problem is that it doesn't seem to exit the while loop properly. If you left click on the drawing, it adds the cutout loop drawing OK, and repeats, but when you right click it still keeps repeating - unless you hold the right button for a second or more, but then it selects all the loops you've added to the drawing so far and changes the line type of one of them (as though you've double clicked on it).

A simplified version of the macro is below.

Strange thing is that if I uncomment the message lines below, the macro seems to work OK, (though with the annoying popup messages of course), except that the first one returns 0 (no mouse click) instead of the expected 1 (left mouse click).

I'm obviously doing something wrong but I can't figure it - any of you clever guys help?

I've attached the cutout loop file, you will just need to change the place line in the macro to where you put the file.

macro test-add-wiring-diagram-cutout-loop

define me as MouseEvent

define ppx1 as Point # x value of user selected point

define ppy1 as Point # y value of user selected point

While (me.Click <> 2)

me = Wait MouseClick

if(me.Click <> 2)

#message me.click

#NOTE THAT ABOVE RETURNS 0, NOT THE EXPECTED 1

ppx1 = me.ptMMGrid.x

ppy1 = me.ptMMGrid.y

place "X:\Illustrators Info\Macros\wiring-diagram-cutout-loop.iso" (ppx1-1) (ppy1-1)(ppx1+1) (ppy1+1)

Select if type is equal to 'Placed_file'

Import selection #BREAKS THE LINK WITH THE PLACED FILE

Select None

else

Select None

end if

End While

#message me.click

end macro

2 REPLIES 2

Looking it over you look like there is nothing blaringly wrong causing your issue. I remember running into this when we started with 7.0. With later versions of IsoDraw, and more important, faster computers the issue basically disappeared. Not the answer you were looking for, but it's what I've found thus far.

As a side, I did go in and tweak your original code to remove the unneeded separation in the if statement and then I also moved your import selection portion to the end of the macro. It's minor, but then this task does not have to be done repeatedly. Only flaw there is that it assumes your users actually left-clicks to insert an image. If they start the macro and hit the right mouse button they'll get an error. You could account for that, but this should suffice.

macro test-add-wiring-diagram-cutout-loop

define me as MouseEvent

define ppx1 as Point # x value of user selected point

define ppy1 as Point # y value of user selected point

While (me.Click <> 2)

me = Wait MouseClick

if(me.Click = 1)

ppx1 = me.ptMMGrid.x

ppy1 = me.ptMMGrid.y

place "X:\Illustrators Info\Macros\wiring-diagram-cutout-loop.iso" (ppx1-1) (ppy1-1)(ppx1+1) (ppy1+1)

end if

End While

Select if type is equal to 'Placed_file'

Import selection #BREAKS THE LINK WITH THE PLACED FILE

Select None

end macro

TimSharp
6-Contributor
(To:thendricks)

Thanks Trevor

We have pretty fast computers here, though we do run them on XP for stability, so maybe it's a speed issue and the macro is trying to move on to something new before completing the last thing.

The problem with having the import selection outside the loop is that it only seems to work on one item, so for example if 3 items are added, the imnport selection will only import one of the three, so I had it within the loop to work on each item as it is placed, which seems to work. I think it's something to do with the annoying way Isodraw works (or should I say doesn't work) with grouped elements.

What I found strange though was that when I added the message function in to see what it reported (message me.click), it gave 0 (for no click) when it should have givend 1 (for left click). I wondered if this mighthave a bearing on why it doesn't always exit the loop properly on right click.

Top Tags