当前位置:首页 > 实用技巧 >

cad约束怎么调出来(cad怎么自带约束了)

来源:原点资讯(www.yd166.com)时间:2023-04-16 18:09:24作者:YD166手机阅读>>

本教程介绍在CadQuery中如何使用装配约束功能来构建逼真的模型,我们将组装一个由 20x20 V 型槽型材制成的门组件。

cad约束怎么调出来,cad怎么自带约束了(1)

1、定义参数

我们希望从定义模型参数开始,以便以后可以轻松更改尺寸:

import cadquery as cq # Parameters H = 400 W = 200 D = 350 PROFILE = cq.importers.importDXF("vslot-2020_1.DXF").wires() SLOT_D = 5 PANEL_T = 3 HANDLE_D = 20 HANDLE_L = 50 HANDLE_W = 4

值得注意的是,v 槽轮廓是从 DXF 文件导入的。 这样就很容易更换为其他铝型材,例如博世或其他供应商提供的 DXF 文件。

2、定义可重用组件

接下来我们要定义根据指定参数生成装配组件的函数。

def make_vslot(l): return PROFILE.toPending().extrude(l) def make_connector(): rv = ( cq.Workplane() .box(20, 20, 20) .faces("<X") .workplane() .cboreHole(6, 15, 18) .faces("<Z") .workplane(centerOption="CenterOfMass") .cboreHole(6, 15, 18) ) # tag mating faces rv.faces(">X").tag("X").end() rv.faces(">Z").tag("Z").end() return rv def make_panel(w, h, t, cutout): rv = ( cq.Workplane("XZ") .rect(w, h) .extrude(t) .faces(">Y") .vertices() .rect(2*cutout,2*cutout) .cutThruAll() .faces("<Y") .workplane() .pushPoints([(-w / 3, HANDLE_L / 2), (-w / 3, -HANDLE_L / 2)]) .hole(3) ) # tag mating edges rv.faces(">Y").edges("%CIRCLE").edges(">Z").tag("hole1") rv.faces(">Y").edges("%CIRCLE").edges("<Z").tag("hole2") return rv def make_handle(w, h, r): pts = ((0, 0), (w, 0), (w, h), (0, h)) path = cq.Workplane().polyline(pts) rv = ( cq.Workplane("YZ") .rect(r, r) .sweep(path, transition="round") .tag("solid") .faces("<X") .workplane() .faces("<X", tag="solid") .hole(r / 1.5) ) # tag mating faces rv.faces("<X").faces(">Y").tag("mate1") rv.faces("<X").faces("<Y").tag("mate2") return rv3、初始装配

接下来我们要实例化所有组件并将它们添加到组件中。

# define the elements door = ( cq.Assembly() .add(make_vslot(H), name="left") .add(make_vslot(H), name="right") .add(make_vslot(W), name="top") .add(make_vslot(W), name="bottom") .add(make_connector(), name="con_tl", color=cq.Color("black")) .add(make_connector(), name="con_tr", color=cq.Color("black")) .add(make_connector(), name="con_bl", color=cq.Color("black")) .add(make_connector(), name="con_br", color=cq.Color("black")) .add( make_panel(W SLOT_D, H SLOT_D, PANEL_T, SLOT_D), name="panel", color=cq.Color(0, 0, 1, 0.2), ) .add( make_handle(HANDLE_D, HANDLE_L, HANDLE_W), name="handle", color=cq.Color("yellow"), ) )4、约束定义

然后我们要定义所有的约束:

# define the constraints ( door # left profile .constrain("left@faces@<Z", "con_bl?Z", "Plane") .constrain("left@faces@<X", "con_bl?X", "Axis") .constrain("left@faces@>Z", "con_tl?Z", "Plane") .constrain("left@faces@<X", "con_tl?X", "Axis") # top .constrain("top@faces@<Z", "con_tl?X", "Plane") .constrain("top@faces@<Y", "con_tl@faces@>Y", "Axis") # bottom .constrain("bottom@faces@<Y", "con_bl@faces@>Y", "Axis") .constrain("bottom@faces@>Z", "con_bl?X", "Plane") # right connectors .constrain("top@faces@>Z", "con_tr@faces@>X", "Plane") .constrain("bottom@faces@<Z", "con_br@faces@>X", "Plane") .constrain("left@faces@>Z", "con_tr?Z", "Axis") .constrain("left@faces@<Z", "con_br?Z", "Axis") # right profile .constrain("right@faces@>Z", "con_tr@faces@>Z", "Plane") .constrain("right@faces@<X", "left@faces@<X", "Axis") # panel .constrain("left@faces@>X[-4]", "panel@faces@<X", "Plane") .constrain("left@faces@>Z", "panel@faces@>Z", "Axis") # handle .constrain("panel?hole1", "handle?mate1", "Plane") .constrain("panel?hole2", "handle?mate2", "Point") )

