天天看点

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

🍺相关文章汇总如下🍺:

  • 🎈LMS Virtual.Lab二次开发:声学仿真理论基础准备(Python)🎈
  • 🎈LMS Virtual.Lab二次开发:场点网格编辑(VBScript)🎈
  • 🎈LMS Virtual.Lab二次开发:声学仿真结果导出方法(VBScript、Python)🎈
  • LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

    文章目录

    • ​​1、网格类型简介​​
    • ​​2、场点网格工具栏​​
    • ​​3、场点网格菜单​​
    • ​​4、添加Spherical Field Point Mesh​​
    • ​​5、添加Box Field Point Mesh​​
    • ​​6、添加Plane Field Point Mesh​​
    • ​​7、添加Cylinder Field Point Mesh​​
    • ​​8、添加Point Set Field Point Mesh​​
    • ​​9、添加ISO Power Field Point Mesh​​
    • ​​10、添加Line Field Point Mesh​​
    • ​​11、添加Directivity Field Point Mesh​​
    • ​​12、结果重新更新​​
    • ​​结语​​

1、网格类型简介

LMS Virtual.Lab Acoustic 工作台可以包含不同类型的网格部件,这些部件都列在规范树的节点和元素特征下。网格部分属于以下三种类型之一:

  • 结构网格部分(Structural Mesh Part):

    结构网格部分是一个结构有限元网格,它代表了振动结构的几何和结构行为。这个网格仅仅存在于声振分析的结构部分,它将表示结构的动力特性(在物理坐标系或模态坐标系中)。

  • 声学网格部分(Acoustic Mesh Part):

    声学网格部分是一个声学网格,它只代表振动结构的几何形状。这种网格没有结构特性。它只存在于振动声学分析的声学部分,会影响声场的反射、散射和衍射。

  • 场点网格部分(Field Point Mesh Part):

    场点网格部分(FPM)是一个可视化网格,用于计算和表示振动结构周围空间的声学结果。这个网格不影响声学解: 它对声波是完全透明的。场点网格部分默认显示为半透明黄色。

修改网格类型的VBA脚本代码如下:

'***********************************************************************
'   Purpose:   修改网格类型
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************

Sub CATMain()
Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   ' Set the Mesh Part Type
   AcousticCmd.SetMeshPartType StructuralMesh, eLMSStructural 
   AcousticCmd.SetMeshPartType AcousticMesh, eLMSAcoustical 
   AcousticCmd.SetMeshPartType FieldPointMesh, eLMSFieldPoint
   AcousticCmd.SetMeshPartType CGNSMesh, eLMSSource
End Sub      

2、场点网格工具栏

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
  • Insert a Plane Field Point Mesh
  • Insert a Spherical Field Point Mesh
  • Insert a Cylinder Field Point Mesh
  • Insert a Box Field Point Mesh
  • Insert a Point Set Field Point Mesh
  • Insert an ISO Power Field Point Mesh
  • Insert a Line Field Point Mesh
  • Insert a Directivity Field Point Mesh

3、场点网格菜单

  • (1)场点网格菜单默认是隐藏的。第一种显示场点网格菜单的方法是鼠标点击主菜单“开始”中的子菜单“Acoustic Harmonic BEM”。
  • LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
  • 也可以通过如下的VBA脚本进行工作台的环境菜单切换:
'***********************************************************************
'   Purpose:   执行工作台的环境界面切换
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************

Sub CATMain()
' Opening Acoustic Harmonic BEM Workbench
CATIA.StartWorkbench("Acoustics")
End Sub      

然后通过通过如下的VBA脚本检查当前使用的工作台的名称:

'***********************************************************************
'   NOTE: Following script when run in a workbench will display the corresponding Workbench ID. This ID can be used as shown above to initialize the respective workbench.
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************

Sub CATMain()
msgbox(CATIA.GetWorkbenchId)
End Sub      
LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

然后在主菜单“插入”-“Field Point Meshes”会出现相关子菜单。

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

同时在“Analysis Manager”对象树的子节点“Nodes and Elements”的右键菜单“Field Point Meshes”里也会出现相关子菜单。

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

