Jump to content
Developer Wiki and Function Reference Links ×

Label Legend Swapper


Recommended Posts

Attempting a script that searches my lighting devices and finds the ones rotated less than 180 degrees and applies my second label legend.

This is what I have thus far:

Procedure Loop;

Procedure RotTest;

VAR

h :handle;

rot :integer;

BEGIN

SetSelect(h);

rot:= GetSymRot(h);

If rot<180 THEN

BEGIN

SetRField(h,'Lighting Device','Use Legend','Legend Rotated');

End;

END;

BEGIN

ForEachObjectInLayer(RotTest, 2, 0, 4);

END;

RUN (Loop);

I get a Boolean error and I am unsure why. Any advice/better solutions?

Much appreciated,

J

Link to comment

The problem is that ForEachObjectInLayer needs a Function in stead of a Procedure. You also forget the Handle. So

Procedure RotTest;

should be

Function RotTest(h : HANDLE) : BOOLEAN;

SetSelect(h);

This isn't necessary. Most of the time, you don't need to select your objects to adjust them in VS

rot :integer;

Better would be to make it a Real in stead of an Integer. Otherwise your value will get rounded. So 179,8 will become 180 and i don't think that is what you want (could be wrong of course).

ForEachObjectInLayer(RotTest, 2, 0, 4);

Here you're passing almost every object on the active layers to the Procedure RotTest. That way you'll also try to adjust that record field even if the object doesn't have that record attached.

Better would be:

ForEachObject(RotTest,(R IN ['Lighting Device']));

Now you'll only pass that objects that have that record attached. But be aware, this will pass objects on all layers while ForEachObjectInLayer only passed objects on the layers you choosed. Also, this procedure doen't need a Function to call, but a Procedure.

Link to comment

Maarten,

Your help has led to something so so helpful to me thankyou. For those of you who are interested in a finished product or for me reading this later when I can't remember what I did:

Procedure Loop;

Procedure RotTest(h : HANDLE);

VAR

rot :real;

BEGIN

rot:= GetSymRot(h);

If GetRField(h,'Lighting Device','Device Type')='Light' THEN

BEGIN

If rot<=0 THEN

BEGIN

SetRField(h,'Lighting Device','Use Legend','Legend Rotated');

ResetObject(h);

sysbeep;

End

ELSE

BEGIN

SetRField(h,'Lighting Device','Use Legend','Regular');

ResetObject(h);

sysbeep;

End;

End;

END;

BEGIN

ForEachObject(RotTest,(R IN ['Lighting Device']));

END;

RUN (Loop);

Mission success! Thanks all!

J

Ps. sysbeeps are just for fun!

Edited by James Russell
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...