一直以来,我们都是先通过anaconda安装pythonocc,然后在通过运行pycharm设置开发环境的方式来运行pythonocc的程序。但是我最近发现了pycharm也是通过设置环境变量以使得pythonocc程序得以运行。后来我观察出来他们是设置以下几个环境变量,于是我把他们写成了bat,通过此方法来运行pythonocc,结果肯定是成功的下面我将把过程和内容告诉大家。
需要设置的环境变量如下所示

C:\Users\Administrator\Anaconda3\envs\3Dsource;
C:\Users\Administrator\Anaconda3\envs\3Dsource\Library\mingw-w64\bin;
C:\Users\Administrator\Anaconda3\envs\3Dsource\Library\usr\bin;
C:\Users\Administrator\Anaconda3\envs\3Dsource\Library\bin;
C:\Users\Administrator\Anaconda3\envs\3Dsource\Scripts;
C:\Users\Administrator\Anaconda3\envs\3Dsource\bin;
C:\Users\Administrator\Anaconda3\condabin;

运行过程如下所述:

1.新建一个记事本取名为init.bat 里面内容如下

@echo off
cd /d %~dp0
rem 你自己安装anaconda目录来写
set path=C:\Users\Administrator\Anaconda3\envs
rem 你的pythonocc安装环境的名称
set parameter0=3Dsourceset parameter1=\Library\mingw-w64\bin
set parameter2=\Library\usr\bin
set parameter3=\Library\bin
set parameter4=\Scripts
set parameter5=\bin
set parameter6=\Lib\site-packages\PyQt5\Qt5\plugins\platformsset path0=%path%%parameter0%
set path1=%path0%%parameter1%
set path2=%path0%%parameter2%
set path3=%path0%%parameter3%
set path4=%path0%%parameter4%
set path5=%path0%%parameter5%
set path6=%path0%%parameter6%set PATH=%PATH%;%path0%
set PATH=%PATH%;%path1%
set PATH=%PATH%;%path2%
set PATH=%PATH%;%path3%
set PATH=%PATH%;%path4%
set PATH=%PATH%;%path5%
set QT_QPA_PLATFORM_PLUGIN_PATH=%path6%echo %PATH%python core_classic_occ_bottle.py

2.新建一个记事本取名为start.bat 里面内容如下

start init.bat

3.start.bat所在文件夹下 新建一个名字为core_classic_occ_bottle.py的python文件 其内容如下

