VS:ForEachObjectInList

From Vectorworks Developer
Revision as of 19:07, 20 December 2013 by Root (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Processes all items in the specified list and and applies the specified action to each item.

Table - ForEachObjectInList Selectors
Option Selector Description
Object Options
All objects 0
Visible Objects only 1
Selected Objects only 2
Unlocked objects only 4
Traversal Options
Traverse Shallow 0
Traverse Groups 1 Traverse inside groups
Traverse Deep 2 Traverse all containers

(walls, extrudes, sweeps, etc)

PROCEDURE ForEachObjectInList(
actionFunc :FUNCTION;
objOptions :INTEGER;
travOptions :INTEGER;
list :HANDLE);
def vs.ForEachObjectInList(actionFunc, objOptions, travOptions, list):
    return None

Parameters

actionFunc FUNCTION Subroutine which performs operation on found objects.
objOptions INTEGER Object selection option index.
travOptions INTEGER Search options index.
list HANDLE Handle to first item in list.

Remarks

Be careful using this together with a call to VS:BeginSym: it deselects all selected objects on active layer (VW 13)

It seems that when you fill in a NIL Handle in the list Parameter, the ActionFunc will be executed on all the objects of the active layer (VW2011).

Example

VectorScript

PROCEDURE Example;
{ This example demonstrates how to duplicate multiple objects by preserving the constraints between them.}
{ We will duplicate all objects on the active layer, 
{ create a new layer and insert them into it and select them.}
CONST
   newLayerName = 'MyNewLayer';
VAR
 srcLayerH, srcLayerList, newLayerH : HANDLE;  
   
FUNCTION DoMultipleDuplicate(h :HANDLE) :BOOLEAN;
VAR
 dupH : HANDLE;
BEGIN
   
   dupH := CreateDuplicateObject(h, NIL);  { copy and insert into active layer }
   SetSelect(dupH);
   
END;

FUNCTION BuildModel(h :HANDLE) :BOOLEAN;

BEGIN
   BuildConstraintModelForObject(h, FALSE); 
   { 'traverseContainers' is set to FALSE because we are getting here from a ForEach call}
   { that already goes deep inside containers}
END;


BEGIN
 srcLayerH := ActLayer;
 srcLayerList := FActLayer;  
 newLayerH := CreateLayer(newLayerName,1);
 IF ((srcLayerH <> ActLayer) & (srcLayerList <> NIL)) THEN  BEGIN
    { start a multiple objects duplicate that preserves constraints}
    BeginMultipleDuplicate;
    { duplicate all objects }
    ForEachObjectInList(DoMultipleDuplicate, 0, 0, srcLayerList);
    { end the multiple duplicate process} 
    EndMultipleDuplicate;
 END;

 { all objects in the first layer have been duplicated and inserted into the new layer }
 { we must build a contraint model for the duplicated objects }
 ForEachObjectInLayer(BuildModel, 0, 2, 0);

  
END;
RUN(Example);

Python

def DoMultipleDuplicate(h):
	dupH = vs.CreateDuplicateObject(h, None) #{ copy and insert into active layer }
	vs.SetSelect(dupH)

def BuildModel(h):
	vs.BuildConstraintModelForObject(h, False) 
	#{ 'traverseContainers' is set to FALSE because we are getting here from a ForEach call}
	#{ that already goes deep inside containers}

def Example():
	#{ This example demonstrates how to duplicate multiple objects by preserving the constraints between them.}
	#{ We will duplicate all objects on the active layer, 
	#{ create a new layer and insert them into it and select them.}
	newLayerName = "MyNewLayer"

	srcLayerH = vs.ActLayer()
	srcLayerList = vs.FActLayer()  
	newLayerH = vs.CreateLayer(newLayerName,1)

	if ((srcLayerH != vs.ActLayer()) & (srcLayerList != None)):
		#{ start a multiple objects duplicate that preserves constraints}
		vs.BeginMultipleDuplicate()
		#{ duplicate all objects }
		vs.ForEachObjectInList(DoMultipleDuplicate, 0, 0, srcLayerList)
		#{ end the multiple duplicate process} 
		vs.EndMultipleDuplicate()

	#{ all objects in the first layer have been duplicated and inserted into the new layer }
	#{ we must build a contraint model for the duplicated objects }
	vs.ForEachObjectInLayer(BuildModel, 0, 2, 0)

Example()
PROCEDURE Example;
CONST
pioName = 'Complex Window 2';
parameter = 'MeasureHeight';
value = 'Head of Window';

FUNCTION DoIt(h :HANDLE) :BOOLEAN;
BEGIN
h := FInSymDef(h);
SetRField(h, pioName, parameter, value);
END;

BEGIN
ForEachObjectInList(DoIt, 0, 0, FSymDef);
END;
RUN(Example);


Another example:

PROCEDURE Example;
CONST
pioName = 'Window';
parameter = 'UPI';
value = '25.4';

FUNCTION DoIt(h :HANDLE) :BOOLEAN;
BEGIN
h := FInSymDef(h);
IF (h <> NIL) & (GetType(h) = 86) & (Eval(h, 'R IN [pioName])') > 0) THEN BEGIN
SetRField(h, pioName, parameter, value);
END;
END;

BEGIN
ForEachObjectInList(DoIt, 0, 0, FSymDef);
END;
RUN(Example);

Python:

pioName = 'Complex Window 2'
parameter = 'MeasureHeight'
value = 'Head of Window'

def DoIt(h):
    h := vs.FInSymDef(h);
    vs.SetRField(h, pioName, parameter, value);

vs.ForEachObjectInList(DoIt, 0, 0, vs.FSymDef);

Python


Version

Availability: from VectorWorks 8.5