如果你需要做一些基于字符串的选择器不可能做的不寻常的事情,例如使用 cadquery.selectors.BoxSelector 或用户定义的选择器类,可以直接将 cadquery.Shape 对象传递给 cadquery.Assembly.constrain( ) 方法。 例如,上面的

.constrain('part1@faces@>Z','part3@faces@<Z','Axis')

等效于:

.constrain('part1',part1.faces('>z').val(),'part3',part3.faces('<Z').val(),'Axis')

此方法需要一个 cadquery.Shape 对象,因此请记住使用 cadquery.Workplane.val() 方法传递单个 cadquery.Shape 而不是整个 cadquery.Workplane 对象。

5、最终结果

下面是完整的代码,包括最后的求解步骤。

cad约束怎么调出来,cad怎么自带约束了(2)

import cadquery as cq # Parameters H = 400 W = 200 D = 350 PROFILE = cq.importers.importDXF("vslot-2020_1.dxf").wires() SLOT_D = 6 PANEL_T = 3 HANDLE_D = 20 HANDLE_L = 50 HANDLE_W = 4 def make_vslot(l): return PROFILE.toPending().extrude(l) def make_connector(): rv = ( cq.Workplane() .box(20, 20, 20) .faces("<X") .workplane() .cboreHole(6, 15, 18) .faces("<Z") .workplane(centerOption="CenterOfMass") .cboreHole(6, 15, 18) ) # tag mating faces rv.faces(">X").tag("X").end() rv.faces(">Z").tag("Z").end() return rv def make_panel(w, h, t, cutout): rv = ( cq.Workplane("XZ") .rect(w, h) .extrude(t) .faces(">Y") .vertices() .rect(2*cutout,2*cutout) .cutThruAll() .faces("<Y") .workplane() .pushPoints([(-w / 3, HANDLE_L / 2), (-w / 3, -HANDLE_L / 2)]) .hole(3) ) # tag mating edges rv.faces(">Y").edges("%CIRCLE").edges(">Z").tag("hole1") rv.faces(">Y").edges("%CIRCLE").edges("<Z").tag("hole2") return rv def make_handle(w, h, r): pts = ((0, 0), (w, 0), (w, h), (0, h)) path = cq.Workplane().polyline(pts) rv = ( cq.Workplane("YZ") .rect(r, r) .sweep(path, transition="round") .tag("solid") .faces("<X") .workplane() .faces("<X", tag="solid") .hole(r / 1.5) ) # tag mating faces rv.faces("<X").faces(">Y").tag("mate1") rv.faces("<X").faces("<Y").tag("mate2") return rv # define the elements door = ( cq.Assembly() .add(make_vslot(H), name="left") .add(make_vslot(H), name="right") .add(make_vslot(W), name="top") .add(make_vslot(W), name="bottom") .add(make_connector(), name="con_tl", color=cq.Color("black")) .add(make_connector(), name="con_tr", color=cq.Color("black")) .add(make_connector(), name="con_bl", color=cq.Color("black")) .add(make_connector(), name="con_br", color=cq.Color("black")) .add( make_panel(W 2*SLOT_D, H 2*SLOT_D, PANEL_T, SLOT_D), name="panel", color=cq.Color(0, 0, 1, 0.2), ) .add( make_handle(HANDLE_D, HANDLE_L, HANDLE_W), name="handle", color=cq.Color("yellow"), ) ) # define the constraints ( door # left profile .constrain("left@faces@<Z", "con_bl?Z", "Plane") .constrain("left@faces@<X", "con_bl?X", "Axis") .constrain("left@faces@>Z", "con_tl?Z", "Plane") .constrain("left@faces@<X", "con_tl?X", "Axis") # top .constrain("top@faces@<Z", "con_tl?X", "Plane") .constrain("top@faces@<Y", "con_tl@faces@>Y", "Axis") # bottom .constrain("bottom@faces@<Y", "con_bl@faces@>Y", "Axis") .constrain("bottom@faces@>Z", "con_bl?X", "Plane") # right connectors .constrain("top@faces@>Z", "con_tr@faces@>X", "Plane") .constrain("bottom@faces@<Z", "con_br@faces@>X", "Plane") .constrain("left@faces@>Z", "con_tr?Z", "Axis") .constrain("left@faces@<Z", "con_br?Z", "Axis") # right profile .constrain("right@faces@>Z", "con_tr@faces@>Z", "Plane") .constrain("right@faces@<X", "left@faces@<X", "Axis") # panel .constrain("left@faces@>X[-4]", "panel@faces@<X", "Plane") .constrain("left@faces@>Z", "panel@faces@>Z", "Axis") # handle .constrain("panel?hole1", "handle?mate1", "Plane") .constrain("panel?hole2", "handle?mate2", "Point") ) # solve door.solve() show_object(door,name='door')6、数据导出

