Macro Texture Objects: Difference between revisions

From FreeCAD Documentation
(Created page with '{{Macro|Name=Texture Objects|Description=This macro allows you to temporarily put a texture image on selected objects. To remove the textures, simply close and reopen the documen…')
 
No edit summary
Line 1: Line 1:
{{Macro|Name=Texture Objects|Description=This macro allows you to temporarily put a texture image on selected objects. To remove the textures, simply close and reopen the document.|Author=yorik}}
{{Macro|Name=Texture Objects|Description=This macro allows you to temporarily put a texture image on selected objects. To remove the textures, simply close and reopen the document.|Author=yorik}}

[[Image:Textured_objects.jpg]]


import FreeCADGui
import FreeCADGui
Line 12: Line 14:
rootnode = obj.ViewObject.RootNode
rootnode = obj.ViewObject.RootNode
tex = coin.SoTexture2()
tex = coin.SoTexture2()
tex.filename = jpgfilename
tex.filename = str(jpgfilename)
rootnode.insertChild(tex,1)
rootnode.insertChild(tex,1)

Revision as of 12:56, 13 October 2011

Generic macro icon. Create your personal icon with the same name of the macro Texture Objects

Description
This macro allows you to temporarily put a texture image on selected objects. To remove the textures, simply close and reopen the document.

Author: yorik
Author
yorik
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

import FreeCADGui
from PyQt4 import QtGui
from pivy import coin

# get a jpg filename
jpgfilename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open image file','*.jpg')

# apply textures
for obj in FreeCADGui.Selection.getSelection():
    rootnode = obj.ViewObject.RootNode
    tex =  coin.SoTexture2()
    tex.filename = str(jpgfilename)
    rootnode.insertChild(tex,1)