#!/usr/bin/env python##Copyright 2009-2015 Thomas Paviot (tpaviot@gmail.com)
##
##This file is part of pythonOCC.
##
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC 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 Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.import mathfrom OCC.Core.gp import (gp_Pnt, gp_OX, gp_Vec, gp_Trsf, gp_DZ, gp_Ax2, gp_Ax3,gp_Pnt2d, gp_Dir2d, gp_Ax2d, gp_Pln)
from OCC.Core.GC import GC_MakeArcOfCircle, GC_MakeSegment
from OCC.Core.GCE2d import GCE2d_MakeSegment
from OCC.Core.Geom import Geom_CylindricalSurface
from OCC.Core.Geom2d import Geom2d_Ellipse, Geom2d_TrimmedCurve
from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire,BRepBuilderAPI_MakeFace, BRepBuilderAPI_Transform)
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism, BRepPrimAPI_MakeCylinder
from OCC.Core.BRepFilletAPI import BRepFilletAPI_MakeFillet
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeThickSolid, BRepOffsetAPI_ThruSections
from OCC.Core.BRepLib import breplib
from OCC.Core.BRep import BRep_Builder
from OCC.Core.GeomAbs import GeomAbs_Plane
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface
from OCC.Core.TopoDS import topods, TopoDS_Compound, TopoDS_Face
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_EDGE, TopAbs_FACE
from OCC.Core.TopTools import TopTools_ListOfShapedef face_is_plane(face: TopoDS_Face) -> bool:"""Returns True if the TopoDS_Face is a plane, False otherwise"""surf = BRepAdaptor_Surface(face, True)surf_type = surf.GetType()return surf_type == GeomAbs_Planedef geom_plane_from_face(aFace: TopoDS_Face) -> gp_Pln:"""Returns the geometric plane entity from a planar surface"""return BRepAdaptor_Surface(aFace, True).Plane()height = 70
width = 50
thickness = 30print("creating bottle")
# The points we'll use to create the profile of the bottle's body
aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
aPnt5 = gp_Pnt(width / 2.0, 0, 0)aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
aSegment2 = GC_MakeSegment(aPnt4, aPnt5)# Could also construct the line edges directly using the points instead of the resulting line
aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())# Create a wire out of the edges
aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())# Quick way to specify the X axis
xAxis = gp_OX()# Set up the mirror
aTrsf = gp_Trsf()
aTrsf.SetMirror(xAxis)# Apply the mirror transformation
aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf)# Get the mirrored shape back out of the transformation and convert back to a wire
aMirroredShape = aBRespTrsf.Shape()# A wire instead of a generic shape now
aMirroredWire = topods.Wire(aMirroredShape)# Combine the two constituent wires
mkWire = BRepBuilderAPI_MakeWire()
mkWire.Add(aWire.Wire())
mkWire.Add(aMirroredWire)
myWireProfile = mkWire.Wire()# The face that we'll sweep to make the prism
myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)# We want to sweep the face along the Z axis to the height
aPrismVec = gp_Vec(0, 0, height)
myBody_step1 = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec)# Add fillets to all edges through the explorer
mkFillet = BRepFilletAPI_MakeFillet(myBody_step1.Shape())
anEdgeExplorer = TopExp_Explorer(myBody_step1.Shape(), TopAbs_EDGE)while anEdgeExplorer.More():anEdge = topods.Edge(anEdgeExplorer.Current())mkFillet.Add(thickness / 12.0, anEdge)anEdgeExplorer.Next()# Create the neck of the bottle
neckLocation = gp_Pnt(0, 0, height)
neckAxis = gp_DZ()
neckAx2 = gp_Ax2(neckLocation, neckAxis)myNeckRadius = thickness / 4.0
myNeckHeight = height / 10.0mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)myBody_step2 = BRepAlgoAPI_Fuse(mkFillet.Shape(), mkCylinder.Shape())# Our goal is to find the highest Z face and remove it
zMax = -1.# We have to work our way through all the faces to find the highest Z face so we can remove it for the shell
aFaceExplorer = TopExp_Explorer(myBody_step2.Shape(), TopAbs_FACE)
while aFaceExplorer.More():aFace = topods.Face(aFaceExplorer.Current())if face_is_plane(aFace):aPlane = geom_plane_from_face(aFace)# We want the highest Z face, so compare this to the previous facesaPntLoc = aPlane.Location()aZ = aPntLoc.Z()if aZ > zMax:zMax = aZaFaceExplorer.Next()facesToRemove = TopTools_ListOfShape()
facesToRemove.Append(aFace)myBody_step3 = BRepOffsetAPI_MakeThickSolid(myBody_step2.Shape(), facesToRemove, -thickness / 50.0, 0.001)# Set up our surfaces for the threading on the neck
neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)# Set up the curves for the threads on the bottle's neck
aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
anAx2d = gp_Ax2d(aPnt, aDir)aMajor = 2.0 * math.pi
aMinor = myNeckHeight / 10.0anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)anEllipsePnt1 = anEllipse1.Value(0)
anEllipsePnt2 = anEllipse1.Value(math.pi)aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)# Build edges and wires for threading
anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1)
anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1)
anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2)
anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2)threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(), anEdge2OnSurf1.Edge())
threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(), anEdge2OnSurf2.Edge())# Compute the 3D representations of the edges/wires
breplib.BuildCurves3d(threadingWire1.Shape())
breplib.BuildCurves3d(threadingWire2.Shape())# Create the surfaces of the threading
aTool = BRepOffsetAPI_ThruSections(True)
aTool.AddWire(threadingWire1.Wire())
aTool.AddWire(threadingWire2.Wire())
aTool.CheckCompatibility(False)
myThreading = aTool.Shape()# Build the resulting compound
bottle = TopoDS_Compound()
aBuilder = BRep_Builder()
aBuilder.MakeCompound(bottle)
aBuilder.Add(bottle, myBody_step3.Shape())
aBuilder.Add(bottle, myThreading)
print("bottle finished")if __name__ == "__main__":from OCC.Display.SimpleGui import init_displaydisplay, start_display, add_menu, add_function_to_menu = init_display()display.DisplayShape(bottle, update=True)start_display()

4.最后双击start.bat 就会出现如下画面

最后祝你们成功!