生成的程序集可以导出为 STEP 文件或内部 OCCT XML 格式。

STEP 可以加载到所有 CAD 工具中,例如在 FreeCAD 中,XML 可用于其他使用 OCCT 的应用程序。

door.save('door.step') door.save('door.xml')

当保存为STEP格式时,颜色被保留但不透明。

cad约束怎么调出来,cad怎么自带约束了(3)

7、对象位置

可以将对象添加到具有提供的初始位置的装配中,例如:

cad约束怎么调出来,cad怎么自带约束了(4)

栏目热文

cad约束有什么用(cad约束在哪里设置)

cad约束有什么用(cad约束在哪里设置)

CAD也疯狂约束,顾名思义就是给它一些限制条件或者控制条件来限制控制它。就拿标注约束来说,你添加标注约束之后,改变标注的...

2023-04-16 18:05:28查看全文 >>

cad自动约束快捷键(cad参数化自动约束怎么用)

cad自动约束快捷键(cad参数化自动约束怎么用)

在CAD软件中的几何约束功能我们已经讲到了第四期,前面的命令大家都会了吗?接下来我们要使用CAD制图软件继续讲解CAD几...

2023-04-16 18:09:30查看全文 >>

cad里面如何打开约束(cad怎么自带约束了)

cad里面如何打开约束(cad怎么自带约束了)

上一期我们讲了在CAD软件中的几何约束功能的前面四个命令的使用教程讲解,这一期我们接着讲后面两个命令怎么使用吧!后面两个...

2023-04-16 17:42:42查看全文 >>

cad约束图解(cad最佳约束方法)

cad约束图解(cad最佳约束方法)

在CAD软件中,我们的新手小伙伴会看到有一个几何约束功能,但是并不知道是什么意思,也不知道是怎么使用的。今天我们就来讲一...

2023-04-16 18:22:00查看全文 >>

cad约束的正确方法(cad约束垂直使用方法)

cad约束的正确方法(cad约束垂直使用方法)

一、分析与说明1.1、约束方法会用到“几何约束”和“标注约束”。1.2、会尽可能详尽地写出绘制步骤,希望你看了我的讲解之...

2023-04-16 18:02:56查看全文 >>

cad约束说明什么(cad的约束是怎么产生的)

cad约束说明什么(cad的约束是怎么产生的)

约束的作用可以使你单独移动一个夹点时,整个线条依旧按设定的角度整体移动,使得线条不会出现偏斜。1、在CAD经典模式中可以...

2023-04-16 18:01:25查看全文 >>

怎么判断一个人艾滋病(正常人怎么知道自己得了艾滋病)

怎么判断一个人艾滋病(正常人怎么知道自己得了艾滋病)

众所周知,艾滋病病毒是异常可怕的病毒,它是由人免疫缺陷病毒,也就是HIV引起的一种获得性免疫缺陷综合症。HIV感染人体以...

2023-04-16 17:49:05查看全文 >>

女人得了艾滋病有什么症状(女性有艾滋病有哪些症状)

女人得了艾滋病有什么症状(女性有艾滋病有哪些症状)

艾滋病是由于HIV病毒感染造成的,这种病毒进入人体之后,可攻击人体的免疫系统,导致人体免疫力越来越低,最终患上各种各样的...

2023-04-16 18:07:55查看全文 >>

3个艾滋病潜伏期表现(艾滋病潜伏期是什么表现)

3个艾滋病潜伏期表现(艾滋病潜伏期是什么表现)

谈癌色变是很常见的,各类癌症在近几年的发展是有目共睹的,其对人体的伤害威力也是无比强大的。但是,除了癌症,艾滋病也是很令...

2023-04-16 17:47:27查看全文 >>

男人得了艾滋病的症状(男人得艾滋病有什么症状)

男人得了艾滋病的症状(男人得艾滋病有什么症状)

艾滋病,又称为获得性免疫缺陷综合征,是由于机体感染人类免疫缺陷病毒,亦称艾滋病病毒,而引发的全身性疾病。艾滋病病毒感染可...

2023-04-16 18:20:01查看全文 >>

文档排行