Jump to content

Create a Texture with Color shader with imported Image


Recommended Posts

Hi,

 

I don't seem to find the way to create a texture color shader that will use a bitmap imported from the file system.

 

Looking at the documentation I found this possible sequence:

 

    texture = vs.CreateTexture()
    vs.SetName(texture, "Test Texture")
    shader = vs.CreateShaderRecord(texture, 1, 41)
    bitmap = vs.CreateTextureBitmap()

    image = vs.ImportImageFile("E:\IMG_8509.JPG", importPt)
    paint = vs.CreatePaintFromImage(image)
    vs.SetTexBitPaintNode(bitmap, paint)
    vs.SetTextureBitmap(shader, bitmap)
 

There seems to be some problems with this sequence:

  • vs.CreateTextureBitmap() is not doing what the documentation says; Instead of creating an empty bitmap object, it opens a dialog to pick an image. It seems to be deprecated also.
  • For some reason vs.CreatePaintFromImage(image) returns always 0 when an a  Type 14 (Bitmap Image – BITMAP) coming from vs.ImportImageFile() is used as parameter.

 

Some help will be appreciated

Thanks

 

--Carlos

 

Edited by gorrunyo
Link to comment

Hi Carlos

 

I also failed by doing this. I found a way that works for me:

 

1. Converting the external images to the Arroway format.

2. Manually select the "Import Arroway Materials" menu command. (I hope this function is part of your Vectorworks version)

 

Maybe this also can help you to realize your project.

 

The Python Script:

#DomC
import os
import shutil; import string
FileList = []
major, minor, maintenance, platform = vs.GetVersion()
isMac = False
if platform == 1: isMac = True
err, path = vs.GetFolder( 'Ordner mit Bildern auswählen' )
if err == 0: # no-error
    hsfPath = path
    if isMac: ok, hsfPath = vs.ConvertPosix2HSFPath( path )
    Index = 1
    while True: # loop the files
        fileName = vs.GetFilesInFolder( hsfPath, Index )
        Index += 1
        if fileName == '':
            break
        if fileName[0] != '.':    
            FileList.append(fileName)
n=1
for i in FileList:
    file, file_extension = os.path.splitext(i)
    folder = path+str(n)+'_'+file
    os.mkdir(folder, mode=0o777,dir_fd=None)
    shutil.move(path+i, folder+'/'+file+'_d100'+'.png')
    n=n+1

And if you want to rename the materials:

Bild_liste,numItems = vs.BuildResourceList(97, 0, 0) #97 steht für Material, die anderen Nummern, siehe Vectorscript Appendix
for bild in range(numItems):
    b = vs.GetResourceFromList(Bild_liste, bild+1)
    name = vs.GetName(b)
    #name = name[8:]
    newName = name[8:]+'.MAT'
    vs.SetName(b, newName)

 

Link to comment

Thanks DomC,

 

I do have a menu option "Import Arroway Textures" with I assume is the one you mention above.

 

Let me see if I understand the tip.

  1. The first script above will convert a directory with images (in PNG format?) to a format that the Import command will understand.
  2. After that script in step 1 is executed, then, manually select the "Import Arroway Textures" command in order to automatically create all the textures.
  3. Optionally run the second script in order to rename the created textures during step 2

Is that correct?

 

Cheers

--Carlos

 

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