pixel2 Posted April 21, 2009 Share Posted April 21, 2009 Hello guys, I have 300 squares. with 1 meter side. I want to select them and apply a script that randomize its dimensions from center. between .6 and 1. Can someone give me a glimpse to make this? Thanks in advance. Bruno Quote Link to comment
Pat Stanford Posted April 21, 2009 Share Posted April 21, 2009 Try this: Procedure RandomScaleSelected; Var H1: Handle; R1: Real; X1,Y1 :Real; Begin H1:=FSActLayer; While H1<>Nil do Begin R1:=Random*4/10+0.6; HCenter(H1,X1,Y1); HScale2D(H1,X1,Y1,R1,R1,false); {change last param to true to scale text} H1:=NextSObj(H1); End; RedrawAll; End; Run(RandomScaleSelected); Quote Link to comment
RubenH Posted June 6, 2009 Share Posted June 6, 2009 (edited) Excellent! Edited June 6, 2009 by Mr. Gog Quote Link to comment
RubenH Posted July 5, 2010 Share Posted July 5, 2010 (edited) Hello all Vectorscripters! Is there a way to make the posted by pat script work with 3d rotated objects (extrudes)? Thanks in advance! Edited July 5, 2010 by Mr. Gog Quote Link to comment
Pat Stanford Posted July 5, 2010 Share Posted July 5, 2010 Try this. Note that is scales the object around the 3D center. If you need the bottoms to stay in place I will have to give it some more thought. Procedure RandomScaleSelected; Var H1: Handle; R1: Real; X1,Y1,Z1 :Real; Begin H1:=FSActLayer; While H1<>Nil do Begin R1:=Random*4/10+0.6; Get3DCntr(H1,X1,Y1,Z1); HScale3D(H1,X1,Y1,Z1,R1,R1,R1); H1:=NextSObj(H1); End; RedrawAll; End; Run(RandomScaleSelected); Quote Link to comment
RubenH Posted July 6, 2010 Share Posted July 6, 2010 (edited) I tried the same thing. It works well when the extrudes are perpendicular to the ground plane, but It doesn't work with rotated extrudes that aren't perpendicular to the ground plane (check the attach). Edited July 6, 2010 by Mr. Gog Quote Link to comment
Pat Stanford Posted July 6, 2010 Share Posted July 6, 2010 Send me a file with a sample of the extrudes that don't scale. Either post it here or email it directly to me and I will take a look and see what I can do. What do you want varied? Height or area and height? Do you want the bases to stay in place (scale around the 3D Center) or something else? Quote Link to comment
RubenH Posted July 6, 2010 Share Posted July 6, 2010 (edited) These are the needed things: 1. Scale Area 2. Around the center 3. Scale other shapes. no only extrudes. The example was obtained with duplicate along path. The cylinders (extrudes) need to be scaled. The example contains cylinders forms, but could be another shape. Thanks!! Edited July 6, 2010 by Mr. Gog Quote Link to comment
Pat Stanford Posted July 6, 2010 Share Posted July 6, 2010 There is a bug in the HScale3D procedure so it does not work on many types of objects. I have submitted a bug report on it. Right now I don't have any work around for the bug. If I come up with anything I will let you know. Quote Link to comment
RubenH Posted July 6, 2010 Share Posted July 6, 2010 Thanks anyway... When I made the modification to the script and it didn't work I though it was my fault. Let's wait... Thanks's for your help. Quote Link to comment
MullinRJ Posted July 7, 2010 Share Posted July 7, 2010 If you replace HScale3D() with the following procedure, you will be able to scale 3D objects in place, even if they are rotated. Raymond procedure ScaleIt3D(H :Handle; X, Y, Z, SF :Real); { Scale a 3D object by scale factor SF around point (X, Y, Z) } Var mirror :Boolean; Xrot, Yrot, Zrot :Real; Begin if Get3DOrientation(H, Xrot, Yrot, Zrot, mirror) then begin { unrotate it } Set3DRot(H, 0, 0, -Zrot, X, Y, Z); Set3DRot(H, 0, -Yrot, 0, X, Y, Z); Set3DRot(H, -Xrot, 0, 0, X, Y, Z); { scale it } HScale3D(H, X, Y, Z, SF, SF, SF); { re-rotate it } Set3DRot(H,?Xrot, Yrot, Zrot, X, Y, Z); end; { if } End; { ScaleIt3D } Quote Link to comment
RubenH Posted July 8, 2010 Share Posted July 8, 2010 (edited) Thanks Raymond. Thanks Pat. This is the working script: {FROM HERE} Procedure RandomScaleSelected; Var H1: Handle; R1: Real; X1,Y1,Z1 :Real; xr, yr, zr :Real; mrr :Boolean; Begin H1:=FSActLayer; While H1<>Nil do Begin R1:=Random*4/10+0.6; if Get3DOrientation(H1, xr, yr, zr, mrr)then begin Get3DCntr(H1,X1,Y1,Z1); Set3DRot(H1, 0, 0, -zr, X1, Y1, Z1); Set3DRot(H1, 0, -yr, 0, X1, Y1, Z1); Set3DRot(H1, -xr, 0, 0, X1, Y1, Z1); HScale3D(H1,X1,Y1,Z1,R1,R1,R1); Set3DRot(H1,?xr, yr, zr, X1, Y1, Z1); H1:=NextSObj(H1); End; End; RedrawAll; End; Run(RandomScaleSelected); {TO HERE} Edited July 8, 2010 by Mr. Gog Quote Link to comment
MullinRJ Posted July 9, 2010 Share Posted July 9, 2010 Mr. Gog, You are going to run into trouble if Get3DOrientation() ever fails. In such a case, your code will never move to the next object and will wind up in an endless loop. You need to put H1:=NextSObj(H1); outside the IF statement and place it as the last statement in the WHILE loop. Raymond PS - Why did you create inline code and not use a user defined function? For small programs such as this, it's not a real issue, but as soon as you get up to 50 lines or more, user defined procedures and function will make the main body of your code read much more easily. In the following example, the main routine becomes 3 lines inside the WHILE loop: generate a random number, scale the object by that number, get the next selected object. In a year or two, which version of the script do you think will be easier to read? Procedure RandomScaleSelected; { Scale selected 3D objects by a random factor between 0.6 and 1.0 } Var ???H1: Handle; ???R1: Real; ???procedure ScaleIt3D(H :Handle; SF :Real); ???{ Scale a 3D object around its center by scale factor SF. } ???Var ??????mirror :Boolean; ??????X, Y, Z, Xrot, Yrot, Zrot :Real; ???Begin ??????if Get3DOrientation(H, Xrot, Yrot, Zrot, mirror) then begin ?????????Get3DCntr(H1, X, Y, Z);?????????????????????{ Get 3D center } ?????????Set3DRot(H, 0, 0, -Zrot, X, Y, Z);????????{ unrotate it } ?????????Set3DRot(H, 0, -Yrot, 0, X, Y, Z); ?????????Set3DRot(H, -Xrot, 0, 0, X, Y, Z); ?????????HScale3D(H, X, Y, Z, SF, SF, SF);???????{ scale it } ?????????Set3DRot(H,?Xrot, Yrot, Zrot, X, Y, Z);???{ re-rotate it } ??????end;??????{ if } ???End;??????{ ScaleIt3D } Begin ???H1 := FSActLayer; ???While (H1<>Nil) do Begin ??????R1 := Random * 0.4 + 0.6; ??????ScaleIt3D(H1, R1); ??????H1 := NextSObj(H1); ???End; ???RedrawAll; End; Run(RandomScaleSelected); Quote Link to comment
RubenH Posted July 12, 2010 Share Posted July 12, 2010 Thanks for the lesson Raymond! I'll let you know the advancements with this. Thanks again. Quote Link to comment
Recommended Posts
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.