Jump to content
The Hamma

Script to create Classes from Textures

Recommended Posts

"""
This script identifies the name of a texture in the drawing and creates a new class with identified 
texture assigned to the newly created class.
This is useful so that objects can be textured by assigning them to the appropriate class. 

This Python Script may be freely distributed. No warranty provided.
Use at your own risk.

If the name of the texture and the prefix exceeds 63 characters the class name will be shortened to 63 
characters.  This is a Vectorworks class name limitation. 

David Hamer, 2020
"""

ClassPrefix ='I-FNSH-' #Newly created classes prefix

TextureList, NumItems = vs.BuildResourceList(97, 0, '') 
while NumItems != 0:
	TextureName = vs.GetNameFromResourceList(TextureList, NumItems) 
	TextureClassNameW = vs.Concat(ClassPrefix,TextureName)
	TextureClassName = vs.Copy(TextureClassNameW, 1, 63) 
	vs.NameClass(TextureClassName)
	vs.SetClFillFore(TextureClassName,0,0,0)
	vs.SetClFillBack(TextureClassName,0,0,0)
	vs.SetClPenFore(TextureClassName,65535,65535,65535)
	vs.SetClPenBack(TextureClassName,65535,65535,65535)
	vs.SetClFPat(TextureClassName,1)
	vs.SetClLSN(TextureClassName,2)
	vs.SetClLW(TextureClassName,10)
	vs.EnableCLDropShadow(TextureClassName,False)
	vs.SetClUseGraphic(TextureClassName,True)
	TextureIndex = vs.Name2Index(TextureName)
	vs.SetClTextureC(TextureClassName, TextureIndex)
	vs.SetClTextureD(TextureClassName, TextureIndex)
	vs.SetClTextureG(TextureClassName, TextureIndex)
	vs.SetClTextureL(TextureClassName, TextureIndex)
	vs.SetClTextureR(TextureClassName, TextureIndex)
	vs.SetClTextureT(TextureClassName, TextureIndex)
	vs.SetClUseTexture(TextureClassName, True)
	NumItems = NumItems -1

 

 

Edited by The Hamma

Share this post


Link to post

Hey @The Hamma this is a nice script that I've finally got around to checking out. Could be really usefully when experimenting with different textures.

Are you using it in your workflow? Would it be useful iof the script also placed the selected object in the newly created class as well as made the object's take on the class texture?

Thanks for sharing it.

Share this post


Link to post

The script creates several classes at once and would not know which class to assign the selected object to. I will think about it and if any ideas come to mind I will script them down.  On another note the script above would change the settings of previously created classes created by this script when running it a second time.  I have modified the script to only create a new class if it does not exist and to give you a list of all the newly created classes when it is finished. 

 

"""
This script identifies the name of a texture in the drawing and creates a new class with identified 
texture assigned to the newly created class.
This is useful so that objects can be textured by assigning them to the appropriate class. 

This Python Script may be freely distributed. No warranty provided.
Use at your own risk.

If the name of the texture and the prefix exceeds 63 characters the class name will be shortened to 63 
characters.  This is a Vectorworks class name limitation. 

David Hamer, 2020 Revised 2020-07-31
"""

ClassPrefix ='I-FNSH-' #Newly created classes prefix
runtimes = 0

TextureList, NumItems = vs.BuildResourceList(97, 0, '') 
while NumItems != 0:
	TextureName = vs.GetNameFromResourceList(TextureList, NumItems) 
	TextureClassNameW = vs.Concat(ClassPrefix,TextureName)
	TextureClassName = vs.Copy(TextureClassNameW, 1, 63) 
	ClassCount = vs.ClassNum()  # determine number of classes in drawing
	vs.NameClass(TextureClassName)
	if ClassCount + 1 == vs.ClassNum():
		runtimes = runtimes + 1
		if runtimes == 1:
			allclasses = TextureClassName
		else:
			allclasses = vs.Concat(allclasses, ', ', TextureClassName)
		vs.SetClFillFore(TextureClassName,0,0,0)
		vs.SetClFillBack(TextureClassName,0,0,0)
		vs.SetClPenFore(TextureClassName,65535,65535,65535)
		vs.SetClPenBack(TextureClassName,65535,65535,65535)
		vs.SetClFPat(TextureClassName,1)
		vs.SetClLSN(TextureClassName,2)
		vs.SetClLW(TextureClassName,10)
		vs.EnableCLDropShadow(TextureClassName,False)
		vs.SetClUseGraphic(TextureClassName,True)
		TextureIndex = vs.Name2Index(TextureName)
		vs.SetClTextureC(TextureClassName, TextureIndex)
		vs.SetClTextureD(TextureClassName, TextureIndex)
		vs.SetClTextureG(TextureClassName, TextureIndex)
		vs.SetClTextureL(TextureClassName, TextureIndex)
		vs.SetClTextureR(TextureClassName, TextureIndex)
		vs.SetClTextureT(TextureClassName, TextureIndex)
		vs.SetClUseTexture(TextureClassName, True)
	NumItems = NumItems -1

if runtimes != 0:	
	vs.AlrtDialog('New Classes Created: ', allclasses)
else:
	vs.AlrtDialog('No new Classes created')

 

Edited by The Hamma

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