Jump to content

Trying to filp the source polyline in an extrude but my scipt does not work.


Recommended Posts

Trying to filp the source polyline in an extrude but my scipt does not work.

Any ideas!

 

def FlipIt(h):
	if vs.GetTypeN(h) == 21:
		if vs.Random() >= .5:
			vs.SetSelect(h) 
			vs.FlipVer() # doesn't flip the poly,  but if I replace this command with vs.HDuplicate(h) it will duplicate it

			
def ResetIt(h):
	vs.ResetObject(h)
	
vs.ForEachObjectInLayer(FlipIt,2,2,0)
vs.ForEachObjectInLayer(ResetIt,2,0,0)

 

Edited by The Hamma
Link to comment

Sorry, I am too lazy to try and convert to Python tonight.  

 

But it appears to be a redraw/refresh issue with the extrude.

 

Take a look at the extrude in the attached file. See that the polygon profile matches with the extrude.

 

Run the script.  Check the profile of the extrude.  Note that the profile has been flipped.  Exit the extrude and watch the extrude flip and move to the flipped location.

 

All the redraw, reset, move(0,0) garbage at the bottom are my attempts to force a redraw/refresh of the extrude.  All failing.

 

If you can find the proper incantation to force the redraw of the extrude you should have what you need. I am out of ideas.

 

Good Luck.

 

 

Flip Extrude Profile.vwx

Link to comment

Thanks, I just came to same conculsion after I got this script to work minus the refreshing issue. 

 

 

def FlipIt(h):
	h1= vs.FIn3D(h)
	if vs.GetTypeN(h1)==24:
		h2 =vs.FIn3D(h1)
		if vs.GetTypeN(h2) == 21:
			if vs.Random() >= .5:
				vs.Mirror(h2,False, (0,0), (5,0))
	vs.ResetObject(h1)
	vs.ResetObject(h)
			
vs.ForEachObjectInLayer(FlipIt,2,2,0)

 

Edited by The Hamma
Link to comment

Hello David,

   Okay, this works, but it is like throwing a hand grenade over the wall. Using Pat's script as a starting point I tried the not so obvious as it's something that's worked for me in the past. CUT & PASTE.

 

   Since you're working in 3D, I assume the final stacking order is not critical. The result in the script below will end up on the top of the stack. If it is critical, you can save the extrude's original position using NextObj() or PrevObj(), and use hMoveBackward() on your flipped extrude to reposition it to its original neighbors. More lines of code, but doable. After you get your script running, you should still file a bug. 

 

PROCEDURE Test;
VAR	H1,H2 :Handle;
	P1,P2 :Point;
BEGIN
	P1.x := 1;	P1.y := 0;
	P2.x := 2;	P2.y := 0;
	
	H1 := FinGroup( FSActLayer );		{ the Poly profile }
	H2 := Mirror( H1, False, P1, P2 );
	
	DoMenuTextByName( 'Cut', 0 );
	DoMenuTextByName( 'Paste In Place', 0 );
	H2 := LActLayer;			{ for future reference }
	
	SysBeep;	{ make noise when done }
END;
Run(Test);

 

 

HTH,

Raymond

Link to comment

David (@The Hamma),

   I was not able to get your script to work, and even tried it on a lone extrude without the first "vs.FIn3D()" and the "if vs.Random()" lines. If it's working for you then ignore the following. 

 

   Cut & Paste works on the entire selection and probably won't work the way you've structured your script. By making some assumptions, I was able to get this version to work, but it assumes you are only working on one group at a time. A selection of multiple groups will get merged into one (not ideal). Again, if you got your script to work, please ignore the following.

def FlipIt(h):
	if vs.GetTypeN(h) == 24:
		h2 = vs.FIn3D(h)
		if vs.GetTypeN(h2) == 5:
			if vs.Random() > 0.5:
				vs.Mirror(h2, False, (0,0), (5,0))
		
vs.Ungroup()
vs.ForEachObjectInLayer(FlipIt, 2, 2, 0)
vs.DoMenuTextByName('Cut', 0)
vs.DoMenuTextByName('Paste In Place', 0)
vs.Group()

vs.SysBeep()

 

Raymond

  • Like 1
Link to comment

This is interesting.  The points defining the reflection are relative.  If you rotate the extrude and run the script it flips left and right.  It remembers the location where the polygon was originally drawn and the reflection line is always relative to that no matter where you drag the extrude.  Everybody probably already knew that 🙂 

 

If you edit the extrude that contains a polygon, circle, rectangle and run the script while in the edit mode…. it works.

 

Edit:  In the edit mode the vector script works.  The python script doesn't.

If you run the vector script on an extrude that "doesn't work" then edit, the polygon, circle, rectangle etc will appear in a flipped position.

 

And after a successful reflection the selection is wrong.

image.thumb.png.1622fb9881d26b4f8a1b82be65c8d079.png

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...