FreeCAD Logo FreeCAD 1.0
  • English Afrikaans Arabo Bielorusso Catalano Czech German Greek Spanish Spanish Basco Finnish Filippino Français Galiziano Croatian Hungarian Indonesiano Italiano Japanese Kabyle Coreano Lituano Dutch Norvegese Bokmal Polish Portuguese Portuguese Romanian Russian Slovak Slovenian Serbo Swedish Turkish Ukrainian Valenziano Vietnamita Cinese Cinese
  • Funzioni
  • Download
  • Blog
  • Documentazione
    Indice di documentazione Per iniziare Documentazione utenti Il manuale FreeCAD Documentazione degli ambienti di lavoro Documentazione di scripting Python Documentazione codice C++ Tutorial Domande frequenti Politica sulla Privacy Informazioni Su FreeCAD
  • Contribuire
    Come aiutare Sponsor Segnala un bug Fai una richiesta Opportunità di lavoro e ricompense Linee guida per contribuire Manuale degli sviluppatori Traduzioni
  • Comunità
    Codice di condotta Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Calendario
  • ♥ Donate

Donate

$
Informazioni SEPA
Si prega di intestare il bonifico SEPA a:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Agenzia bancaria: BNP Paribas Fortis
Indirizzo: Rue de la Station 64, 1360 Perwez, Belgium

While Stripe doesn't support monthly donations, you can still become a sponsor! Simply make a one-time donation equivalent to 12 months of support, and you'll gain access to the corresponding sponsoring tier. It's an easy and flexible way to contribute.

If you are not sure or not able to commit to a regular donation, but still want to help the project, you can do a one-time donation, of any amount.

Choose freely the amount you wish to donate one time only.

You can support FreeCAD by sponsoring it as an individual or organization through various platforms. Sponsorship provides a steady income for developers, allowing the FPA to plan ahead and enabling greater investment in FreeCAD. To encourage sponsorship, we offer different tiers, and unless you choose to remain anonymous, your name or company logo will be featured on our website accordingly.

from 1 USD / 1 EUR per month. You will not have your name displayed here, but you will have helped the project a lot anyway. Together, normal sponsors maintain the project on its feet as much as the bigger sponsors.

from 25 USD / 25 EUR per month. Your name or company name is displayed on this page.

from 100 USD / 100 EUR per month. Your name or company name is displayed on this page, with a link to your website, and a one-line description text.

from 200 USD / 200 EUR per month. Your name or company name and logo displayed on this page, with a link to your website and a custom description text. Companies that have helped FreeCAD early on also appear under Gold sponsors.

Instead of donating each month, you might find it more comfortable to make a one-time donation that, when divided by twelve, would give you right to enter a sponsoring tier. Don't hesitate to do so!

Choose freely the amount you wish to donate each month.

Please inform your forum name or twitter handle as a notein your transfer, or reach to us, so we can give you proper credits!

Macro PartToVRML

Descrizione
Questa macro converte le parti selezionate in mesh VRML.

Versione macro: 1.9.2
Ultima modifica: 2016-02-22
Download: ToolBar Icon
Autore: Easyw-fc
Autore
Easyw-fc
Download
ToolBar Icon
Link
Raccolta di macro
Come installare le macro
Personalizzare la toolbar
Versione macro
1.9.2
Data ultima modifica
2016-02-22
Versioni di FreeCAD
None
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Questa macro converte le parti selezionate in mesh VRML per avere dimensioni ridotte e un caricamento più rapido (modelli VRML compatibili con KiCad e Blender)

Script

L'icona

Macro_PartToVRML.FCMacro

# -*- coding: utf-8 -*-

# PartToVRML.FCMacro
# creates VRML model of selected object(s), with colors (for KiCad and Blender compatibility)
# useful messages on Report view
#

__title__ = "PartToVRML"
__author__ = "easyw-fc, hyOzd"
__url__     = "https://freecad.org/"
__version__ = "1.9.2"
__date__    = "22/02/2016"

