Jump to content
Sign in to follow this  
DomC

Get a List of all symbols of a symbol folder

Recommended Posts

Hi

I try to get a list of symbols in a specific symbol folder on the active document. I searched the script reference and the internet. It sould be possible by using:

id, number = vs.BuildResourceList(16, -1, foldername)

But the result is always an empty list. All positive index values works but lists all symbols in all folders. I can't find out, what I am doing wrong.

Would be fantastic if anyone can help. The following script, do what I want (not finally, it's just a test, the alert box is my debug workflow :-)

Best Regards

Dom

folderlistid,listlength = vs.BuildResourceList(92, 0,'')

i=0
x=1

while i < listlength:
foldername = vs.GetNameFromResourceList(folderlistid,x)
vs.AlrtDialog('foldername :'+foldername)
symlistid, symnum='keine', 0
symlistid, symnum = vs.BuildResourceList(16, -1, foldername) #index -1 do not work?	#index 

n=0
o=1
while n < symnum:
	symname= vs.GetNameFromResourceList(symlistid,o)
	vs.AlrtDialog('symname: '+str(symname))
	n=n+1
	o=o+1
i=i+1
x=x+1

n=0
i=2
while n < 20:
foldername = vs.GetNameFromResourceList(folderlistid,x)
symlistid, symnum = vs.BuildResourceList(16, i, 'Folder-1') #just to test, if maybe an index from +2 till -20 works
symname= vs.GetNameFromResourceList(symlistid,1)
vs.AlrtDialog('symname: index'+str(i)+str(symname))
n=n+1
i=i-1

Share this post


Link to post

The foldername variable is used for the RESOURCE folder name starting from the path identifier used. This has nothing to do with a symbol folder.

I'm pretty sure your best option is to loop trough all symbol definitions and check their parent folder so you can do your thing.

Edited by hippothamus

Share this post


Link to post

Cool, great hint. GetParent() does the job perfectly.

symid = vs.FInFolder( vs.GetObject( 'Folder-1' ) )

while vs.GetTypeN(symid)==16:
folder=vs.GetName(vs.GetParent(symid))
symname=vs.GetName(symid)
vs.AlrtDialog('symname: '+symname+' parent :'+folder)
symid=vs.NextSymDef(symid)
sym=symid

if vs.GetTypeN(sym)!=16:
	vs.AlrtDialog('keine weiteren Symbole im Ordner')

Share this post


Link to post

Great, the python subforum isnt dead!

Am curious of what you use for your IDE. I'm trying to get into scripting in python but I can't seem set up Aptana to work with Vectorworks.

Do you use Aptana or something else?

THanks

Tui

Share this post


Link to post
Great, the python subforum isnt dead!

Am curious of what you use for your IDE. I'm trying to get into scripting in python but I can't seem set up Aptana to work with Vectorworks.

Do you use Aptana or something else?

THanks

Tui

I use IntelliJ IDEA, which is great for python.

Also check out: https://bitbucket.org/dieterdworks/vw-dlibrary, It's a library for scripting plugins in python for VW. Open-source and everyone is welcome to contribute.

Share this post


Link to post

PyCharm. But not integrated any vs modules ... handy to check those intents.

To keep it alive. The working result:

A simple script to paste all symbols of a folder on the active layer. The idea is to enlarge it sometime with text of the symbol name or making layers for every symbol folders to get a nice, printable preview of all symbols. I think code could be still more reduced and optimized.

def placesymb(name,x,y,spalten):
reihen=num/spalten
vs.Symbol(name,x,y,0)
return()

symid = vs.FInFolder( vs.GetObject( 'Folder-1' ) )
x=0
y=0
num=0
spalten=4 #total spalten
zeile=0 #aktuelle zeile
versatz=2 # einheit beachten!
n=0

while vs.GetTypeN(symid)==16:
folder=vs.GetName(vs.GetParent(symid))
symname=vs.GetName(symid)
placesymb(symname,x,y,spalten)
symid=vs.NextSymDef(symid)
sym=symid
x=x+versatz
zeile=int(n/spalten)
y=zeile*versatz	
if n % spalten ==0:
	x=0

n=n+1

or another one, to place all symbols of a folder on a activated area. The symbol loops till the area is filled:

def placesymb(name,x,y,spalten):
vs.Symbol(name,x,y,0)
return()

versatz = 4
rotation = 0
folder='Folder-1'	
area = vs.FSActLayer()
symid = vs.FInFolder(vs.GetObject(folder))


p1,p2=vs.GetBBox(area)
x1=p1[0]
y1=p2[1]
x=x1
y=y1
num=0
breite=abs(p2[0]-p1[0])
hoehe=abs(p2[1]-p1[1])

zeile=0
spalte=0
i=0
spalten=int(breite/versatz)


zeilen=(hoehe/versatz)
n=0

while spalte <= spalten and zeile <=zeilen:

folder=vs.GetName(vs.GetParent(symid))
symname=vs.GetName(symid)
p=x,y
if vs.PtInPoly(p, area) == True:
	placesymb(symname,x,y,spalten)
symid=vs.NextSymDef(symid)

if vs.GetTypeN(symid)!=16:
	symid=vs.FInFolder(vs.GetObject(folder))
x=spalte*versatz+x1		
zeile=int(n/spalten)
if spalte % spalten ==0:
	spalte=0
spalte=spalte+1	
y=zeile*versatz+y1
n=n+1	
i=i+1	

Share this post


Link to post

Oh, appreciate it Dieter and Dom..

I'm currently trying to get my head around Object oriented programming and starting with C++, going through the lessons at learncpp.com, it's a long read/exercise but I'm hoping to translate the OPP thinking onto python.

Your repo looks very interesting and helpful. Appreciate the initiative.

I've decided to go with Visual Studio 2015, as they have both Python & C++ IDE's.

The journey continues...

tui

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.

Sign in to follow this  

 

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