Jump to content
Developer Wiki and Function Reference Links ×

VectorScript and Symbols


Jiajing

Recommended Posts

On 1/17/2008 at 5:28 PM, Pat Stanford said:

Jonathan is correct that it can be done, but how to do it depends on what you are trying to do.

So, what are you trying to do? Is it your symbol or just some generic symbol? Do you want to just go into the symbol edit mode, or do you want to make the changes and have them applied to all of the instances in the drawing?

Tell us more and we can probably help you.

Pat

HI Pat,

 

I am trying to go into the lighitng symbol, change geometry attributes and apply that changes to all instance in the drawing. any leads are appreciated.

Link to comment

I split this into a different thread since you tagged onto a 14 year old conversation. 😉

 

As far as I know symbols of lights are usually pretty complicated objects and specific parts need to have specific records attached to make them work properly. I don't know all of the internal details of what needs to be don't in light symbols.

 

Since you want all instances in the drawing changed you only need to edit the symbol definition.

 

How much programming experience do you have?

 

It is relatively easy to get a handle to a symbol definition from a selection on the drawing. Then you can get a handle to the first object in the symbol definition and "walk" through the list to find the objects you want to change. But you will pretty much have to test every object in the symbol to see if it is the one you are interested. Once you find it, you can modify it however you want.

 

But why do you want to do this by script? Unless you have a very large number of symbols that need to be changed in a very similar way, a script may not work well as each symbol could be made differently and you could need to modify the script for every symbol.

 

Is this something you want to be able to change back and forth between different sets of attributes? If so, you might be better off editing the symbols to have the attributes set to By Class and then just edit the class attribute settings as needed.

 

More definition of what you are trying to do will help with the solution.

  • Like 2
Link to comment

@Jiajing I believe what you are looking for is FInGroup to traverse through a symbol definition.  I have written out a simple script below that will traverse the symbol definition of a selected Lighting Device object and set the pen attributes of all symbol geometry to be By Class.

 

PROCEDURE UpdateLightingDeviceSymbol;

{	Traverses symbol geometry for selected Lighting Device Objects
	Developed by: Jesse Cogswell
	VW Version: 2019
	Date: 4/13/2022
}

CONST

	kLightingRecord = 'Lighting Device';
	kSymbolField = 'Symbol Name';

PROCEDURE UpdateSymbol(h:HANDLE);

{Pulls symbol for given lighting device object and traverses geometry}

	VAR
	
		lightSymName:STRING;
		symDefHd,h2:HANDLE;
	
	BEGIN
		lightSymName:=GetRField(h,kLightingRecord,kSymbolField);
		symDefHd:=GetObject(lightSymName);
		
		h2:=FInGroup(symDefHd);
		WHILE(h2<>NIL) DO
			BEGIN
				{FILL IN WHAT YOU WANT TO DO TO EACH OBJECT HERE}
				SetPenColorByClass(h2);
				
				h2:=NextObj(h2);
			END;
		
		ForEachObject(ResetObject,((R IN [kLightingRecord]) & (kLightingRecord.kSymbolField=lightSymName)));
	END;

BEGIN
	ForEachObject(UpdateSymbol,((R IN [kLightingRecord]) & (SEL=TRUE)));
END;

Run(UpdateLightingDeviceSymbol);

 

The works by following these steps:

  1. Use ForEachObject with the criteria to find Lighting Device objects that are also selected (may not be a bad idea to throw an additional criteria for selected objects on the active layer to prevent the script from being run on selected objects not on the active layer when not in Show/Snap/Modify) to start a PROCEDURE that I called UpdateSymbol.
  2. Use GetRField to pull the "Symbol Name" record field from given lighting device.
  3. Use GetObject with the symbol name to get a handle to the symbol definition used by the Lighting Device.
  4. Use FInGroup with the handle to the symbol definition to get a handle to the first object inside the symbol definition.
  5. Use a WHILE loop with the criteria set to <>NIL, this will ensure that the script will go through each object of the symbol definition and will terminate when the handle equals NIL (no object).
  6. This loop is where you will set your code to alter the geometry attributes.  In my example, I am using SetPenColorByClass to ensure that the object has its pen color attribute to be set by class (as I think you mentioned in the other thread).
  7. Use NextObj to cycle to the next object inside the symbol definition.  THIS IS SUPER IMPORTANT TO HAVE, OTHERWISE THE WHILE LOOP NEVER COMPLETES AND VECTORWORKS WILL CRASH!
  8. Once the loop terminates, you will need to make sure that the given Lighting Device object resets so that it will reflect the changes made to the symbol definition.  Normally, you would do this with ResetObject(h);  However, in this instance, you want to make sure that all other Lighting Device objects that use this definition are also updated, so instead you would do this with ForEachObject with the criteria set to look for Lighting Device objects whose "Symbol Name" field match the symbol definition.

Is this what you are looking to do?  As @Pat Stanford mentions above, this can be a dangerous operation, as you might not always want EVERY object inside a symbol definition to have their attributes set the same way.

  • Like 3
Link to comment

@PatStanfordI am defenitely learning coding.   I would love to traverse throught all objects inside lighting symbol and change their attributes to start, the reason I wasn't able to do that by SETCLASS simply becasue customized symbol libraries may not well maintained and objects could be assigned to mutiple classes, which is not easy to keep track on. 

 

@Jesse Cogswell Really appreciate on pointing me to the right direction. Good to know VWX is using FInGroup to reach inside lighting symbol, that is a huge help. One thing I do notice is that following criteria doesn't necessary work on VW2022 SP3 for some reason.

import vs;
vs.SelectObj("INOBJECT & (S='Light Instr ETC Source 4 LED Studio HD 10deg')");

The above script should select 10deg leko in the document, but it doesn't. 

 

I am working on find alternative criteria to RESETOBJECT. 

Edited by Jiajing
Link to comment

I am far from a Spotlight expert, but I don't think a Lighting Device actually contains the symbol of the light object. I think it just uses the symbol to hold geometry that it then imports. So you will probably not be able to find that symbol in the drawing if you are using it in lighting devices.

 

If you want to learn about scripting, just keep posting your questions. There are a number of us here including @Jesse Cogswell, @michaelk, @MullinRJ, @Sam Jones, and many other who I am blanking on right now who are happy to help get you over the hurdles.

Link to comment

@PatStanford 

import vs;
vs.SelectObj("INOBJECT & (S='Light Instr ETC Source 4 LED Studio HD 10deg')");

It does not work on script, but when I create that criteria using CUSTOME SELECTION, in that dialogue it does show number of symbols match that criteria. However, it just does not work by simply running the pure script.

 

Circle back to @Jesse Cogswell original post, I ended up using 

('Lighting Device'.'Symbol Name'={LightSymbolName}) # fstring here

That works great. Always learning. Thank you

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