Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
AEChadwick

Is there a simple method to "mirror" (dupe & flip) a 2D object?

Recommended Posts

I'm trying to economize code, and figured I had a clever solution...

But it does not work, my procedures are lacking?I have not been able to ascertain how to simply "duplicate and mirror" a 2D object.

To explain, instead of making two, separate draw door by type routines, I figured "if the door is a double, just draw half and mirror it..."

the first part checks if it's a double-version and sets a couple variables:

FlipIt := FALSE;

If PDOORS = 'Double Door' then

begin

FlipIt := TRUE;

DoorWidth := (wRight/2);

End;

the procedure then draws the appropriate door, then duplicates itself...

PROCEDURE DrawSimpleHinged;

BEGIN

BeginGroup;

Rect(wLeft,wBottom-DoorWidth,wLeft+DoorThickness,wBottom);

Rect(WLeft,wBottom,wLeft+DoorWidth, wBottom+DoorThickness);

Oval(wLeft-.5",wBottom-.5",wLeft+.5",wBottom+.5");

ArcByCenter(wLeft,wBottom,DoorWidth,0,-90);

EndGroup;

If FLIPIT then

begin

FirstHalf := HDuplicate(LNewObj,DoorWidth,0);

SetSelect(FirstHalf); FlipHor;

End;

END; {DrawSimpleHinged}

...but, of course, this just flips the entire PIO, not the door-half.

Am I doing the handles wrong, or missing an obvious command?

I sure appreciate the help!

PS. other code critique welcome, I?m know I'm a n00b, feel free to school me!

?

Edited by AEChadwick

Share this post


Link to post

Objects inside of PIOs are not actually drawn (and therefore don't have a handle or exist to the LNewObject command) until the PIO refresh routine is done.

No way that I know of to get around this.

I think all (or at least most) of us have fought with this at some point as it would be so useful to be able to access the components inside the PIO.

Share this post


Link to post

Sorry about that.

Brutal Honesty is my middle name (names?)

Actually I just don't want to see anyone else waste the time I spent trying to fight this.

Actually, I really hope I am wrong. ;-)

Share this post


Link to post

Well, that's not entirely true. Objects within PIOs are added to the drawing structure as the code runs, so you can get a handle to them using LNewObj. There are a few objects that don't respon to LNewObj no matter where you create them. Search the forum for the Waldo method for a workaround. You're getting a handle directly from HDuplicate, so that's not an issue.

The gist of what Pat said is correct. Objects don't DRAW on screen until the code finishes, so you can't use any commands dependent on selection. In general you should avoid using and VS commands that use the selection instead of a handle. You should only use SetSelect as part of your UI -- if you want the user to see certain objects selected when your code finishes. There is a version of flip that uses a handle (can't recall it off the top of my head). Use that instead of FlipHor, and all should be fine.

If you really want to write efficient code, make the door creation section in to a sub-procedure that takes an integer as a variable (I call mine flipMult). Multiply evry X coordinate by flipMult. Set to 1 for the right half and -1 for the left half.

-Josh

Share this post


Link to post

Sorry but I tend to disagree with both. Objects do get a handle and are drawn as they are created. You do not see any change when the object has been created because the screen does not refresh until the code completes.

I have created tools with a loop structure and a redraw function within that would get called as I moved the cursor & reported the x,y position as text on the drawing. Also while debugging, I have terminated the code before it completes and any objects that have been created to that point will be drawn.

I also recall that in the beginning of VS most function calls operated on selected objects only as it has been with menu commands. Back then we relied on menu commands a lot since there was no equivalent functions. Over time, VS functions were added to operate on object handles as well.

Having said that and looking at the code, the problem I see is that when an object is created, it is automatically selected. When flipHor is called all the objects are selected and consequently, all the objects get flipped. Try it with "DSelectAll" before the creation of the second group object as in:

Begin

DSelectAll;

FirstHalf := HDuplicate(LNewObj,DoorWidth,0);

SetSelect(FirstHalf);

FlipHor;

End;

The other way of mirroring as Josh pointed out is to create the same object with the x,y coordinates in the opposite direction.

Share this post


Link to post

Joshua and Miguel are correct.

I should not be posting without chcekcin and especially on too little sleep.

Share this post


Link to post

Miguel, you're fantastic!

I had just finished cobbling two routines as "flipmult" variations (had to get out the Pythagorean Theorem for part...), but I instantly abandoned them and plugged in that DSelectAll. It worked perfectly.

I had previously avoided DSelect, thunking it would drop the entire PIO... I should have experimented. Looks like everyone is learning valuable lessons today!

Thanks to everyone! I absolutely love posting here, everyone is always smart and helpful [unlike most of the rest of the internet].

?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×