Jump to content

Worksheet Criteria to search layer tags


Recommended Posts

Is there any way to use layer tags as a worksheet criteria?

 

We have a main inventory on our front page that auto counts symbols of all different types with different records attached. When we duplicate a layer to try a different symbol layout or show a second position on worksheets our worksheet then adds all these duplicate fixtures.

 

Rather than going in to the worksheet and setting each criteria to ignore the new layers (there are a lot) it would be nice to say to ignore all layers with a certain tag, lets say an "Ignore" tag. Is this possible or failing that does anyone have any cunning ways of accomplishing the same result.

 

Thanks

 

Ben

  • Like 2
Link to comment

I don't believe there is a way in VW2019 and before to use tags in criteria.

 

Would it be better to use a positive entry for layers that you DO want in the worksheet rather than a negative entry for layers you DON'T want?

 

That way you would only need to edit the criteria if you added a layer that you wanted to keep.

Link to comment
  • 2 years later...
  • 2 years later...
  • Vectorworks, Inc Employee
40 minutes ago, ashot said:

@Pat Stanford on somewhat related topic: do you know how to search and filter SL in Navigation palette using Layer Tags for Sheet Layers

What is the use of Tags if I can not use them in search field on Navigation palette?

While you cannot search for tags directly in the search field on the Navigation palette, you can setup layer filters based on tags.

Link to comment

Thank you Hugues, I know that setting up new filter tied to tag is a way to sort the list.
However for every Tag  I need to create Matching Filter, I can not use several Tags in the same Filter.
I was hoping to avoid a duplicate of my work, if I could just use Tags to search.

 

Example: Many (500)  Sheet Layers with Details have Tags: Drilling, Nothing, Rebars, etc. I can assign several Tags to each Layer. However instead of searching by one Tag name, I have to create matching Filter for each and every Tag to do the same. It wold be useful to have Tags behave like a keyword in search, and with comma separation I would get more results. The Filters on the other Hand are very useful to include all other parameters for Layers. But they are limited by choosing only one Tag at a time.

see screenshot of sample layres

 

Screenshot2024-06-25at1_44_52PM.thumb.jpg.8912469cb87f5fb8ecd14fc7d19f8deb.jpg

 

Screenshot2024-06-25at1_45_07PM.thumb.jpg.5955df02d17c81826f8bf3e30df37ff0.jpg

Screenshot2024-06-25at1_45_22PM.thumb.jpg.e5e02acfc3bb2e0351d505124973a07c.jpg

 

 

 

 

 

Edited by ashot
Link to comment

Here is a simple version that will give you a database of all the layers associated with a single tag.

 

Save the script with a name of 'Layer_DB_By_Tag'

 

Create a database row with dummy criteria and then right click on the header and choose Edit Database Formula. Replace the formula with

 

{=DatabaseByScript('Layer_DB_By_Tag', 'Your Tag Name Here')}

=DatabaseByScript('Layer_DB_By_Tag', 'Your Tag Name Here')

 

Using your tag name instead.

 

You can use the above formula in as many different database rows with different tag names as will fit in your worksheet.

 

The script is currently set to handle layers with up to 20 tags. It does not care if there are more than 20 different tags as long as no layer has more than that. If you need more, edit the script and change the three locations where it says 20 and increase to what you need.

 