__Comment__ = "This macro creates VRML model of selected object(s), with colors (for KiCad and Blender compatibility)"
__Web__ = "https://freecad.org/"
__Wiki__ = "https://wiki.freecad.org/index.php?title=Macro_PartToVRML"
__Icon__  = "https://wiki.freecad.org/images/f/f8/PartToVRML.png"
__IconW__  = "C:/Users/User Name/AppData/Roaming/FreeCAD/Macro_PartToVRML.png"
__Help__ = "start the macro and follow the instructions"
__Status__ = "stable"
__Requires__ = "Freecad"

# FreeCAD VRML python exporter is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This sw is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with expVrmlColor.FCMacro.  If not, see
# <http://www.gnu.org/licenses/>.

## export VRML from FreeCAD is a python macro that will export simplified VRML of 
## a (multi)selected Part or fused Part to VRML optimized to KiCad and compatible with Blender
## the size of VRML is much smaller compared to the one exported from FC Gui
## and the loading/rendering time is smaller too
## change mesh deviation to increase quality of VRML

## to do 
#  export material properties to vrml

import FreeCAD,FreeCADGui,Part,Mesh
import PySide
from PySide import QtGui, QtCore
from collections import namedtuple
import sys, os
from os.path import expanduser

#clearing previous messages
mw=Gui.getMainWindow()
c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
c.clear()
r=mw.findChild(QtGui.QTextEdit, "Report view")
r.clear()

def say(msg):
    FreeCAD.Console.PrintMessage(msg)
    FreeCAD.Console.PrintMessage('\n')

# points: [Vector, Vector, ...]
# faces: [(pi, pi, pi), ], pi: point index
# color: (Red, Green, Blue), values range from 0 to 1.0
Mesh = namedtuple('Mesh', ['points', 'faces', 'color', 'transp'])

def shapeToMesh(shape, color, transp, scale=None):
    mesh_deviation=0.03 #the smaller the best quality, 1 coarse; 0.03 good compromise :)
    mesh_data = shape.tessellate(mesh_deviation)
    points = mesh_data[0]
    if scale != None:
        points = map(lambda p: p*scale, points)
    newMesh= Mesh(points = points,
                faces = mesh_data[1],
                color = color, transp=transp)
    return newMesh
        
def exportVRML(objects, filepath):
    """Export given list of Mesh objects to a VRML file.

    `Mesh` structure is defined at root."""

    with open(filepath, 'w') as f:
        # write the standard VRML header
        f.write("#VRML V2.0 utf8\n\n")
        for obj in objects:
            f.write("Shape { geometry IndexedFaceSet \n{ coordIndex [")
            # write coordinate indexes for each face
            f.write(','.join("%d,%d,%d,-1" % f for f in obj.faces))
            f.write("]\n") # closes coordIndex
            f.write("coord Coordinate { point [")
            # write coordinate points for each vertex
            #f.write(','.join('%.3f %.3f %.3f' % (p.x, p.y, p.z) for p in obj.points))
            f.write(','.join('%.3f %.3f %.3f' % (p.x, p.y, p.z) for p in obj.points))
            f.write("]\n}") # closes Coordinate
            #shape_col=(1.0, 0.0, 0.0)#, 0.0)
            f.write("}\n") # closes points
            #say(obj.color)
            shape_col=obj.color[:-1] #remove last item
            #say(shape_col)
            shape_transparency=obj.transp
            f.write("appearance Appearance{material Material{diffuseColor %f %f %f\n" % shape_col)
            f.write("transparency %f}}" % shape_transparency)
            f.write("}\n") # closes Shape
        say(filepath+' written')
###

