Jump to content
jonasfehr

Create a texture resource from image in a folder

Recommended Posts

Hi,

I try now to subdivide my question from my previous post - Looking for script to import images as imageprop.

Does anyone have a good approach to create a texture resource from images loaded from a folder.

I found the example script to load images as symbols(https://developer.vectorworks.net/index.php/Python_Sample_Import_Images_as_Symbols), but I can't figure out how to bind them to a renderworks texture. Afterwards the texture could be used on an extruded object or with a image prob.

Cheers

Jonas

 

Share this post


Link to post

I got so far, to create a texture, and add a shaderrecord set to color / image. But how to add a path to a image?

 

h_text = vs.CreateTexture()
h_shaderRecord = vs.CreateShaderRecord(h_text, 1, 41) # color image

 

Share this post


Link to post

Following forum entry says it's not possible with python can someone verify this?

 

 

Share this post


Link to post

Hi Jonas,

 

From Vectorworks 2019 and newer it is possible to create a image based texture by using CreateTextureBitmapD (before you had to use a dummy texture...)

#Part 1 - import and convert image
hPaint = vs.ImportImageFile(thePath, 0,0) #Needs to be deleted afterwards
hImage = vs.CreateImageFromPaint(hPaint, 'Just_a_name')

#Part 2 - Create ShaderRecord and convert to TextureBitmap
hShaderRec = vs.CreateShaderRecord(hTexture, 1, 41) #1 = Color image
hTextureBitMap = vs.CreateTextureBitmapD( hShaderRec)

#Part 3 - Connect the image to the TextureBitmap
vs.SetObjectVariableHandle(hTextureBitMap, 528, hImage) #Were the magic happens!

Hope this helps.

🙂

Gelde-Aart

  • Like 1

Share this post


Link to post

Here my complete script to choose a folder and import the images as rendertexture:

 

import os

major, minor, maintenance, platform = vs.GetVersion()
isMac = False
if platform == 1: isMac = True

# define a location to import the images
importPt = (0,0)

symCreatedCnt = 0

err, dirPath = vs.GetFolder( 'Select a Folder' )
if err == 0: # no-error
	hsfDirPath = dirPath
	if isMac: ok, hsfDirPath = vs.ConvertPosix2HSFPath( dirPath )

	fileIndex = 1
	while True: # loop the files
		fileName = vs.GetFilesInFolder( hsfDirPath, fileIndex )
		fileIndex += 1

		if fileName == '': # no more files
			break

		name, ext = os.path.splitext( fileName )
		if ext.lower() == '.png' or ext.lower() == '.jpg':
			imagePath = os.path.join( dirPath, fileName )
						
			hPaint = vs.ImportImageFile(imagePath, 0,0) #Needs to be deleted afterwards
			hImage = vs.CreateImageFromPaint(hPaint, 'Just_a_name')

			hTexture = vs.CreateTexture()
			vs.SetName(hTexture, name+"_tex")
			hShaderRec = vs.CreateShaderRecord(hTexture, 1, 41) #1 = Color image
			hTextureBitMap = vs.CreateTextureBitmapD( hShaderRec)

			vs.SetObjectVariableHandle(hTextureBitMap, 528, hImage) #Were the magic happens!
			
			vs.DelObject(hPaint)
			symCreatedCnt += 1

vs.AlrtDialog( 'Done! Imported ', symCreatedCnt , ' images to textures.' )

Hope it is beneficial for other too...

  • Like 3
  • Love 1

Share this post


Link to post

Thanks for sharing this very useful script.

Would be possible to modify script to be able to select only one image or selected images instead of whole content of folder?

Thanks.

Share this post


Link to post

I don't think so, I can't find any function which returns just some selected files after a folder dialog.

But you could add a condition, and just create textures, when the naming fit's some criteria...

if "xxx" in name :
	#create the texture

 

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