对于之前添加的其他类型网格对象,我们也通过如下菜单将之修改为场点网格,即子菜单“Set as Field Point Mesh Part”。

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

当然这一组子菜单也有对应的工具栏。通过如下图的方式显示和隐藏这个工具栏。

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
  • (2)上面这个工具栏和菜单经常容易消失而找不到,我们需要通过如下的第二种方法添加需要的场点网格对象到“Nodes and Elements”中,用于方便结果数据的输出和查看。
  • LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

4、添加Spherical Field Point Mesh

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
'***********************************************************************
'   Purpose:   添加球形场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'''' /CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_SphericalFieldPointMesh_60302.htm

Sub CATMain()
'Creates a new Spherical Field Point mesh. By default uses the Acoustical Mesh Center as Sphere center.
   Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   Set mesh = AcousticCmd.CreateSphericalFieldPointMesh("ExampleSphericalFPM", 1, 4)

   ' Change the name
   mesh.Name = "Example Spherical Field Point Mesh"
   'The center coordinates may also be modified on the returned object.
   'Set the coordinates of the center. Plain numbers are considered to be in meter, strings should have a length unit
   mesh.X = 0
   mesh.Y = "1cm"
   mesh.Z = "0mm"
   ' Change the radius (to 2.5 meter, a string with length unit is also possible)
   mesh.Radius = 2.5
   ' Change the refinement level
   mesh.Refinement = 3
   ' Update the feature, this creates the nodes and elements
   ' of the spherical field point mesh
   mesh.Update
End Sub      

5、添加Box Field Point Mesh

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
'***********************************************************************
'   Purpose:   添加立方体场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'''' /CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_BoxFieldPointMesh_48494.htm

Sub CATMain()
 ' Create a new Box Field Point Mesh
   Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   Set myBox= AcousticCmd.CreateBoxFieldPointMesh("ExampleBoxFPM")

   ' Change the name
    myBox.Name = "Example Box Field Point Mesh"
   ' Set the Start and End point
    myBox.SetStartPoint 10, 10, 10
    myBox.SetEndPoint 10, 10, 110

   ' Set the Dvisions based on the axis
    myBox.XDivision  = 5
    myBox.YDivision  = 3
    myBox.ZDivision  = 3
   ' Update the feature, this creates the nodes and elements
   ' of the cylindrical field point mesh
    myBox.Update
End Sub      

6、添加Plane Field Point Mesh

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
'***********************************************************************
'   Purpose:   添加平面场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'/CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_PlaneFieldPointMesh_51985.htm

Sub CATMain()
' Create a new Plane Field Point Mesh
   Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   Set mesh = AcousticCmd.CreatePlaneFieldPointMesh

   ' Set the name
   mesh.Name = "Example Plane Field Point Mesh"
   ' Set the coordinates of Point 1, Point 2 and Point 3
   ' plain numbers are considered to be in meter, strings should have a length unit
   mesh.Point1_X = 0
   mesh.Point1_Y = 1
   mesh.Point1_Z = 0
   mesh.Point2_X = "0in"
   mesh.Point2_Y = "1300mm"
   mesh.Point2_Z = 0
   mesh.Point3_X = 0.4
   mesh.Point3_Y = "1m"
   mesh.Point3_Z = 0
   ' Set the refinement levels
   mesh.Refinement_P1P2 = 3
   mesh.Refinement_P1P3 = 4
   ' Update the feature, this creates the nodes and elements
   ' of the plane field point mesh
   mesh.Update
End Sub      

7、添加Cylinder Field Point Mesh

'***********************************************************************
'   Purpose:   添加锥体场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'/CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_CylinderFieldPointMesh_58154.htm

