Jump to content
Developer Wiki and Function Reference Links ×

Symbol Library - Editing with Scripts


Recommended Posts

Hey all,

I want to alter some records within symbols in the symbol library. My end goal is to select some symbols in the library, run the script and changes are made to records in each of the items in the library.

I'm wondering if anyone can point me in the direction or let me know if helpful commands for:

1. Getting a handle to object selected in the Resource Browser.

2. Editing a record of selected symbol within Resource Browser.

Anything relating to these would be helpful, even just for a read-through.

Cheers,

J

Link to comment

Vectorscript is pretty much a single file option. I don't think you will be able to open a different file and edit the symbols.

You might be able to import the symbols and edit them in the current file and then export them back to the resource file.

Take a look at the ResourceList functions (Document List Handling) to see how to get a list of resources and import them into the current file.

I don't know how to export them back to a resource file using VS.

Link to comment

So right now I'm quite content with just working within my file with symbols that are within it.

As a little starter example I'm just wanting to select my symbol in the resources browser and have the script alter the width of that object from within the symbol. I think that's the first link I need to make in my head.

I'll keep reading this list.

Thanks Pat for the starting point,

J

Link to comment

So I wrote this:

{-------------Test Change Record - Selected Items----------}

PROCEDURE xxx;

CONST

record = 'Light Info Record';

parameter = 'Device Type';

value = 'New Type';

FUNCTION Replacement (h:HANDLE) : BOOLEAN;

BEGIN

h:=FInSymDef(h);

SetRField(h,record,parameter,value);

END;

BEGIN

ForEachObjectInList(Replacement,2,0,FSymDef);

END;

Run(xxx);

{---------------}

Two things. Didn't work. Not unexpected but would have been nice.

The ForEachObjectInList says that Object Options can be Selected Objects Only (2), does this include if you've selected something in the resource browser?

Secondly traversing depth... er...?

J

Link to comment

Didn't test it, but i think you need to add SetRecord before SetRField.

...

h:=FInSymDef(h);

SetRecord(h,record);

SetRField(h,record,parameter,value);

...

And here's an example of a dialog with Image popup in which you can select a symbol. If you want to make a list of symbols in your library, you need to replace "kFolder = 0" to something else (look in the Funct Ref under BuildResourceList for a list of the FolderIndexes).

PROCEDURE Example;
CONST
kSymbol = 16;
kFolder = 0;
kImgPopRes = 100;
VAR
listID, numItems,diaID,MesInt: LONGINT;
HBname : STRING;

{sub}
PROCEDURE DialHand(VAR item,data:LONGINT);
VAR
	cnt,tmpint : INTEGER;
BEGIN
	CASE item OF
		SetupDialogC: FOR cnt:=1 TO numItems DO tmpint:=InsertImagePopupResource(diaID,kImgPopRes,listID,cnt);
		1:
		BEGIN
			tmpint:=GetImagePopupSelectedItem(diaID,kImgPopRes);
			HBname:=GetImagePopupObject(diaID,kImgPopRes,tmpint);
		END;
	END;
END;
{endsub}
{main}
BEGIN
listID:=BuildResourceList(kSymbol,kFolder,'',numItems);
diaID:=CreateLayout('title',FALSE,'OK','Cancel');
CreateControl(diaID,kImgPopRes,10,'',0);
SetFirstLayoutItem(diaID,kImgPopRes);
IF VerifyLayout(diaID) THEN MesInt:=RunLayoutDialog(diaID,DialHand);
IF (MesInt=1) THEN Message('You have selected ',HBname);
END;
RUN(Example);

Link to comment

James,

Not sure of everything you want to do, but to change the all the field values, you don't need to do this with VS. Just go to Tools>Records>Change One Field.

OK, back to the script.

To apply a script to symbols, you can't affect only selected symbols in the resource browser. You can get a handle to:

- The active symbol definition

- Symbol definitions for selected symbol instances in the drawing

- Every symbol in the resource browser by stepping through the list

ForEachInList does not pay attention to resource selection.

In order to access symbols in folders, you have to use recursion.

Procedure do stuff(h)

IF get type (h) is symbol folder, then do stuff(first symbol in folder)

else...

h:=next def after h

Do stuff (first def handle)

I think there may be an example in the online VS examples section.

Attaching records to symbols, you're dealing with the record attached to the entire symbol, not FInSymDef(h). (ie. just deal with the record attached to h)

If you are changing the width of very symbol (which I think you alluded to), then you would need to step through every object in the symbol, starting with FInSymDef.

-Josh

Link to comment

Thanks Maarten and Josh,

Maarten - I tried the change, no result yet but I think I still need to do a bit more reading about handles and referencing.

Josh - Change one field you say... Ah! This is a work around for part b) of my problem. There are two outcomes that I wanted to achieve from this. The first being object manipulation through a script from within the resource browser, ie. Select a few symbols in your browser and have them all filled black or width increased by 100mm.

The second part was record manipulation. Much like your Instrument Maintenance can rewrite the base Light Info Record on a fixture but on a batch scale. I've done some modifications to the Light Info Record (not quite mastered yet mind you), in an attempt to give a lamp a specific Label Legend upon insertion, ie. Fluro batten having an elongated Label, ganged cyc units and small conventionals vs large conventionals. In this case I was hoping to just select the fixtures in my library and much like the dialog for Change One Field select the record/parameter/field value and set the selected fixtures. I think Change One Field will work, I'll just move batches of things into folders, make the required batch changes and move them back.

I'll keep at it regardless in all the spare time I have ;)

Cheers,

J

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