Jump to content
Developer Wiki and Function Reference Links ×

select object on other layer


Recommended Posts


So I pick an object on the screen, then launch my script...I wanna get a handle to object picked, but of course

h := FSObject(ActLayer);

will only work if the picked object is on the active layer.

What I really want to do is

h := FSObject(All Visible Layers);

But I dont know how.

Anyone have any ideas?

Thanks in advance.


Link to comment

Hi Zero,

Here's a VS function that should do as you wish:


function FSVObj :Handle;

{ Return a handle to the First_Selected_Visible_OBJect. }


ObjHnd :Handle;

Function FSVisObj(H :Handle) :Boolean;


if Selected(H) then ObjHnd := H;

FSVisObj := Selected(H);

End; { FSVisObj }


ObjHnd := nil;

ForEachObjectInLayer(FSVisObj , 1, 0, 2);

FSVObj := ObjHnd;

End; { FSVObj }

Use it as you would FSActLayer.


[ 03-22-2004, 05:28 PM: Message edited by: MullinRJ ]

Link to comment
  • 2 weeks later...

Well Mr Mullin Sir, I have been working on your hint for the past few days and I have learnt a lot, including the following;

{} can only be used to comment out one line at a time, and certainly not blocks of other {} braces?

How do you comment out a whole block of code easily?

I got the ForEachObjectInLayer command to traverse deeply, return the class of each object, then hide that class. It was actually really easy!

I still can't workout how your snippet of code returns a handle to a selected object on another layer though. Why does "if Selected(H)" not simply return "true" if an object on any layer is selected?

Maybe if you can be bothered, you could explain how it works please.

If you are too busy, then no worries mate, I unnerstand!

Thanks in advance


Link to comment

Hi Mat,


How do you comment out a whole block of code easily?

You can comment out multiple lines of code with { }, but you are right about embedded comments, they will kick an error on the first unintentional }. If there aren't many comments in your block, you can remove all the }'s and retype them when you reinstate your code block. If there are a lot, you can replace the }'s with another character [i.e., an !], then replace the ! with } when you remove the outer { }. This assumes you are using an editor with search and replace features.

Next question.


Why does "if Selected(H)" not simply return "true" if an object on any layer is selected?

It would, but getting the handle to an object not on the Active Layer is not as easy as getting one ON the Active Layer. Unlike the standard suite of handle retrieving functions* (FSActLayer, FActLayer, LSActLayer, LActLayer, LnewObj), which is set up to work on the active layer, ForEachObjectInLayer() steps through EVERY object in the DRAWING. It's scope can be limited with the three integer option variables in its definition, which is defined in the VS 10.5 Function Reference as:


Procedure ForEachObjectInLayer(

actionFunc : PROCEDURE; { should say FUNCTION, not PROCEDURE }

objOptions : INTEGER;

travOptions : INTEGER;

layerOptions : INTEGER );

The handle of each object retrieved is passed to a user defined FUNCTION which can do anything you like. The actionFunc is defined as:


Function actionFunc(objHand :Handle) :Boolean;[/code][/indent]

As long as this function returns a value of FALSE, ForEachObjectInLayer will continue stepping through the objects in the drawing. When, or if, the function returns a value of TRUE, ForEachObjectInLayer will stop. If you want to examine every object in the drawing, then never return a TRUE value.

In my code, I have my actionFunc, FSVisObj(), return TRUE when an object is SELECTED. I know it is also visible because I set the first parameter (objOptions) to 1, which restricts ForEachObjectInLayer to only examine visible objects, and the fourth parameter (layerOptions) to 2, which further restricts it to only examine visible layers. The handle to the object in question is passed back through the locally global variable, ObjHnd.

If this does not clarify your question, ask again. Maybe I can be more succinct next time.



* FInLayer(), FSObject() will return handles to objects on other layers, but you have to know which layer you want first. An outer loop could be implemented to step through every layer in the drawing, and an inner loop to step through each object on a layer, but ForEachObjectInLayer does that for you now.

[ 04-04-2004, 01:13 AM: Message edited by: MullinRJ ]
Link to comment

Thanks Raymond

I'll keep working on it and let you know.

Part of my problem is I keep getting tripped upu with syntax type problems, (eg the {{}}), spend an hour mucking around solving that and it's soon bedtime.

And using the editor built into VW, on a 15" laptop at 1440x900 pixels make the { hard to see!



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.

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