Jump to content
Developer Wiki and Function Reference Links ×

Access an unknown number of objects inside a unknown number of nested groups


Recommended Posts

Hello Everyone,

I have a very nasty problem which until now nobody could solve. This is the problem.

I have a layer called laySupport. On that layer there can be an unlimited number of objects, groups and even nested groups inside other groups. The level of nested groups are unknown (can be 1, 10, infinite...). In short it cannot be predicted how many groups and especially nested groups there will be on the laySupport layer.

I have to disconnect all the records from every individual group member. I do that with a DelRecord(hndObject,1) instruction.

My problem.I cannot determine how many groups and escpecially nested groups there are present on the layer laySupport or inside another group. I need to access every individual group member.

Do you know how I can access every individual object inside an unknown number of nested groups?

I will appreciate your help very much. I am sure the one who can solve this problem, is very good indeed. If you need the example document, send me an email and I will send you the document with everything in it. The script is calling ResetGroup. We are using Vectorworks Architect 9.1 Dutch version for Mac.

I thank you very much and I wish you a nice day.

With friendly greetings,

StarGateEmail : woods@skynet.be

Link to comment

If all you want to do is perform a function on a GROUP, and you don't care how deeply nested it is, you can use the ForEachObjInLayer procedure.

PROCEDURE ForEachObjectInLayer (actionProc : PROCEDURE;? ? objOptions :INTEGER;? ? travOptions :INTEGER;? ? layerOptions :INTEGER);

with procedure calls reading something like this:

Procedure actionProc(H :Handle); Begin if (ObjType(H)=11) then begin { Do something to GROUP here } end; End; ForEachObjectInLayer(actionProc, 0, 1, 0);

The Online Function Reference can be found at:http://www.nemetschek.net/support/custom/vscript/functionref/VSFunctionReference.html

IF you would like to have more control of object processing, the following recursive routine can be used. Recursion is fun, especially if you have lots of RAM, but who doesn't these days? tongue.gif" border="0

PROCEDURE Recurse;CONST aGroup = 11;VAR Level :Integer; ObjHnd :Handle;

Procedure StepIn (ObjHnd :Handle; var Level :Integer); { Step through each Obj in a Group } Begin Level := Level + 1; { counter is not necessary, but can be used for debug }

{ Do stuff to entire GROUP object here, if desired }

ObjHnd := FInGroup(ObjHnd); { Get handle to First Obj in GROUP } while (ObjHnd<>nil) do { Step through each Obj in GROUP } begin if (GetType(ObjHnd)= aGroup) then StepIn(ObjHnd, Level) { Enter nested GROUP and continue } else begin

{ Do stuff to non-GROUP objects here, if desired } { these are the non-GROUP objects that are in the group }

end; { if } ObjHnd := NextObj(ObjHnd); { Next Obj in GROUP } end; { while }

Level := Level - 1; { Decrement on exit } End;

BEGIN Level := 0; ObjHnd := FActLayer; while (ObjHnd<>nil) do { Step through each Obj on Active Layer } begin if (GetType(ObjHnd)= aGroup) then StepIn(ObjHnd, Level) { now enter the group and continue } else begin { Do stuff to non-GROUP objects here, if desired } { these are the non-GROUP objects that are on the Active Layer } end; ObjHnd := NextObj(ObjHnd); { Next Obj on Active Layer } end;

if (Level<>0) then SysBeep; { Something went wrong }END;Run (Recurse);

Have fun,Ray Mullin

[ 01-08-2002: Message edited by: MullinRJ ]

Link to comment

Hello Ray,

Thank you very much for your explanation and your code. I will try it and give you a message about my successes.

I am very glad that you do know the answer to my problem. On this moment I can go 10 nested groups deep, thereafter it stops. Because I never know how much nested groups and objects inside, the code has to check itself. I did not know about the For-Each-object in VectorWorks.

Thank you very much for your help. I really appreciate it because I searched for hours without finding a solution. Now the sun shines again a little brighter.

I wish you a very nice day and very much success with VectorScript programming.

Friendly greetings,

StarGate(Chrissy)

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