Sub CATMain()
' Create a new Spherical Field Point Mesh
   Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   Set myCylinder = AcousticCmd.CreateCylindricalFieldPointMesh("ExampleCylindricalFPM")

   ' Change the name
    myCylinder.Name = "Example Cylindrical Field Point Mesh"
   ' Set the coordinates of the two centers
    myCylinder.SetStartPoint 10, 10, 10
    myCylinder.SetEndPoint 10, 10, 110
   ' Set the Start, Middle and End radius
    myCylinder.SetRadius 100, 100, 100
   ' Set the Length and Section Refinement
    myCylinder.SectionRefinement = 5
    myCylinder.LengthRefinement = 5
   ' Update the feature, this creates the nodes and elements
   ' of the cylindrical field point mesh
    myCylinder.Update
End Sub      

8、添加Point Set Field Point Mesh

'***********************************************************************
'   Purpose:   添加点云场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'/CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_PointSetFieldPointMesh_58106.htm

Sub CATMain()
 ' Create a new Point Set Field Point Mesh
   Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   Set mesh = AcousticCmd.CreatePointSetFieldPointMesh

   ' Set the name
   mesh.Name = "Example Point Set Field Point Mesh"
   ' Add two points
   mesh.AddPoint "P1", 0, "100mm", "0m"
   mesh.AddPoint "P2", 0, 1, 0
   ' Remove the first point
   mesh.RemovePoint "P1"
   ' Update the feature, this creates the nodes of the Point Set Field Point Mesh
   mesh.Update

   ' Retrieve information about the Point Set Field Point Mesh
   NrOfPoints = mesh.Count ' result: 1
   FirstPoint = mesh.GetNameOfPoint(1) ' result: "P2"
   mesh.GetCoordinatesOfPoint 1, x, y, z ' result: 0, 1, 0
End Sub      

9、添加ISO Power Field Point Mesh

To retrieve this interface on an existing field point mesh in a VB Script, use the following approach:

'***********************************************************************
'   Purpose:   添加ISO场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'/CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_ISOFieldPointMesh_48384.htm

Sub CATMain()
Dim AnalysisDoc ' As AnalysisDocument
 Set AnalysisDoc = CATIA.ActiveDocument
 Set analysisManager1 = AnalysisDoc.GetItem("AnalysisManager")
 Set analysisModels1 = analysisManager1.AnalysisModels
 Set analysisModel1 = analysisModels1.Item(1)
 Set analysisSets1 = analysisModel1.AnalysisSets
 Set analysisMeshManager1 = analysisSets1.ItemByType("MSHMeshSet")
 Set analysisMeshParts = analysisMeshManager1.AnalysisSets
 Set ISOFieldPointMesh = analysisMeshParts.GetItem("ISO Power Field Point Mesh.1")
End Sub      

Gets or sets the refinement level.

This attribute has a meaning only if the ISO field point mesh is of type ‘Parallelepiped’. If it is of a different type this function will fail. Only positive values are allowed.

This example shows the usage of all properties mentioned above:

'***********************************************************************
'   Purpose:   添加ISO场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************

Sub CATMain()
  Dim AnalysisDoc ' As AnalysisDocument
  Set AnalysisDoc = CATIA.ActiveDocument
  Set analysisManager1 = AnalysisDoc.GetItem("AnalysisManager")
  Set analysisModels1 = analysisManager1.AnalysisModels
  Set analysisModel1 = analysisModels1.Item(1)
  Set analysisSets1 = analysisModel1.AnalysisSets
  Set analysisMeshManager1 = analysisSets1.ItemByType("MSHMeshSet")
  Set analysisMeshParts = analysisMeshManager1.AnalysisSets
  Set ISOFieldPointMesh = analysisMeshParts.GetItem("ISO Power Field Point Mesh.1")

  MsgBox (ISOFieldPointMesh.Alias)
  ISOFieldPointMesh.Alias = "ISO FPM Name Changed by User"
  MsgBox (ISOFieldPointMesh.Alias)

  ISOFieldPointMesh.ISOFieldPointMeshType = eLMSMeshTypeCoarse
  ISOFieldPointMesh.ISOFieldPointMeshType = eLMSMeshTypeFine
  ISOFieldPointMesh.ISOFieldPointMeshType = eLMSMeshTypeParallelepiped

  MsgBox (ISOFieldPointMesh.ModelMeshReference.Name)
  ' Selecting another Acoustic Mesh Part to be used as Model Mesh Reference in the ISO Field Point Mesh
  Dim AcousticMeshPart ' As AnalysisMeshPart
  Set AcousticMeshPart = analysisMeshParts.GetItem("Acoustic Cavity")
  ISOFieldPointMesh.ModelMeshReference = AcousticMeshPart
  MsgBox (ISOFieldPointMesh.ModelMeshReference.Name)

  MsgBox (ISOFieldPointMesh.Refinement)
  ISOFieldPointMesh.Refinement = 8
  MsgBox (ISOFieldPointMesh.Refinement)