def export(componentObjs, fullfilePathName, scale=None):
    """ Exports given ComponentModel object using FreeCAD.

    `componentObjs` : a ComponentObjs list
    `fullfilePathName` : name of the FC file, extension is important
    
    """
    
    exp_name=componentObjs[0].Label
    path, fname = os.path.split(fullfilePathName)
    fname=os.path.splitext(fname)[0]
    if scale != None:
        filename=path+os.sep+exp_name+'.wrl'
    else:
        filename=path+os.sep+exp_name+'_1_1.wrl'
    say(filename)    
    color=[]
    Diffuse_color=[]
    transparency=[]
    for obj in componentObjs:
        say(obj.Label)
        color.append(Gui.ActiveDocument.getObject(obj.Name).ShapeColor)
        transparency.append(Gui.ActiveDocument.getObject(obj.Name).Transparency/100.0)
        #say("color")
        #say(Gui.ActiveDocument.getObject(obj.Name).DiffuseColor)
        Diffuse_color.append(Gui.ActiveDocument.getObject(obj.Name).DiffuseColor)
    i=0
    meshes=[]
    #say("diffuse color")
    #say(Diffuse_color)
    indexColor=0;
    color_vector=[]
    applyDiffuse=0
    for obj in componentObjs:
        shape1=obj.Shape
        single_color=Diffuse_color[i];
        #check lenght color
        #say("len color")
        #say(len(single_color))
        #colors less then faces
        if(len(single_color)!=len(shape1.Faces)):
            applyDiffuse=0;
            #copy color to all faces
        #else copy singolar colors for faces
        else:
            applyDiffuse=1;
            for color in single_color:
                color_vector.append(color)
        #say("color_vector")
        #say(color_vector)
        for index in range(len(shape1.Faces)):
            #say("color x")
            #say(color_vector[indexColor])
            singleFace=shape1.Faces[index]
            if(applyDiffuse):
                #say(color_vector[indexColor])
                meshes.append(shapeToMesh(singleFace, color_vector[indexColor], transparency[i], scale))
            else:
                #say(single_color[0])
                meshes.append(shapeToMesh(singleFace, single_color[0], transparency[i], scale))
            indexColor=indexColor+1
            #meshes.append(shapeToMesh(face, Diffuse_color[i], transparency[i], scale))
        color_vector=[]
        indexColor=0;
        i=i+1            
    exportVRML(meshes, filename)
    return
###

def go_export():
    sel = FreeCADGui.Selection.getSelection()
    if not sel:
        FreeCAD.Console.PrintWarning("Select something first!\n\n")
        msg="export VRML from FreeCAD is a python macro that will export simplified VRML of "
        msg+="a (multi)selected Part or fused Part to VRML optimized to KiCad and compatible with Blender "
        msg+="the size of VRML is much smaller compared to the one exported from FC Gui "
        msg+="and the loading/rendering time is also smaller\n"
        msg+="change mesh deviation to increase quality of VRML"
        say(msg)
    else:
        objs = []
        for obj in sel:
                objs.append(obj)
                #say(obj.Label)
                #say(obj.Name)
        say(fullFilePathName)
        #say(objs)
        export(objs, fullFilePathName, scale=None)
        export(objs, fullFilePathName, 0.3937)
    
doc = FreeCAD.ActiveDocument
if doc!=None:
    fullFilePathName=doc.FileName
    if fullFilePathName=="":
        home = expanduser("~")
        fullFilePathName=home+os.sep+doc.Label+'.FCStd'
        say('path not found, saving to '+fullFilePathName)
        #say(fullFilePathName)
    else:
        fullFilePathName = os.path.dirname(os.path.abspath(fullFilePathName))
        fullFilePathName=fullFilePathName+os.sep+doc.Label+'.FCStd'
        say(fullFilePathName)
    go_export()

Link

La discussione nel forum export VRML from FreeCAD with python for smaller size, KiCad and Blender compatible

La macro inversa, Macro_MeshToPart

Questa pagina è recuperata da https://wiki.freecad.org/Macro_PartToVRML

Tieniti aggiornato!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© The FreeCAD Team. Homepage image credits (top to bottom): ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

Questo progetto è supportato da: , KiCad Services Corp. e altri sponsor

GitHubMigliora questa pagina su GitHub