Jump to content
jonasfehr

Accessing objects within a symbol / lighting devices

Recommended Posts

Hi,

I am quite new to vw, but have been programming for many years now. Unfortunately I have a very hard time understanding the API and how to use it.

For a project I am working on, I need to export the position, rotation etc. of certain planes and render cameras, as the naming is crucial and we need to be able to simply redesign and replace objects, we would like to use the built in tools from spotlight.

So far, I managed to find the handles of objects based on predefined classes [ForEachObject(...)], and am able to export their position and naming to a csv table. But when it comes to symbols i hit a wall. I am able to define the search criteria looking for a symbols name, which works if its a standard symbol, but when I try to do the same for the symbol associated with a lighting device (or is it called instrument), it is not found. When I have found the handle to a specific symbol, how I am not able to go into the symbol/object and access components/objects inside of it. Can anyone help me out?

 

Here the main questions I have are:

  1. How do I access the components/objects inside a symbol / lighting device?
  2. How can i create a search criteria for Lighting Devices (not lights)?
  3. Can anyone point me to a good collection of scripts I could use as reference?

 

Sorry if I use the wrong terminology to describe my problem.  Actually that's another confusion - How to name the different components?

 

I hope anyone can help me out

kind regards

Jonas

 

import vs
import os, sys, stat 
import numpy as np
import pandas as pd


handlersList = []  # list to store handlers to the cameras
symbolsList = []  # list to store handlers to symbols

#vs.AlrtDialog();
def collect_Symbols(h):
    symbolsList.append(h)
    
vs.ForEachObject(collect_Symbols, "( (C ='Stands') )" )

def collect_handlers(h):
    handlersList.append(h)

vs.ForEachObject(collect_handlers, "( (C ='ContentPlaceHolder') | (C ='RenderPoints') )")

#vs.AlrtDialog(len(handlers));

databased_export = []
for i, h in enumerate(handlersList):
	#symbolName = vs.GetSymName(h)
	className = vs.GetClass(h)
	name = vs.GetName(h)
	posXY, posZ = vs.Get3DCntr(h)
	w, h, d = vs.Get3DInfo(h)
	#hasOri, xRot, yRot, zRot, isMirroredXY = vs.Get3DOrientation(h)

	databased_export.append([className, name, posXY[0], posXY[1], posZ, w, h, d]) #, xRot, yRot, zRot])
	

columns = ["className", "name", "posX","posY", "posZ", "w", "h", "d"]#, "xRot", "yPot", "zRot"]
dataframe = pd.DataFrame(databased_export, columns=columns)

script_path = os.path.split(vs.GetFPathName())[0]
dataframe.to_csv(os.path.join(script_path, "ExportForPano2VR.csv")) # store dataframe in csv for external checking

 

Share this post


Link to post
Posted (edited)
2 hours ago, jonasfehr said:
  • How do I access the components/objects inside a symbol / lighting device?
  • How can i create a search criteria for Lighting Devices (not lights)?

1. For every symbol defined in the resource manager there is one Symbol Definition (grouplike object that contains the actual objects) that can have multiple Symol Instances in the drawing. You collected the symbol instances.

To get the definition you have to get the name first:

 

Quote

symDef =  vs.GetObject( vs.GetSymName( symInst) )

 

1.1

 

So to get the symbol off a lightning device you get the symbol instance inside the parametric object (grouplike object).

 

In the doc is a good example off iterating groups:

https://developer.vectorworks.net/index.php/VS:FInGroup

 

 

2. To find param objects by a creatia you have to look if the parametric record is present which is mostly eual to the name in the OIP:

Unbenannt.thumb.PNG.73fb2fd496598658af88418c754c1419.PNG

Edited by PatW

Share this post


Link to post

And as a follow on to what PatW said, Symbols have one a single definition. If you edit that definition it will edit for EVERY instance in the drawing. If you truly need to have specially named objects inside of individual lights, you probably can not use the standard Spotlight instruments to do that. Or you will have to duplicate the Symbol Definition and have a separate definition for every different instrument.

 

Would it be possible to just attach a Record to the Instrument in question with the added data that you need?

Share this post


Link to post

Thanks PatW and Pat S. for your quick responses.

It is fine just to work with the naming of the LightDevices (LDs), what I need is the absolut placement of the components inside the LDs.

So my idea is following:

  1. search for the LDs
  2. getTheirPosition
  3. find their corresponding Symbol Definition (symDef)
  4. find the components i need inside the symDef.
  5. combine the relative positioning of the components in de symDef with the absolute position of the LDs.
  6. write these positions to my spreadsheet, make them unique identifiable to their "parent" with the given UnitNumer from the LDs

Does this approach make sense?

Following skript does the first 3 steps, but now I have difficulties to identify the objects of interest inside the symDef. It's mainly a plane, which i need the center position, size  and orientation from.

 

ld_list = []  # list to store handlers to light devices

def collect_LightDevices(h):
    ld_list.append(h)
    
vs.ForEachObject(collect_LightDevices, "((R IN ['Lighting Device']))" )

for ld in ld_list:
	# find the symname of the stands
	h = vs.FInGroup(ld)
	while vs.GetTypeN(h) != 15:
		h = vs.NextObj(h)		
	print(vs.GetSymName(h))
	symDef =  vs.GetObject( vs.GetSymName(h) )
	h = vs.FInGroup(symDef)
	# here I got stuck how to identify the objects of interest
	# so far I have been using class naming to identify them but is there a smarter way?

 

Share this post


Link to post

1 through 5 make good sense as as to the general steps required.

 

For 6 rather than directly writing them to the spreadsheet (unless you need the data to go into a specific cell), I would consider just writing the data to a Record/Field and then using the Database function of the worksheet to pull in the data for you. That way you avoid all of the hassle of trying to keep track of what row and column you are trying to write into for each object. It might also allow you to have a version of the script that would update the record for a specific object that you know has changed rather than having to run on every light in the drawing every time there is an update.

Share this post


Link to post

Thanks, I really apprechiate your feedback. I'll think a little about what would be smartest four our purpose.

 

Do you have any suggestions regarding step 4 & 5. How I can search for specific object within a symbol def?

I may still haven't understood the overall logic behind objects. As I understand it now, they can be almost anything. So how can I for example loop through just the objects within the symDef? And how to identify for eksample a 3D plane?

 

Share this post


Link to post

PatW's code above gets you the handle to the Symbol Definition.  FInSymDef will get you to the first object in the symbol definition. From there you check the object type and then use NextObject to iterate through the symbol definition until you find what you want.

 

I am not aware of a 3D Plane being an object type in Vectorworks, so I don't know how you get that. I think you will have to find that object that is on the plane and then calculate  the plane information from the object position. And then probably adjust based on the Instrument portion and angle as the symbol definition will be drawn in its own coordinate system.

Share this post


Link to post

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.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...