CATIA的VBA宏在一台计算机上工作,而在另一台计算机上不工作 [英] VBA macros for CATIA works on one computer, and doesn't work on another

查看:151
本文介绍了CATIA的VBA宏在一台计算机上工作,而在另一台计算机上不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBA中有一个CATIA宏,该宏通过坐标(从数组中)绘制点.它可以在我的计算机上运行(Catia V5-R2014和我的邻居-两个版本V5-R2014和R21).但这不适用于其他城市的大学(它们的版本为R21).基本上,我的宏从文件中读取输入数据,计算坐标,将其写入文件外,然后绘制这些点.除最后一个步骤外,所有步骤均可在任何一台计算机/版本上进行.但是在最后一步,他们"的Catia却什么也没画,没有任何错误.

I have a CATIA macro in VBA, that draws points by coordinates (from arrays). It works on my computer (Catia V5-R2014 and on my neigbours - two versions V5-R2014 and R21). But it doesn't work for colleges in a different city (they have version R21). Basically, my macro reads input data from file, calculates coordinates, writes them in out-file, and then draws these points. All steps except the last one work on either computer/version. But at the last step "their" Catia just doesn't plot anything, w/o any errors.

所以最后一步的Subruotine是:

So the Subruotine for the last step is:

Sub PlotGeometry()
' Nmlp - number of points
Dim i As Integer

Dim oPartDocument As Document
Dim ohSPointCoord() As HybridShapePointCoord
Dim ohSPoints As HybridShapePointCoord
Dim bodies1 As Bodies
Dim body1 As Body

ReDim ohSPointCoord(0 To Nmlp)

Set oPartDocument = CATIA.Documents.Add("Part")
Set oPart = oPartDocument.Part
Set oPartBody = oPart.MainBody
Set oPlaneYZ = oPart.CreateReferenceFromGeometry(oPart.OriginElements.PlaneYZ)
' -- Draw Points
Dim ohSFactory As HybridShapeFactory
Set ohSFactory = oPart.HybridShapeFactory

For i = 0 To Nmlp
    Set ohSPointCoord(i) = ohSFactory.AddNewPointCoord(XM(i), YM(i), ZM(i))
    oPartBody.InsertHybridShape ohSPointCoord(i)
Next i

oPart.Update

End Sub

那会是什么?

推荐答案

也许在您的站点上启用了混合设计,而在其他站点上则没有.

Perhaps at your site you have Hybrid Design enabled, and at the other site they do not.

启用混合设计后,您将可以向实体添加点.如果未启用它,则不是这样,您不会从代码中得到任何错误.

With Hybrid Design enabled, you would be able to add points to a Body. Not so if it is not enabled and you would get no error from your code.

该设置位于工具"->选项"->基础结构"->零件基础结构"->零件文档"选项卡->启用零件主体和主体内部的混合设计"下.

The setting is under Tools->Options->Infrastructure->Part Infrastructure->Part Document Tab->Enable hybrid design inside part bodies and bodies.

由于无法解释的原因,默认启用混合设计.但是,我不建议您使用它.

For unexplained reasons, hybrid design being enabled is the default. However I do not recommend using it.

如果只想使代码在两个地方都能工作,则可以使用几何集"来聚合点而不是主体.

If you just want to make your code work in both places then use a Geometrical Set to aggregate your points instead of the main body.

Dim pointsBody as HybridBody
Set pointsBody = oPart.HybridBodies.Add
pointsBody.Name = "Points_Body"

...

For i = 0 To Nmlp
    Set ohSPointCoord(i) = ohSFactory.AddNewPointCoord(XM(i), YM(i), ZM(i))
    pointsBody.AppendHybridShape ohSPointCoord(i)
Next i

这篇关于CATIA的VBA宏在一台计算机上工作,而在另一台计算机上不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