Jump to content
Developer Wiki and Function Reference Links ×

ForEachObjectInLayer


Recommended Posts

Hey all,

Working on a little automator at the moment. I have a group containing various arc and lines and then in the middle of it a circle, lines and text all within a symbol. What I want to do is copy the group around to a few places and rotate it.

After rotating the full group I want all the symbols contained within to remain at a rotation of 0?. I thought I'd use this opportunity to make/try a script, and I have this thus far:

{-----------------------------}

Procedure Loop;

Procedure RotTest(h : HANDLE);

VAR

rot :real;

BEGIN

rot:= GetSymRot(h);

If GetSymName(h)='Symbol-1' Then

BEGIN

SetRot3D(h,0,0,0,0,0,0);

ResetObject(h);

sysbeep;

End;

END;

BEGIN

ForEachObjectInLayer(RotTest,0,1,1);

END;

RUN (Loop);

{----------------------}

But it doesn't work. Can someone read over and let me know if I'm on the right track?

Any help appreciated.

Cheers,

J

Ps. Sysbeeps are cool okay.

Link to comment

James,

Change:

???Procedure RotTest(h : HANDLE);

To:

???Function RotTest(h : HANDLE) :Boolean;

All of the ForEachObj... VS calls take a FUNCTION as the callback "procedure" except ForEachObject(), which takes a PROCEDURE as the callback "procedure".

If you want to terminate the loop early, then the callback "function" needs to return a TRUE value. By default, it will return a value of FALSE, even if it's not explicitly stated, and continue to the end.

As to whether your callback will do what you want, I don't know.

Raymond

Link to comment

You should also filter only symbols before the call to GetSymRot. The compiler usually gives an error if the object handle is not appropriate for the function.

IF GetType(h) = 15 THEN

BEGIN

rot:= GetSymRot(h);

...

...

END;

For most 3D objects, you should use Set3DRot instead which accepts symbols. SetRot3D only works for extrudes and sweeps. And even if the function was the right one, the object would not rotate because the angles are all zeros. It should be something like:

Set3DRot(h,0,0,-rot,symX,symY,symZ);

Furthermore, if the symbol has only a 2D component always use HRotate such as:

GetSymLoc(h,symX,symY);

rot:= GetSymRot(h);

HRotate(h,symX,symY,-rot);

Link to comment

The following seems to do what you want:

Procedure Test;

Var H1, H2 :Handle;
Rot :Real;
X1,Y1,Z1 :Real;

Function DoIt(H3:Handle):Boolean;
Begin

If GetType(H3)=11 then
 Begin
H1:=FInGroup(H3);
While H1 <> Nil do
	Begin
		if GetType(H1)=15 then
			Begin
				Get3DCntr(H1,X1,Y1,Z1);
				Rot:=GetSymRot(H1);
				HRotate(H1,X1,Y1,-Rot);
			end;
		H1:=NextObj(H1);
	end;
end;
End;

Begin
ForEachObjectinLayer(DoIt,0,0,0);
End;

Run(Test);

Link to comment

Hey all,

Thanks for great responses here. I've had a read through all and have just tested your script Pat.

It's all good in terms of rotating the symbol within the group and I'm pretty sure I can play with the IF constraints to isolate it to a symbol as required the only issue it that the rotation seems to be around the group centre not symbol centre.

See the attached file for results and a little more insight.

Thankyou for the responses Raymond and Miguel, it's little snippets like this that'll get me over the line at some stage ;)

Cheers,

J

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...