问题标签 [freecad]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2842 浏览

cad - 无法将 FreeCAD 导入 Python

当我尝试从另一个文件夹中的 Python 文件导入到 FreeCAD 时,我遇到了一个小问题。Python 文件位置:c:/users/workspace/main.py FreeCAD:c:/program files (x86)/FreeCAD0.13/bin

当我尝试使用命令导入时 from FreeCAD import *(我将 FreeCAD 的路径附加到sys sys.path.append (" path-To-FreeCADs-BinFolder " ) 我得到一个错误:

但是当我在 FreeCAD 的文件夹中创建一个 Python 文件时,它可以工作。我的意思是像我上面写的那样导入 FreeCAD。

ps:我的 Python 版本是 2.7.5,而 FreeCAD 是:0.13

0 投票
2 回答
518 浏览

python - FreeCAD 宏中的 Pyqt 表单未保持打开状态

行。所以,我一直试图弄清楚这一点,但我只是卡住了。每次我尝试运行它时,窗口都会立即打开和关闭。我似乎无法弄清楚。请帮忙。

供参考。这是用于创建圆柱体的 FreeCAD 宏。我以前做过其他宏,它们工作得很好。直到我介绍了 PyQt GUI,我才开始遇到麻烦。

0 投票
1 回答
1297 浏览

python - Python:如何以编程方式清除 FreeCAD 中的查看器?

我可以使用 Python 脚本在 FreeCAD 中创建和显示零件,如下所示:

但是,如果我再次运行该脚本,它会在原始文件的顶部覆盖 myPart 的第二个副本。Python 脚本如何在开始绘图之前清除查看器?我可以手动使用 FreeCAD 菜单“全选”,然后“删除”,但我怎样才能自动化它以加快我的工作流程?

0 投票
3 回答
460 浏览

python - 如何访问转换为变量的字符串的名称?

我正在使用 FreeCAD 中的 Python,并向我们使用的对象添加属性(可调变量):

使用 for 循环我想添加具有多个变量名的多个属性。我阅读了如何将字符串转换为变量,但我没有找到如何访问该变量名。就我而言:如何在上面代码中的 .variable 位置使用它。

说我有代码:

例如,我知道我可以使用 print variable0 来获取值 2。如何访问 variable0 的名称并将其放在.variable位置?我读过有关创建变量列表或字典的信息,但是您只能访问变量的值,而不是其名称,对吗?

一个列表可以作为这个对象的输入并且它的内容应该被分配给变量名。输出应如下所示(但不适合任何长度的输入列表):

0 投票
1 回答
118 浏览

python - 使水平集字段适合 CAD 数据

我正在寻找可以将符号距离函数拟合到矢量图像或从 AutoCAD 或 FreeCAD 输出的软件。首选 CAD 数据,因为该输出是 3D。我正在研究用 C 或 Python 编写一些东西,但我想我会检查一下是否有任何东西,因为我无法使用谷歌找到任何东西。

谢谢您的帮助

0 投票
2 回答
91 浏览

python - Method ignored when subclassing a type defined in a C module

I am subclassing a type defined in a C module to alias some attributes and methods so that my script works in different contexts.

How is it that to get this to work, I have to tweak the dictionary of my class manually ? If I don't add a reference to DistanceTo in the dictionnary, I get Point3d has no attribute named DistanceTo.

I was thinking that once __new__ had returned an instance I could still populate it with methods and attributes. Can anyone shed some light on this ?

EDIT : The module I import from is FreeCAD. The C base type is defined there. Then Vector is derived form this definition here

EDIT2 : I also tried the following :

and after creating a second point, both Point3d p returns the value of the last point for p.X, p.Y and p.Z no matter what x,y,z parameters were passed at the creation of the instance. p.x, p.y, p.z return the expected values. It seems to indicate that the dictionary is shared between instances.

EDIT 3 : Problem solved ! The Py_TPFLAGS_BASETYPE bit is set to zero to prevent subclassing as explained in the answer below.

0 投票
3 回答
915 浏览

python - 如何在 Python 中获取切向向量?

我可以从 Arc 获得一些信息。

  • 第一点 [x, y, z]
  • 最后点 [x, y, z]
  • 中心 [x, y, z]
  • axis [x, y, z] # 垂直于平面

如何获得 FirstPoint&LastPoint 的切线方向向量?

我想从两个方向向量中得到一个交点。

我在 FreeCAD 工作。

0 投票
1 回答
1057 浏览

freecad - How to create an arch in FreeCAD for architecture?

I'd like to create an arch in FreeCAD to be used in the architecture module. In OpenSCAD it'd look like this:

Arch in OpenSCAD

Source:

Using the OpenSCAD module is not a solution because I'd like to use the grid snapping features and be able to edit the arch without deleting and recreating it from OpenSCAD source code (which apparently is necessary in FreeCAD).

Searching for solutions with a search engine is impossible because apparently only referring to the architecture module (= Arch) are displayed.

0 投票
0 回答
1698 浏览

python - 在 python 脚本中嵌入 FreeCAD

我正在尝试从 python 脚本运行 FreeCAD 模块。这是我根据本教程编写的用于导入 FreeCAD 模块的代码“(即使我的 HD 上没有安装任何 FreeCAD.dll):

但我收到以下错误:

“ import Part ImportError: No module named Part”

我还尝试了 64 位版本的 FreeCAD

C:\Program Files\FreeCAD 0.16\bin

有什么建议吗?

0 投票
1 回答
98 浏览

python - 更新草图配额并读取模型的尺寸

我有一个草图,两条线之间的角度固定。我还有一个与草图分区相关联的尺寸(来自草稿)。我需要更改草图上的角度并获取尺寸的实际值。我还需要从外部 python 模块(嵌入)

代码是:

输出是:

为什么变量“res”没有改变它的值?如何正确解决此任务?

感谢您的帮助。

freecad 模型在这里:MyModel