End Sub      

10、添加Line Field Point Mesh

'***********************************************************************
'   Purpose:   添加线段场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'/CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_LineFieldPointMesh_50174.htm

Sub CATMain()
' Create a new Line Field Point Mesh
   Dim myLineFPM As LineFieldPointMesh
   Set myLineFPM = AcousticCmd.CreateLineFieldPointMesh("My Line FPM")
   'Set the Start and End Point
   myLineFPM.SetStartPoint 10, 10, 10
   myLineFPM.SetEndPoint 110, 110, 110
   'Set the Division
   myLineFPM.Division = 3
   'Update
   myLineFPM.Update
End Sub      

11、添加Directivity Field Point Mesh

'***********************************************************************
'   Purpose:   添加方向性场点网格
'   Author:    爱看书的小沐
'   Date:      2022-02-21 
'   Languages: VBA
'   Platform:  LMS Virtual.Lab 13.10
' ***********************************************************************
'/CAADoc/VLDoc/generated/interfaces/LMSVAMScriptingInterfaces/interface_DirectivityFieldPointMesh_65529.htm

Sub CATMain()
 ' Create a new Directivity Field Point Mesh with a radius of 2 meter
   ' and the z axis as normal direction
   Set AcousticCmd = CATIA.GetItem("LMSAcousticFactory")
   Set mesh = AcousticCmd.CreateDirectivityFieldPointMesh(2, 0, 0, 1)

   ' Change the name
   mesh.Name = "Example Directivity Field Point Mesh"

   ' Change the coordinates of the center
   ' plain numbers are considered to be in meter, strings should have a length unit
   mesh.X = 0
   mesh.Y = 1
   mesh.Z = "50cm"

   ' Set the radius and the normal direction explicitly again
   ' (just for clarity how to use these properties - they were already initialized
   '  with the following values by CreateDirectivityFieldPointMesh)
   mesh.Radius = "2m"
   mesh.Normal_Direction_X1 = 0
   mesh.Normal_Direction_Y1 = 0
   mesh.Normal_Direction_Z1 = 0
   mesh.Normal_Direction_X2 = 0
   mesh.Normal_Direction_Y2 = 0
   mesh.Normal_Direction_Z2 = 1

   ' Change the coordinates of the initial angle direction
   mesh.Initial_Angle_Direction_X1 = 0
   mesh.Initial_Angle_Direction_Y1 = 1
   mesh.Initial_Angle_Direction_Z1 = "50cm"
   mesh.Initial_Angle_Direction_X2 = "1in"
   mesh.Initial_Angle_Direction_Y2 = "1cm"
   mesh.Initial_Angle_Direction_Z2 = "50cm"

   ' Change the angles to get a 180 degrees directivity field point mesh (instead of 360 degrees)
   mesh.Angle_Start = 0
   mesh.Angle_End = 180
   mesh.Angle_Step = "5deg"

   ' Update the feature, this creates the nodes and elements
   ' of the directivity field point mesh
   mesh.Update
End Sub      

12、结果重新更新

场点不参与计算,其只相当于一个声压传感器,场点定义在哪里,就是计算哪里的声场结果。

对场点网格进行编辑之后,需要鼠标点击相关结果节点,进行结果效果重新更新操作,比较耗时。

LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
LMS Virtual.Lab二次开发:场点网格编辑(VBScript)
LMS Virtual.Lab二次开发:场点网格编辑(VBScript)

结语

继续阅读