Macro Texture Objects: Difference between revisions

From FreeCAD Documentation
m (modify "tex.filename = str(jpgfilename)" to "tex.filename = str(jpgfilename[0]))
(Use {{MacroCode}})
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|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}}
|Name=Texture Objects
|Icon=Macro_Texture_Objects.png
|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
|Version=1.0
|Date=2011-10-13
|Download=[https://www.freecadweb.org/wiki/images/d/da/Macro_Texture_Objects.png Icon Toolbar]
|FCVersion= 0.18 and below
}}


<!--T:2-->
==Description== <!--T:2-->
This macro allows you to temporarily put a texture image on selected objects. To remove the textures, simply close and reopen the document.
This macro allows you to temporarily put a texture image on selected objects. To remove the textures, simply close and reopen the document.


</translate>
<!--T:3-->
[[Image:Textured_objects.jpg|680px]]
[[Image:Textured_objects.jpg|680px]]
<translate>


==Script== <!--T:4-->
</translate>
</translate>

{{clear}}
'''Macro_Texture_Objects.FCMacro'''
<syntaxhighlight>

{{MacroCode|code=


import FreeCADGui
import FreeCADGui
Line 27: Line 41:
rootnode.insertChild(tex,1)
rootnode.insertChild(tex,1)


}}
</syntaxhighlight>
<translate>

==Links== <!--T:5-->

<!--T:6-->
[https://forum.freecadweb.org/viewtopic.php?t=7216 Macro Texture Objects]

<!--T:7-->
[https://forum.freecadweb.org/viewtopic.php?f=3&t=28795 Script to map texture with environement checked]

</translate>
{{clear}}
{{clear}}
<languages/>

Revision as of 22:49, 7 May 2020

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.

Macro version: 1.0
Last modified: 2011-10-13
FreeCAD version: 0.18 and below
Download: Icon Toolbar
Author: yorik
Author
yorik
Download
Icon Toolbar
Links
Macro Version
1.0
Date last modified
2011-10-13
FreeCAD Version(s)
0.18 and below
Default shortcut
None
See also
None

Description

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

Script

Macro_Texture_Objects.FCMacro

import FreeCADGui
from PySide 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[0])
    rootnode.insertChild(tex,1)

Links

Macro Texture Objects

Script to map texture with environement checked