Procedure Layer_DB_By_Tag;
{©2024  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

{takes a single parameter which is the name of Tag associated to a Layer}
{returns a database of all the layers that have that tag.}

{use with a worksheet DatabaseByScript database formula.}
{=DatabaseByScript('Layer_DB_By_Tag', 'Your Tag Name Here')}

VAR	
	H1:		Handle;
	S1:		String;
	B1:		Boolean;
	A1:		Array[1..20] of string;
	N1:		Integer;
	
BEGIN
	S1:=WSScript_GetPrmStr(0);

	H1:=FLayer;

	While H1<> Nil DO
		Begin
			For N1:=1 to 20 Do A1[N1]:='';

		
			B1:=GetObjectTags(H1,A1);
			For N1:=1 to 20 DO
				BEGIN
					If A1[N1]=S1 then WSScript_AddHandle(H1);
				End;
			H1:=NextLayer(H1);
		End;
End;

Run(Layer_DB_By_Tag);

 

Link to comment

@Pat Stanford Thank you for help and good script.

Later on I will attach a sample file to describe my dilemma.

 

but for now  I was looking something trivial (if exists at all)

say in any search database in one column I can type =Layer() and get the name of all found layers

so, my question: is there any similar command like: =LayerTags() to get the tags listed in the next column

 

Link to comment

No there is no built in function to return Layer Tags.

 

It is possible with a different worksheet script.  

 

Are your layers going to have multiple tags? If so, do you want them all returned in a single cell? Or to be able to separate them out to multiple columns?  If a single column what would you like to use as a separator character between the tags?

Link to comment

I know it is too much to ask:

 

Yes, Layers have dozen tags

first column - single cell, separated by comma

+ next columns - each tag separated in multiple columns

 

Note:

I can achieve this with multiple  Data Tag on every sheet layer with assigned Keyword Records and bring to database with OR statement

and then I can Select Item from database - that is the exact behavior  I need

but creating records and duplicating the same info in order to match Layer Tags, makes no sense to me

I really hope to achieve the same just with Layer Tags - that is my goal

 

Link to comment

Ok. Try these. I am not at all certain how well these are going to work on your 500 layer file. You are going to be running 6000+ scripts every time you recalculate the worksheet. It may be very slow.

 

Two scripts.  All_Layer_Tags and Specific_Layer_Tag.

 

All_Layer Tags returns a single comma delimited list of all the tags associated with a layer

Specific_Layer_Tag returns the single tag in the tag list position specified by a passed integer.

 

Run them in a worksheet with the following formulas.

 

=RunScript('All_Layer_Tags')

 

=RunScript('Specific_Layer_Tag',1)

Where you change the 1 to whatever positon you want to see the tag from.

 

And here are the scripts.  Rename as necessary and change the MaxTags constant to however large of number you need for the maximum number of tags.

 

Procedure All_Layer_Tags;
{©2024  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

CONST
	MaxTags=20;

VAR	
	H1		:Handle;
	S1		:String;
	A1		:Array[1..MaxTags] of string;
	B1,B2	:Boolean;
	N1		:Integer;
	
BEGIN
	H1:=WSScript_GetObject;
	B1:=GetObjectTags(H1, A1);
	S1:='';
	B2:=False;
	For N1 := 1 to MaxTags DO
		BEGIN
			If A1[N1]<>'' then
				BEGIN
					If B2 Then S1:=Concat(S1,', ',A1[N1]) Else S1:=A1[N1];
					B2:=True;
				End;
		End;
	WSScript_SetResStr(S1);
End;

Run(All_Layer_Tags);

 

Procedure Specific_Layer_Tag;
{©2024  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

CONST
	MaxTags=20;

VAR	
	H1		:Handle;
	A1		:Array[1..MaxTags] of string;
	B1		:Boolean;
	N1		:Integer;
	
BEGIN
	H1:=WSScript_GetObject;
	N1:=WSScript_GetPrmInt(0);
	B1:=GetObjectTags(H1, A1);
	WSScript_SetResStr(A1[N1]);
End;

Run(Specific_Layer_Tag);

 

Link to comment

The last scripts I posted are not for the database, but rather for the database header row columns.

 

I have add three more scripts for use with DatabaseByScript.  DB_Of_Design_Layers, DB_Of_Sheet_Layers, DB_Of_All_Layers.  Pick the one you want and make a database row using that script name and the DatabaseByScript command. This will give you a database that has a single subrow for every Layer. 

 

=DatabaseByScript('DB_Of_Design_Layers')

 

The other scripts are run using a RunScript formula in the database header row. The All_Layer_Tags script returns all of the tags in a single cell.

=RunScript('All_Layer_Tags')

 

The Specific_Layer_Tag script returns the 1st, 2nd, ... (as specified by the final integer) tag associated with a layer.  These are not necessarily in any given order.

=RunScript('Specific_Layer_Tags',1)

 

If the worksheet gets too slow using multiple versions on the Specific_Layer_Tag script, another possibility would be to use an IF function to extract the data from the All_Layer_Tags column.  Something like:

 

=IF(FIND('epoxy', B5)<>-1, 'epoxy', '')

Where B5 is the database header row for the column listing all of the Tags attached to the Layer. This will show epoxy in the column for only those layers that have a Tag of epoxy.  But you will have to be careful, as if you have a tag of "epoxy" and a tag of "epoxy anchor" (or anything else that has "epoxy" as a sub-string) it will be returned also.

 

Using this IF function would allow you to have a single column that would show "epoxy" for only those layers that have the "epoxy" tag. And by changing the strings you can set up single columns for any tag you want.

 

Here is my edited version of your test file.

 

 

Test 5-pat.vwx

Link to comment

And actually you could edit the Find formula to replace the explicit "epoxy" settings with a cell value so you only have to type the Tag name once.

 

So if you put the IF formula in the database header row cell B5, you could type the Tag name into cell B4 and edit the IF to be something like:

 

=IF(FIND(B4, B5)<>-1, B4, '')

 

Link to comment

-1 is what the FIND function returns when the substring is not found.

 

The function says to FIND the substring in the text. If is it found (any returned result other than -1) then return the substring (or you could enter any test you wanted if you only wanted an X in that column for instance), otherwise if the substring is not found, return an empty string (two single quotes).

 

  • Like 1
Link to comment
  • 3 months later...

Hi thanks for sharing the scripts.

I'm pretty new in scripting in VWx and wanted to manipulate the script. I want to read the tags from textures. My list is filtered by objects (extrusions, ...) So I added the lines to get the texture of the object and from these I want to read the tags. Unfortunately it doesn't work. I get confused one time we use vs and one time python in the forum.

Procedure Specific_Object_Tag;

CONST
	MaxTags=20;

VAR	
	H1		:Handle;
	tr		:INTEGER;
	A1		:Array[1..MaxTags] of string;
	B1		:Boolean;
	N1		:Integer;
	text_name:string;
	
BEGIN
	H1:=WSScript_GetObject;
	N1:=WSScript_GetPrmInt(0);
	tr:=GetTextureRefN(H1, 0, 0, 0);
	text_name:=Index2Name(tr);
	GetObjectTags(text_name, A1);
	WSScript_SetResStr(A1[N1]);
End;
	
Run(Specific_Object_Tag);

thanks for any help!

Link to comment

GetObjectTags requires. a Handle (think library book id [Dewey Decimal System]) not a name (think book title).

 

And a couple of other small errors.

 

Procedure Specific_Object_Tag;

CONST
	MaxTags=20;

VAR	
	H1,H2	:Handle;
	tr		:INTEGER;
	A1		:Array[1..MaxTags] of string;
	B1		:Boolean;
	N1		:Integer;
	text_name:string;
	
BEGIN
	H1:=WSScript_GetObject;
	N1:=WSScript_GetPrmInt(0);
	tr:=GetTextureRefN(H1, 0, 0, FALSE);
	text_name:=Index2Name(tr);
	H2:=GetObject(text_name);
	B1:=GetObjectTags(H2, A1);
	WSScript_SetResStr(A1[N1]);
End;
	
Run(Specific_Object_Tag);

 

I think this version will do what you want.

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