Jump to content
Developer Wiki and Function Reference Links ×

Script to create selection scripts of used Light Instruments


Tom M.

Recommended Posts

Hi there,

 

Unfortunately, I have little to no experience with Vectorscript. So far I have created scripts via Marionette or menu commands.

 

I often want to select Light Instruments by its "Fixture Name".

Therefore I used Vectorscripts to select them by their individual name.

 

Script looks like this:

DSelectAll; SelectObj(INSYMBOL & INVIEWPORT & ((PON='Lighting Device') & ('Lighting Device'.'Inst Type'='ALEDA B-EYE K20')));

 

I have all these scripts in the Scriptpallette: 'Sel Scheinwerfer'

The annoying thing is that so far I have to modify each script individually as soon as I add new light instruments to the drawing which I have not used before.

It would be great if its possible to use a script that creates the individual scripts for the light instruments currently imported in the drawing.

Is this possible? Maybe someone can point me in the right direction.

 

Thanks for your help in advance

Tom

Edited by Tom M.
updated signature
Link to comment

@Tom M. Unfortunately, there's not really a way for a script to write scripts directly.  You could write a script that could create text files or even .vsm menu commands, but that would still involve either creating the new scripts and copying and pasting from the text files, or restarting Vectorworks and adding the new menu commands to your workspace.  If you went the route of the menu commands, you would also end up with a boat-load of commands depending on how many fixture types you work with.

 

Instead, I propose this solution: the script below will search the drawing for all Lighting Device objects and will build an array of the Inst Type fields that it finds.  Then, you can select the type or types that you want to select.  It's an extra click, but it's a more flexible script from drawing to drawing.

 

image.png.c4c158e70a164a32a9f608583955be00.png

 

PROCEDURE SelectFixtures;

{*	Builds an array of Lighting Device types and allows user to select all of each type in drawing
	Developed by: Jesse Cogswell
	Date: 4/24/2023
	Revisions:
*}

CONST

	kLightDevice = 'Lighting Device';
	kInstType = 'Inst Type';
	
VAR

	lightTypes:DYNARRAY[] OF STRING;
	numTypes:INTEGER;
	dialog,layoutDialog:LONGINT;

PROCEDURE AddToArray(h:HANDLE);

{Adds lighting device to array}

	LABEL 99; {Escape}
	
	VAR
	
		testStr:STRING;
		i:INTEGER;

	BEGIN
		testStr:=GetRField(h,kLightDevice,kInstType);
		
		FOR i:=1 TO numTypes DO
			BEGIN
				IF(lightTypes[i] = testStr) THEN GOTO 99;
			END;
		
		numTypes:=numTypes+1;
		ALLOCATE lightTypes[1..numTypes];
		lightTypes[numTypes]:=testStr;
		
		99: {Escape}
	END;

FUNCTION DrawDialog(DName:STRING) : LONGINT;

{Creates dialog box and returns dialog ID}

	CONST

		kWidth = 50;
		kHeight = 50;

	VAR

		dia:LONGINT;
	
	BEGIN
		dia:=CreateLayout(DName,FALSE,'OK','Cancel');
		
		CreateListBoxN(dia,11,kWidth,kHeight,TRUE);
		
		CreateGroupBox(dia,101,'Instrument Types',TRUE);
		
		SetFirstGroupItem(dia,101,11);
		SetFirstLayoutItem(dia,101);
		
		DrawDialog:=dia;
	END;

PROCEDURE DialogHandler(VAR item,data:LONGINT);

{Handles dialog box}

	VAR

		i,index:INTEGER;
		selectInst:STRING;
	
	BEGIN
		CASE item OF
			SetupDialogC:
				BEGIN
					FOR i:=1 TO numTypes DO AddChoice(dialog,11,lightTypes[i],i-1); 
				END;
			1: {OK}
				BEGIN
					FOR i:=1 TO numTypes DO
						BEGIN
							GetSelectedChoiceInfo(dialog,11,i-1,index,selectInst);
							IF(index <> -1) THEN ForEachObject(SetSelect,((R IN [kLightDevice]) & (kLightDevice.kInstType = selectInst)));
						END;
				END;
			2: {Cancel}
				BEGIN
				END;
		END;
	END;

BEGIN
	numTypes:=0;
	DSelectObj(ALL);
	
	ForEachObject(AddToArray,(R IN [kLightDevice]));
	
	IF(numTypes>0) THEN
		BEGIN
			SortArray(lightTypes,numTypes,0);
			
			dialog:=DrawDialog('Select Lighting Fixtures');
			layoutDialog:=RunLayoutDialog(dialog,DialogHandler);
		END
	ELSE AlrtDialog('No Lighting Fixtures found in drawing');
END;

Run(SelectFixtures);

 

  • Like 1
Link to comment

So happy with your help.

 

The script brings me directly to another idea.
Do you think it is also possible to create a script that selects the remaining fixtures of the same type used in the drawing based on an activated fixture?

So if I have a Fixture selected I run a Shortcut to select the rest of the same Fixtures?

 

Bonus.
Possibly even for similar plugin objects, like speakers etc.?

 

Tia Tom

  • Like 1
Link to comment

@Pat Stanford is exactly correct in terms of selecting similar plug-in types and is something I use all the time.  It looks like a "Magic Wand" and can be configured to work in all kinds of ways.  What you would be looking for is something like this:

 

image.png.22281d95cbbc9f2383d15eccae539e2e.png

 

You can save "presets" for what you want it to do, changeable in the Mode Bar when you activate the Select Similar tool.  I have one for Object Type, Symbol Name, and Class.

 

What it won't do is select similar based on a single parameter such as fixture type.  But that's easy enough to script:

 

PROCEDURE SelectSimilarFixture;

{*	Selects the same fixture types as selected Lighting Device objects on the active Layer
	Developed by: Jesse Cogswell
	Date: 4/23/2023
	Revisions:
*}

CONST

	kLightDevice = 'Lighting Device';
	kInstType = 'Inst Type';
	
VAR

	currentLayer:STRING;
	check:BOOLEAN;

PROCEDURE SelectSimilar(h:HANDLE);

	VAR
	
		testStr:STRING;

	BEGIN
		check:=TRUE;
		
		testStr:=GetRField(h,kLightDevice,kInstType);
		ForEachObject(SetSelect,((R IN [kLightDevice]) & (kLightDevice.kInstType = testStr)));
	END;

BEGIN
	check:=FALSE;
	currentLayer:=GetLName(ActLayer);
	
	ForEachObject(SelectSimilar,((SEL) & (L=currentLayer) & (R IN [kLightDevice])));
	
	IF NOT check THEN AlrtDialog('No Lighting Devices currently selected on active Layer');
END;

Run(SelectSimilarFixture);

 

  • Like 2
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...