Language="VBSCRIPT"
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set bodies1 = part1.Bodies
Set body1 = bodies1.Item("零件几何体")
Set sketches1 = body1.Sketches
Set originElements1 = part1.OriginElements
Set reference1 = originElements1.PlaneXY
Set sketch1 = sketches1.Add(reference1)
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
arrayOfVariantOfDouble1(3) = 1.000000
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 1.000000
arrayOfVariantOfDouble1(8) = 0.000000
sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1
part1.InWorkObject = sketch1
Set factory2D1 = sketch1.OpenEdition()
Set geometricElements1 = sketch1.GeometricElements
Set axis2D1 = geometricElements1.Item("绝对轴")
Set line2D1 = axis2D1.GetItem("横向")
line2D1.ReportName = 1
Set line2D2 = axis2D1.GetItem("纵向")
line2D2.ReportName = 2
Set point2D1 = factory2D1.CreatePoint(30.000000, 30.000000)
point2D1.ReportName = 3
Set point2D2 = factory2D1.CreatePoint(30.000000, -30.000000)
point2D2.ReportName = 4
Set line2D3 = factory2D1.CreateLine(30.000000, 30.000000, 30.000000, -30.000000)
line2D3.ReportName = 5
line2D3.StartPoint = point2D1
line2D3.EndPoint = point2D2
Set point2D3 = factory2D1.CreatePoint(-30.000000, -30.000000)
point2D3.ReportName = 6
Set line2D4 = factory2D1.CreateLine(30.000000, -30.000000, -30.000000, -30.000000)
line2D4.ReportName = 7
line2D4.StartPoint = point2D2
line2D4.EndPoint = point2D3
Set point2D4 = factory2D1.CreatePoint(-30.000000, 30.000000)
point2D4.ReportName = 8
Set line2D5 = factory2D1.CreateLine(-30.000000, -30.000000, -30.000000, 30.000000)
line2D5.ReportName = 9
line2D5.StartPoint = point2D3
line2D5.EndPoint = point2D4
Set line2D6 = factory2D1.CreateLine(-30.000000, 30.000000, 30.000000, 30.000000)
line2D6.ReportName = 10
line2D6.StartPoint = point2D4
line2D6.EndPoint = point2D1
Set constraints1 = sketch1.Constraints
Set reference2 = part1.CreateReferenceFromObject(line2D3)
Set reference3 = part1.CreateReferenceFromObject(line2D2)
Set constraint1 = constraints1.AddBiEltCst(catCstTypeVerticality, reference2, reference3)
constraint1.Mode = catCstModeDrivingDimension
Set reference4 = part1.CreateReferenceFromObject(line2D4)
Set reference5 = part1.CreateReferenceFromObject(line2D1)
Set constraint2 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference4, reference5)
constraint2.Mode = catCstModeDrivingDimension
Set reference6 = part1.CreateReferenceFromObject(line2D5)
Set reference7 = part1.CreateReferenceFromObject(line2D2)
Set constraint3 = constraints1.AddBiEltCst(catCstTypeVerticality, reference6, reference7)
constraint3.Mode = catCstModeDrivingDimension
Set reference8 = part1.CreateReferenceFromObject(line2D6)
Set reference9 = part1.CreateReferenceFromObject(line2D1)
Set constraint4 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference8, reference9)
constraint4.Mode = catCstModeDrivingDimension
Set reference10 = part1.CreateReferenceFromObject(line2D3)
Set reference11 = part1.CreateReferenceFromObject(line2D5)
Set point2D5 = axis2D1.GetItem("原点")
Set reference12 = part1.CreateReferenceFromObject(point2D5)
Set constraint5 = constraints1.AddTriEltCst(catCstTypeEquidistance, reference10, reference11, reference12)
constraint5.Mode = catCstModeDrivingDimension
Set reference13 = part1.CreateReferenceFromObject(line2D4)
Set reference14 = part1.CreateReferenceFromObject(line2D6)
Set reference15 = part1.CreateReferenceFromObject(point2D5)
Set constraint6 = constraints1.AddTriEltCst(catCstTypeEquidistance, reference13, reference14, reference15)
constraint6.Mode = catCstModeDrivingDimension
sketch1.CloseEdition
part1.InWorkObject = sketch1
part1.Update
Set shapeFactory1 = part1.ShapeFactory
Set pad1 = shapeFactory1.AddNewPad(sketch1, 20.000000)
part1.Update
End Sub
依照要更改的需求,可以做成下面這樣,僅供參考:
如果覺得不夠方便,可以把要提取的開頭字串也寫入一個mode.txt中,分別讀取in.txt和mode.txt,輸出的檔名可以叫做out_**.txt。輸出的檔案名稱不能包含空格等非法字符,可以提前過濾掉。