Jump to content
Developer Wiki and Function Reference Links ×

Alternative to SelectObj


Recommended Posts

Hi all,

Just playing with a new script and having a little issue with SelectObj. I have a whole heap of lighting devices all being called by a ForEach loop. I'm then taking their dimming data and trying to select the appropriate dimmer.

Each of my temp dimmers has a record and field 'Dimming Data'.'Dimmer Name'. There are only individual entities at the moment so no double ups.

Currently I've been calling these with:

DSelectAll;

SelectObj('Dimming Data'.'Dimmer Name'=LDCIRCUIT);

DIMH:=FSActLayer;

Where LDCIRCUIT is the dimmer name taken previously as a string. This works fine as long as your dimming layer is active. Is there something better I can use? I would have loved if it was

DSelectAll;

DIMH:=SelectObj(ect..);

But alas no.

Suggestions?

Cheers,

James

Link to comment

I don't think you can combine variables with constants as part of a criteria. If you create the entire criteria string as a single variable you can then use that in the SelectObj. Something like:

MyVar := Concat('Dimming Data'.'Dimmer Name'=LDCIRCUIT);

SelectObj(MyVar);

I have not gotten the quotes done properly in the above example. You either need to triple quote (''') the single quotes to get them to actually be part of the string or use my perferred option of using CHR(39). If you use the CHR then the correct version of the above line becomes:

MyVar := Concat(Chr(39),'Dimming Data',Chr(39),'.',CHR(39),'Dimmer Name',CHR(39),'=LDCIRCUIT');

But you probably need to replace LDCIRCUIT with the actual text and not the variable name.

Link to comment

- The less your code uses selected objects, unless you want your code to only work with a user selection, the happier you will be. There are enough VS routines that affect selection state/order, it's really best to do everything handle based.

- ForEachObject and ForEachObjectIn... will be your friends. Instead of using a loop, you act on each object with a sub procedure or function. VS will handle the list iteration for you.

- Criteria used to be a lot more fussy about variables and constants, but I find I don't need to force them into a string anymore. Just as good coding practice, however, I recommend using constants for all your record and field selectors.

-Josh

Link to comment

WhoCanDo - Totally agree. I did have a ForEachLoop in the first revision but I'll explain more in a sec.

Pat - I'm actually a fan of the triple ' . I enjoy the challenge of deciding between single, double, triples and quads. You're right though, I'll condense a few bits in a sec.

Josh - I'm only just really getting handles. It's taken a VERY long time for me to even start using them in my scripting. I'm revising a lot of my older stuff to include ForEach.. in them.

I think the overall issue here might not relate to the SelectObj part of the script and more to what happens after, if you're not on the current layer. From my experience thus far any of the select commands select across all layers. I'm then using the FSActLayer to grab and save the handle of my selected object (Dimmer) for later use.

The issue for me is what if it's not on the active layer, either on a different layer or a hidden layer, what is the call to allow me to get a handle to the object, FSSelectionAcrossAllLayers?

Thanks for the help thus far though, loving the scripting love.

J

Link to comment

Quote:

"Each of my temp dimmers has a record and field 'Dimming Data'.'Dimmer Name'. There are only individual entities at the moment so no double ups."

so if there are no doubles then you expect SelectObj to only select one item, therefore ForEachObject will know the handle no matter which layer it is on.

With

procedure Record_H (h : handle);

begin

DIMH:=h;

end;

you will record h from any layer.

Regards

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