关于CATIA V5二次开发中实体“体积”测量的宏问题

来源:互联网 发布:查看淘宝店铺排名 编辑:程序博客网 时间:2024/06/18 06:41

尊重原创,转载请注明出处! mansin_csa@163.com

实际上,CATIA在很多情况下并不能成功录制宏,比如,在自由曲面设计模块中,所有功能均不能录制宏。还有在测量功能中也不能录制宏。事实上,查阅V5Automation知道,其实是有关于测量功能的方法的。如下图所示:

这里写图片描述

在Measurable中就可以通过Volume方法来获得目标的体积。在实际编程中,还是需要很多前提才能成功使用该功能的。
【特别注意】:在CATIA GUI中是可以通过在“选项”中更改测量单位的。但在宏程序中所获得的体积的单位是m^3。
以下给出一个测量一个拟柱体体积的完整的宏程序。

Sub CATMain()Set documents1 = CATIA.DocumentsSet partDocument1 = documents1.Add("Part")Set part1 = partDocument1.PartSet bodies1 = part1.BodiesSet body1 = bodies1.Item("零件几何体")Set sketches1 = body1.SketchesSet originElements1 = part1.OriginElementsSet reference1 = originElements1.PlaneZXSet sketch1 = sketches1.Add(reference1)Dim arrayOfVariantOfDouble1(8)arrayOfVariantOfDouble1(0) = 0.000000arrayOfVariantOfDouble1(1) = 0.000000arrayOfVariantOfDouble1(2) = 0.000000arrayOfVariantOfDouble1(3) = -1.000000arrayOfVariantOfDouble1(4) = 0.000000arrayOfVariantOfDouble1(5) = 0.000000arrayOfVariantOfDouble1(6) = 0.000000arrayOfVariantOfDouble1(7) = -0.000000arrayOfVariantOfDouble1(8) = 1.000000sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1part1.InWorkObject = sketch1Set factory2D1 = sketch1.OpenEdition()Set geometricElements1 = sketch1.GeometricElementsSet axis2D1 = geometricElements1.Item("绝对轴")Set line2D1 = axis2D1.GetItem("横向")line2D1.ReportName = 1Set line2D2 = axis2D1.GetItem("纵向")line2D2.ReportName = 2Set ellipse2D1 = factory2D1.CreateClosedEllipse(0.000000, 0.000000, 100.000000, 0.000000, 100.000000, 30.000000)Set point2D1 = axis2D1.GetItem("原点")ellipse2D1.CenterPoint = point2D1ellipse2D1.ReportName = 3Set point2D2 = factory2D1.CreatePoint(0.000000, 30.000000)point2D2.ReportName = 4Set constraints1 = sketch1.ConstraintsSet reference2 = part1.CreateReferenceFromObject(point2D2)Set reference3 = part1.CreateReferenceFromObject(line2D2)Set constraint1 = constraints1.AddBiEltCst(catCstTypeOn, reference2, reference3)constraint1.Mode = catCstModeDrivingDimensionSet reference4 = part1.CreateReferenceFromObject(ellipse2D1)Set reference5 = part1.CreateReferenceFromObject(point2D2)Set constraint2 = constraints1.AddBiEltCst(catCstTypeOn, reference4, reference5)constraint2.Mode = catCstModeDrivingDimensionsketch1.CloseEdition part1.InWorkObject = sketch1part1.UpdateObject sketch1Set hybridShapeFactory1 = part1.HybridShapeFactorySet hybridShapePlaneExplicit1 = originElements1.PlaneZXSet reference6 = part1.CreateReferenceFromObject(hybridShapePlaneExplicit1)Set hybridShapePlaneOffset1 = hybridShapeFactory1.AddNewPlaneOffset(reference6, 20.000000, False)body1.InsertHybridShape hybridShapePlaneOffset1part1.InWorkObject = hybridShapePlaneOffset1part1.Update Set hybridShapes1 = body1.HybridShapesSet reference7 = hybridShapes1.Item("平面.1")Set sketch2 = sketches1.Add(reference7)Dim arrayOfVariantOfDouble2(8)arrayOfVariantOfDouble2(0) = 0.000000arrayOfVariantOfDouble2(1) = 20.000000arrayOfVariantOfDouble2(2) = 0.000000arrayOfVariantOfDouble2(3) = -1.000000arrayOfVariantOfDouble2(4) = 0.000000arrayOfVariantOfDouble2(5) = 0.000000arrayOfVariantOfDouble2(6) = 0.000000arrayOfVariantOfDouble2(7) = -0.000000arrayOfVariantOfDouble2(8) = 1.000000sketch2.SetAbsoluteAxisData arrayOfVariantOfDouble2part1.InWorkObject = sketch2Set factory2D2 = sketch2.OpenEdition()Set geometricElements2 = sketch2.GeometricElementsSet axis2D2 = geometricElements2.Item("绝对轴")Set line2D3 = axis2D2.GetItem("横向")line2D3.ReportName = 1Set line2D4 = axis2D2.GetItem("纵向")line2D4.ReportName = 2Set ellipse2D2 = factory2D2.CreateClosedEllipse(0.000000, 0.000000, 100.000000, 30.000000, 104.403065, 22.044853)Set point2D3 = axis2D2.GetItem("原点")ellipse2D2.CenterPoint = point2D3ellipse2D2.ReportName = 3sketch2.CloseEdition part1.InWorkObject = sketch2part1.UpdateObject sketch2Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 2.000000, 3.000000)Set reference8 = part1.CreateReferenceFromObject(sketch1)Set hybridShapeExtremum1 = hybridShapeFactory1.AddNewExtremum(reference8, hybridShapeDirection1, 1)body1.InsertHybridShape hybridShapeExtremum1part1.InWorkObject = hybridShapeExtremum1part1.Update Set hybridShapeDirection2 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 2.000000, 3.000000)Set reference9 = part1.CreateReferenceFromObject(sketch2)Set hybridShapeExtremum2 = hybridShapeFactory1.AddNewExtremum(reference9, hybridShapeDirection2, 1)body1.InsertHybridShape hybridShapeExtremum2part1.InWorkObject = hybridShapeExtremum2part1.Update Set shapeFactory1 = part1.ShapeFactorySet loft1 = shapeFactory1.AddNewLoft()Set hybridShapeLoft1 = loft1.HybridShapehybridShapeLoft1.SectionCoupling = 3hybridShapeLoft1.Relimitation = 1hybridShapeLoft1.CanonicalDetection = 2Set reference10 = part1.CreateReferenceFromObject(sketch1)hybridShapeLoft1.AddSectionToLoft reference10, 1, NothingSet reference11 = part1.CreateReferenceFromObject(sketch2)hybridShapeLoft1.AddSectionToLoft reference11, 1, Nothingpart1.InWorkObject = hybridShapeLoft1part1.Update set reference26=hybridShapes1.Item("多截面实体.1")Set TheSPAWorkbench=CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")Set TheMeasurable=TheSPAWorkbench.GetMeasurable(reference26) AVolume = TheMeasurable.VolumeEnd Sub

这里写图片描述

【说明】:
(1)上面的程序通过AVolume变量获得了体积值,如果需要在CATIA中显示出来,则需要借助Msgbox。在Visual Basic编程中,可以传递给相关变量。
(2)如果通过宏程序在Part中生成了实体,但没有“更新”实体,其测量会报错!
(3)如果要对“零件几何体”进行体积测量,以下给出范例程序:

Set objPart=CATIA.ActiveDocument.PartSet objRef=objPart.CreateReferenceFromObject(objPart.Mainbody)Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")Set TheMeasurable = TheSPAWorkbench.GetMeasurable(objRef)LoftVolume = TheMeasurable.VolumeMsgbox LoftVolume
1 0
原创粉丝点击