通过bat设置环境变量的方式运行pythonocc程序相关推荐

  1. java 代码里设置环境变量_如何在一个java程序里设置环境变量

    展开全部 环境变量是一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如path,当要62616964757a686964616fe4b893e5b19e313333613064 ...

  2. 在linux上,为什么不用配置环境变量还能运行java程序呢?

    问题描述: 我现在想升级pre环境的java版本,打开/etc/profile没有找到配置的JAVA_HOME,又查看了.bashrc文件,也没有配置.但是运行java -version,可以显示版本 ...

  3. Linux下设置时区(通过shell设置和程序中设置)及程序中设置环境变量

    Shell中设置 bash中   export TZ="Europe/Moscow"        date -u -s "2011-10-29 21:55:00&quo ...

  4. Kettle中设置环境变量的几种方式

    下面是设置环境变量的四种方式: 1.设置变量步骤 2. 通过属性文件(常用) 在C:\Users${userName}.kettle\kettle.properties 中添加变量(key=value ...

  5. Win10设置环境变量的5种方式,在哪打开? 如何打开?

    本文目录 前言 一.运行 - 从系统属性入手 二.运行 - 直接打开 三.搜索 - env 四.我的电脑右键-属性,打开设置 五.控制面板-搜索env 前言 本文主要介绍:Win10设置环境变量的5种 ...

  6. Python 标准库之 os (获取当前目录、读取/设置环境变量、重命名文件、运行shell命令、创建/删除/查看目录文件、判断目录/文件/存在、获取绝对路径、获取文件名、获取换行符、获取路径分隔符)

    1. os与sys模块的官方解释如下: os This module provides a portable way of using operating system dependent funct ...

  7. 在package.json里面的script设置环境变量,区分开发及生产环境。注意mac与windows的设置方式不一样...

    在package.json里面的script设置环境变量,区分开发及生产环境. 注意mac与windows的设置方式不一样. "scripts": {"publish-m ...

  8. 【转】Postman系列四:Postman接口请求设置环境变量和全局变量、测试沙箱和测试断言、测试集运行与导入数据文件

    一:Postman中接口请求设置环境变量和全局变量 全局变量和环境变量可以通过Pre-request Script和Tests设置,会在下面测试沙箱和测试断言中讲到. 全局变量的设置:官网参考http ...

  9. linux中csh怎么运行,bash csh 设置环境变量 方法例子

    1.对于csh: 命令:setenv FILTERS FILTERBIN.RES 2.对于bash: export FILTERS=FILTERBIN.RES 注意:若是长久使用,请把以上内容写进 ~ ...

最新文章

  1. html的body内标签之input系列1
  2. navicat保存查询语句_MySQL数据库安装创建及Navicat客户端连接
  3. Redis 新特性篇:100% 掌握多线程模型
  4. pr抖动插件_2020最全的8000多款PR插件合集,一键安装
  5. 通俗理解数字签名,ssl数字证书和https
  6. 深夜,在这个已不再喧嚣的城市中寻找到一片属于自己的宁静,仰望那片属于自己的星空……...
  7. 我的世界服务器名称被占用,为什么我的世界服务器说此用户名已被注册我都换了很多用户了都没用 爱问知识人...
  8. Python入门--Os.path模块常用函数
  9. 给大家带来点福利 整理了一些学习网站,问答网站,和IT咨询网站
  10. Aria2Android 免root,安卓不需root用aria2搭建NAS方法
  11. Elementary OS 修改Home目录下的中文目录为英文目录
  12. 【工具篇】AS连接不上夜神模拟器
  13. android 剪贴板增强工具,ClipX - 超级实用的小巧剪贴板增强工具
  14. 澳洲的10种房屋类型
  15. 计算机时代前的发明,假如1万人回到150万年前,只带简单工具,多久才能制造出计算机?...
  16. Linkedin领英如何批量撤回邀请
  17. nrf52+RFX2401的PA+LNA方案,基于softdevice驱动
  18. @Java web程序员,在保留现场,服务不重启的情况下,执行我们的调试代码(JSP 方式)
  19. CAE(Convolutional Auto-Encode) 卷积自编码
  20. Github项目文档的管理

热门文章

  1. 五险一金后5千的月均工资,在长沙处于什么水平?
  2. 共识算法之Pow工作量证明算法go语言实现
  3. Python+OpenCV图像处理(四)—— 色彩空间
  4. odoo 图标大小调整
  5. 手机手写输入法如果支持词组输入将会大幅度提高录入效率
  6. T4M插件放入unity后怎么找不到_【Unity俯视角射击】我们来做一个《元气骑士》的完整Demo(五)...
  7. pytest自动化测试用例管理,常用功能简介
  8. 为什么你没时间研究一下LED节能灯?五分钟带你暴力拆解!
  9. python 连续不等式_python 连续不等式语法糖实例
  10. SCCM部署(二)---AD服务器配置