Jump to content

Reassign classes within (multiple) symbol definitions


Recommended Posts

I am looking to update imported symbols so that the text within the symbol definitions is assigned appropriately to a "Text" class as I want to be able to toggle the text labels on or off. I can trawl through each symbol definition one-by-one via Resource Manager and select and reassign the text, but is there a quicker way? I have tried creating a worksheet database view which does list my text items within symbols, but not let me change them. Custom selection scripts don't appear to grant access within symbol instances. Currently I'm stumped.

Link to comment

Thanks for picking this up (again) Pat. If only it was all text I agree it would be easier. Unfortunately it is only text within a symbol that I am looking for. However all symbols are within their own layer if that helps any scripting possibilities.

 

So I am looking to select on the following criteria: all text items within symbols on a particular layer.

 

Some items will have an existing class matching that of the parent symbol and others will not have a class assigned or may have a different class which I need to reassign. Unfortunately multiple product suppliers have a myriad on non-uniclass methods of data formatting which is down to me to clean up.

 

incidentally your suggestion of doing an import into a cleaning file is great advice which I am encouraging colleagues to apply. 

Edited by DaviesTheChair
Link to comment

Wow thanks Pat. The Uniclass 2015 code for Furniture text is,....

I-ZZ-20-10-T-FurnitureReference

If you make it work for Furniture Text I may also need another for Equipment etc. so if I can get in and change the script "text" I can make those changes myself.

 

[Incidentally I have solved my previous issues around assigning values to Symbol Definition data. I am using SQLite database connections via Resource Manager so I will video and post as promised. Still awaiting ODBC fix - updates in next Service Pack I understand.]

Link to comment

Ah, good question. In this case I am trying to clean up instances already added in the drawing, but definitions are imported into the file and so also available via Resource Manager for the same file. Plus some symbols are only imported to Resource Manager without being inserted in the drawing. 

Edited by DaviesTheChair
Link to comment

So, how do you want it to work?

 

If we can say the workflow is to import into a new blank file, then there are a few ways we could go.

  Only process placed symbols

  Process All files in the Resource Manager

  Process Placed Symbols and mark those symbol definitions as having been processed. Either by a Tag or my adding a prefix character to the Symbol Name. The user can then see which Symbols have not been converted and choose to place then and convert or not.

 

If you import into a file that already has symbols, then you are going to have to settle for only the placed symbols as there will be no way for me to tell programmatically if the symbols in the RM are from the import and should be processed or are something that was already there that should be left alone.

Link to comment

I think the most likely scenario is that symbols will be placed in the blank “cleaning file”, then cleaned with the script and the definitions tagged to indicate they are cleaned. Changing the symbol name will likely create other problems with database connections so tagging would be best for us.

 

Given we will be using by a “cleaning” file, then only newly imported symbols will be in that file so any options are good for us. We may need to create a “furnishings” Uniclass class to propagate through the Symbol first, then adjust any text within the symbol to the Furniture Reference Class indicated above.

 

(sorry for delayed reply, forgot to hit send last night).

Link to comment

Here is a script to test.  If you run it multiple times on the same symbol it will work OK, but I don't check if the Symbol Definition has been previously tagged, so you may end up with multiple versions of the same tag.

 

Right click on a (or multiple selected) resources in the Resource Manager and choose Edit Tags if you want to delete the tags.

 

You can change the text of the tag and the name of the class to be assigned in the CONST section of the script.

 

This was written and tested in VW2021. Since it looks like you are using an earlier version, test carefully and make backups before using.

 

Copy everything in the following code block into a new blank Vectorscript.

 

Let me know if there are problems or you need more information.

 

Procedure ChangeTextClassInSymDefs;
{March 13, 2021}
{©2021 Patrick Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}

{No Warranty Expressed of Implied. Use at your own risk.}

{Scripting implies bugs. Bugs imply potential data loss.}
{make sure data is backed up before using this script.}
{Test thorougly for suitability to your needs.}
{Check with your doctor or programmer if sudden hair loss}
{occurs due to the use of this script.}

{The Class Name and the Tag to be applied can be edited in the}
{Const section below. Make sure to keep the string values}
{in single quotes and keep the semicolon at the end of the line.}


Const	TheClass='I-ZZ-20-10-T-FurnitureReference';
		TheTag='Symbol Text Processed';

Var	H1:	Handle;
	S1: String;
	
Procedure AddToTags(Hd3:Handle);
{Gets existing tags attached to symbol and adds TheTag to the end}
{All tags must be written at once, so you can't just add one tag}
{You have to read in the existing tags first.}
	Var		A1:DynArray of String;
			N1: Integer;
	Begin
		N1:=GetNumResourceTags(Hd3); {Get the number of existing tags}
		Allocate A1[1..N1+1]; {Set the array for 1 more than the exising number of tags}
		GetResourceTags(Hd3, A1); {Get all of the existing tags}
		A1[N1+1]:=TheTag; {Set the next available slot in the array to the new tag}
		SetResourceTags(Hd3, A1); {Store all of the tags to the symbol}
	End;

Function ChangeClass(Hd4:Handle):Boolean;
{Changes the class of Text objects to value stored in TheClass}
	Begin
		If GetTypeN(Hd4)=10 then  {Check Object type and process text object (type 10) only}
			Begin
				SetClass(Hd4, TheClass);	{Text}
			End;
	End;

Function Execute(Hd1:Handle):Boolean;
{Execute is the function name I use for scripts called from ForEachObject type calls}
{In this case it will take each object in the layer. If it is a symbol then Execute}
{will further call ChangeClass on the objects that make up the symbol definition}
	Var	Hd2:Handle;
	
	Begin
		IF GetTypeN(Hd1)= 15 then
			Begin						{Symbol}
				Hd2:=GetObject(GetSymName(Hd1));  {Get a handle to the symbol definition}
				ForEachObjectInList(ChangeClass, 0, 2, FInSymDef(Hd2)); {All Objects, Travers Deep}
				{Pass each object in the symbol definition to the ChangeClass function}
				AddToTags(Hd2);  {After processing all the objects in the symbol def. add the tag}
			End;
	End;


Begin
{Main procedure. Pass each object in the active layer to the Execute function.}
	ForEachObjectInLayer(Execute, 0, 2, 0);  {All objects, Traverse Deep, Current Layer)}
end;

Run(ChangeTextClassInSymDefs);

 

  • Like 2
Link to comment

That’s excellent and I can follow the logic. Many thanks for all your input Pat you are a star. It is getting late this side of the pond so will have a look tomorrow morning.  We are currently on Vw2021 but the symbols came from an older file so I will be testing in VWks 2021.

 

I hope to return the favour someday. 
 

Cheers,

Marc

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