提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
本文主要记录了一些EKL脚本语言的基础代码示例。
一、什么是EKL?
EKL(Enterprise Knowledge Language) 3DEXPERIENCE中提供的基础脚本语言。
▪主要是作为一种胶水语言,将CATIA 提供的各种知识工程的接口“粘合”在一起。通过简单的语法提供基础的编程的功能。
二、练习案例
1.创建物理产品和3D Part
代码如下:
let productRef(VPMReference)
productRef = new("VPMReference","myProductRef",NULL)
let productIns(VPMInstance)
productIns = new("VPMInstance","myProductIns",rootProduct,productRef)
Let createdInstance1(VPMInstance)
createdInstance1 = new("3DPart", "MyNewRef3DPart",productRef)
2.遍历查询
代码如下:
Let childrenList1,childrenList2,childrenList3,childrenList4,childrenList5(List)
childrenList1 = ProductOcc.Children
//Message("No of Children = ", childrenList1.Size())
Notify("list",childrenList1)
childrenList2=ProductOcc.Reference.Query("AdvisorAction","")
Notify("list",childrenList2)
childrenList3=ProductOcc.Reference.Query("VPMReference","")
Notify("list",childrenList3)
childrenList4=ProductOcc.Query("ProductOccurrence","x.Name==\"MyNewRef3DPart.2\"")
Notify("list",childrenList4)
childrenList5=ProductOcc.Query("ProductOccurrence","x.Name like\"*MyNewRef3DPart*\"")
Notify("list",childrenList5)
3.创建几何图形集
代码如下:(这里有一个问题,3D Shape的节点是PartFeature类型,但是选择的时候却不能选择3D Shape节点,而是选择了其下面的特征节点)
let createdOpenBodyFeature(OpenBodyFeature)
let Body1(BodyFeature)
createdOpenBodyFeature=new("OpenBodyFeature","几何图形集",parentRepInstance)
Body1=new("BodyFeature","立柱",parentRepInstance,"")
4.文件交互
1、读写excel文件,使用CreateSheet()来打开Excel,如果想要打开具体的页,就用CreateSheet([strFileName]SheetNumber),想要写入Excel,要用SetCell(),读取用CellAsBoolean()、CellAsString()、CellAsReal()。但是要注意,SetCell()的行数计数是从1开始的,而CellAsString()这些都是从0开始计数的。
Let strFileName(String)
Let oXLSheet(DTSheetType)
Let indx(Integer)
Let noOfRows(Integer)
Let strColorName(String)
Let rValue(Real)
Let gValue(Real)
Let bValue(Real)
Let strRowValue(String)
strFileName = "C:\\Users\\Atz\\Desktop\\input.xlsx"
Set oXLSheet = CreateSheet(strFileName)
noOfRows = oXLSheet.RowsNb//获取行数
indx = 1
oXLSheet.SetCell(6,2,666)
Notify(oXLSheet.CellAsString(5, 2))
For indx while indx < noOfRows
{
strColorName = oXLSheet.CellAsString(indx, 1)
rValue = oXLSheet.CellAsReal(indx, 2)
gValue = oXLSheet.CellAsReal(indx, 3)
bValue = oXLSheet.CellAsReal(indx, 4)
Notify(strColorName," ",rValue," ",gValue," ",bValue)
}
2、读写txt文件,OpenTextFile的时候,"r"表示读,"w"表示写,"a"表示在结尾往后写,
Let file (TextFile)
Let buffer (String)
Set file = OpenTextFile("C:\\Users\\Atz\\Desktop\\input.txt","r")
buffer = file->Read()
Set file = OpenTextFile("C:\\Users\\Atz\\Desktop\\input2.txt","a")
file->Write(buffer)
file->Close()