CATIA VBA 使用Search语言

原文链接

本文介绍如何在CATIA里使用VBA 搜索语言搜索对象。

search语言开放了跟 Edit > Search 命令相似的大部分功能。使用 Edit > Search 命令,CATIA会创建一个查询语句,并将该语句显示在搜索对话框的查询框中。

查询语句可以用于power input box 、 Search对话框的Advanced tab ,也可以用于宏命令。除了找到元素,还可以自动选中查找到的对象。

Any generated query can be run via the power input box or in macros, whether transformat or not.

However, the transformat query is the only usable query whatever the session language, therefore any query you expect to run in different session languages must be written in this format.

如果不熟悉此格式,可以在搜索对话框Favorites标签栏找到其全文(此列为隐藏,你需要手工拖动才能看到):


举个栗子:


CATDrwSearch.DrwText.Name=test

表示搜索在草图中名称为“test”且在“In <UI-Active object>”范围的对象。

使用操作符

主要有以下操作符:

  • : and = (these separators are interchangeable)
  • != (different)
  • <, <=, >, =>

按名称查找

You can search for an object name. This is particularly useful if you renamed objects using Edit > Properties, or the Properties contextual command. The name can also contain special characters.

可以通过对象名称进行查找,在需要通过 Edit > Properties或Properties 上下文进行重命名时候,这个功能尤其好用。名称中间可以嵌套特殊字符。

参考以下代码:


name:object_name   

或者


name=object_name

再或者将"Name"简化为"n"


n:object_name

这里"object_name"代表需要查找的对象名称。

也可以使用“*”字符作为通配符。举例如下:


name:wheel*

将能搜索所有名称以"wheel"开头的元素。

KeyboardInput.CATNIs中可以设置简写,比如默认情况下c:表示col:。所以可以通过检查该文件以确定简写没有重复。

以下写法区分大小写:


NAME:Wheel*

将会搜索所有名称以 "Wheel"开头的对象。

注意:用于不区分大小写的,其关键字小写;否则,关键字大写。

For languages that do not make any difference between uppercase and lowercase characters, you can either add the string _CAP to the keyword to specify that the query is case sensitive, or use the Name_CAP transformat keyword.

通过名称查找对象

通过名称查找对象,与上面方法的区别在于,此方法查找结构树上对象的显示名称。

示例如下:


name in graph=object_name

大小写敏感的写法:


NAME IN GRAPH=object_name

因为在树上显示名称可以自定义,所以这个名称可能跟我们在属性框内的名称不同

假设有个Part名称为"My_Part_Number"...


一般情况结构树显示如下:



假设我们修改过设置:

Tools > Options > Infrastructure > Product Structure > Nodes Customization


那结构树上将显示 如下:



当查询语句如下:


name=*part*

将不会得到结果,因为这种搜索方式基于在结构树上显示的实例名称。

但当我们输入以下代码:


name in graph=*part*

将能够搜索到结果。

Note that the tree item size defined in the Tree Appearance tab is not taken into account.

通过类型查找

参考以下代码:


type:type   or  type=type

或者:


t:type

可以使用符号"."


Part Design.Pad

以上代码会查找所有使用Part Design工具台创建的Pad(拉伸特征)。

以下代码格式也允许:


workbench.type.attribute=

Part Design.Pad.Color=Sea Green

将会搜索所有使用Part Design工具台创建的Pad(拉伸特征)而且颜色是海蓝的特征。

当类型仅存在于一个工作台,工作台名称可以简写:


Part Design.Pad

与以下等价:


.Pad

类似的


Part Design.Pad.Color=Sea Green

与以下等价:


type=Pad & Color=Sea Green

以下为参考:


workbench.type.name=point*

workbench.type.name!=point*

workbench.type.name:point*

workbench.type.color='sea green'

workbench.type.color!='sea green'

workbench.type.color:'sea green'

按颜色查找

此查找方式,参考以下代码:


color:color_name

col:color_name

此处“color_name”为对象的颜色。


If the name of the color contains a blank (which is the case with most of the colors available), you can type the full name as follows:

如果颜色名称中包含空格(大多数情况),参考如下:


color:Sandy Brown

也可以在空格前后用单引号,如下:


color:Sandy' 'Brown

color:'Sandy Brown'

也可以使用RGB:


color:'(211,178,125)'

在color list或者color palette的任意一个颜色,都在color table中有一个序号,因此假设我们现在要搜索“Salmon”颜色,可以这样:


col:Salmon

也可以这样


col:17

因为“Salmon”是color palette中的 第17个颜色。

color list种16种可用颜色如下:


在调色板中,提供了48种颜色,其中16种颜色与Color list中显示的颜色相同。

这些颜色从上到下编号如下:第一行是颜色#1至#8,第二行是颜色#9至#16,依此类推,直到右下角的颜色为#48:


要查看列出48种颜色及其名称,索引和RGB代码的表格,请参阅调色板
通过产品属性搜索

可以搜索的属性包括:

  • Part Number
  • Revision
  • Definition
  • Nomenclature
  • Product Description
  • Component Description.

    假设有如下代码:
Product Description:completed

Product' 'Description:completed

'Product Description':completed

'Product Description'=completed

将会搜索所有产品描述包含“completed”的元素。

属性名称对大小写敏感。

根据图层搜索

参考如下代码:


l:layer_number  or  l=layer_number
or
layer:layer_number  or  layer=layer_number

"layer_number" 代表图层号。

Searching for Objects Belonging to a Selection Set
根据选择集搜索

参考以下代码:


s:selection_set_name
or
set:selection_set_name

"selection_set_name" 代表选择集名。

以下代码大小写敏感:


SET=selection_set_name

The strings "name", "type", "color" and "set" are appropriate for the English language only. The message catalog KeyboardInput.CATNls determines the exact syntax for your language.

按可见性搜索

参考以下代码:


visibility:visible

vis:visible

visibility:hidden

vis:hidden

按线宽线型搜索

参考代码:


weight:

w:

dashed:

d:

当需要搜索特定宽度,参考以下代码:


weight:6,all

可以搜索所有宽度为2mm的线。

按符号搜索

参考如下代码:


symbol:small full square  or  symbol=small full square

or

symb:small full square  or  symb=small full square

将会搜索方形。

所搜索的字符对大小写不敏感,以下代码意义一样:


symbol:Small Full Square  or  symbol=SMALL FULL SQUARE

可以搜索的符号如下:


使用预定义偏好搜索

预定义偏好不能修改、删除

The shortcuts used to run these predefined queries have been defined to search "Everywhere". However, if the scr as Visible on screen option is selected in the Default Search Scope for Power Input list and if the Replaces scope defined in favorite queries option is selected, the queries will search for visible elements only.

用于预定义偏好的简写,已经定于为全局可用。


For instance, to search for all sketches everywhere, enter the appropriate shortcut after the prefix used to run favorite queries:

比如要搜索所有草图,可用参考如下代码:


f:*SKT  or f=*SKT

也可以


favorite:*SKT   or  favorite=*SKT



f:*LNT2  or f=*LNT2

也可以


favorite:*LNT2  or favorite=*LNT2

当选项“ f: as favorite:”选中时,可以参考:


*LNT2
  • 使用特殊字符

    & +  - ( ) 几个字符作用很大,

举例如下:


n:*')'  searches for all names ending with )
n:*'&'  searches for all names containing &
n:*'(1)'  searches for all names ending with (1).

在KeyboardInput.CATNls 源文件中,有以下代码:


Quote     = " ' ";

定义了默认的包裹字符。


The character * is always interpreted as a wild card except if surrounded by two characters '.

字符 * 常用于通配符,除非有两个 ' 字符 包裹。

举例如下:


n:*''*''  searches for all names ending with *

n:*''*''*  searches for all names containing *

n:*'&'''*''*  searches for all names containing &*

n:'*)'  searches for all names ending with ). This is identical to n:*')'

字符 ' 要包裹两次:

举例如下:


n:*''''*  searches for all names containing a '
n:P''''*  searches for all names beginning with P'
n:P''''''''*  searches for all names beginning with P''
n:P''''''''''''*  searches for all names beginning with P'''
n:P''''''''''''''''*  searches for all names beginning with P''''.
  • 使用操作符

    支持的操作符包括: &, +, and - (代表并, 或和非) 与( ).

    空格不作为特殊字符。可以使用 ' 符号包裹空格,但并不强制。

举例如下:

以下代码搜索所有以"wheel&door"结尾的Part。


name:*wheel'&'door&type:Part
name:*wheel'&'door & type:Part
name:*'wheel&door' & type:Part
name:*'wheel&door'& type:Part
name:*wheel'&'door &type:Part

以下代码搜索名为“wheel1”和“wheel2”的物体:


name:wheel1 + name:wheel2

以下代码供参考:

http://ww3.cad.de/foren/ubb/Forum133/HTML/009577.shtml



Sub CATMain()
    Dim actDoc 'As ProductDocument
    Dim oSel As Selection
    Dim oVisPropSet As VisPropertySet

    Set actDoc = CATIA.ActiveDocument
    Set oSel = actDoc.Selection
    Set oVisPropSet = oSel.VisProperties

    '"Bedingungen werden ausgeblendet"
    oSel.Search "(((((((CATProductSearch.MfConstraint + CATStFreeStyleSearch.MfConstraint) + CATAsmSearch.MfConstraint) + CATSketchSearch.MfConstraint) + CATDrwSearch.MfConstraint) + CATPrtSearch.MfConstraint) + CATSpdSearch.MfConstraint) & Visibility=Shown),all"
    oVisPropSet.SetShow 1
    oSel.Clear

    '"Achsensysteme werden ausgeblendet"
    oVisPropSet.SetShow 1
    oSel.Clear

    '"Ebenen werden ausgeblendet"
    oSel.Search "((((CATStFreeStyleSearch.Plane + CATPrtSearch.Plane) + CATGmoSearch.Plane) + CATSpdSearch.Plane) & Visibility=Shown),all"
    oVisPropSet.SetShow 1
    oSel.Clear

    '"Skizzen werden ausgeblendet"
    oSel.Search "(((CATPrtSearch.Sketch + CATGmoSearch.Sketch) + CATSpdSearch.Sketch) & Visibility=Shown),all"
    oVisPropSet.SetShow 1
    oSel.Clear

    '"Geometrische Sets werden ausgeblendet"
  oSel.Search "((((CATStFreeStyleSearch.OpenBodyFeature + CATPrtSearch.OpenBodyFeature) + CATGmoSearch.OpenBodyFeature) + CATSpdSearch.OpenBodyFeature) & Visibility=Shown),all"
    oVisPropSet.SetShow 1
    oSel.Clear

End Sub

http://www.coe.org/p/fo/et/thread=27384


Public Sub testAll()

        Dim SelectionQuery As String
        'MOSTRAR TODOS LOS PARTS
        SelectionQuery = "CATAsmSearch.Part.Visibility=Hidden,all"
        ocultar (SelectionQuery)
        'MOSTRAR TODOS LOS PRODUCTS
        SelectionQuery = "CATAsmSearch.Product.Visibility=Hidden,all"
        ocultar (SelectionQuery)
        ''OCULTAR TODOS LOS PARTS
        'SelectionQuery = "CATAsmSearch.Part.Visibility=Visible,all"
        'ocultar(SelectionQuery)
        ''OCULTAR TODOS LOS PRODUCTS
        'SelectionQuery = "CATAsmSearch.Product.Visibility=Visible,all"
        'ocultar(SelectionQuery)
        'OCULTAR TODOS LOS EJES
        SelectionQuery = "CATPrtSearch.AxisSystem.Visibility=Visible,all"
        ocultar (SelectionQuery)
        'OCULTAR TODOS LOS SUPERFICIES
        SelectionQuery = "CATPrtSearch.Surface.Visibility=Visible,all"
        ocultar (SelectionQuery)
        'OCULTAR TODOS LOS WIREFRAMES
        SelectionQuery = "CATPrtSearch.Wireframe.Visibility=Visible,all"
        ocultar (SelectionQuery)
        'OCULTAR TODOS LOS SKETCHES
        SelectionQuery = "CATPrtSearch.Sketch.Visibility=Visible,all"
        ocultar (SelectionQuery)
        'OCULTAR TODOS LOS CONSTRAINTS
        SelectionQuery = "CATAsmSearch.MfConstraint.Visibility=Visible,all"
        ocultar (SelectionQuery)
        'OCULTAR TODOS LOS MEASURES
        SelectionQuery = "Name='MeasureBetween',all"
        ocultar (SelectionQuery)

        MsgBox ("Limpieza Realizada")


    End Sub

    Private Sub ocultar(SelectionQuery As String)
'        On Error GoTo salida
        Dim check As Boolean
        Dim HideorShow As Integer
        '"CATAsmSearch.Product.Visibility=Visible,all"
        check = SelectionQuery Like "*Visible*"
        If check Then
            HideorShow = 1
        Else
            HideorShow = 0
        End If
        Dim myDocument As Document
        Dim selection1 As Selection
        Set myDocument = CATIA.ActiveDocument
        Set selection1 = myDocument.Selection
        
        Dim visPropertySet1 As VisPropertySet
        Set visPropertySet1 = selection1.VisProperties
        selection1.Search (SelectionQuery)
        For pp = 1 To selection1.Count
            Set visPropertySet1 = visPropertySet1.Parent
            selection1.Item (pp)
            visPropertySet1.SetShow (HideorShow)
        Next pp
        selection1.Clear
'        selection1.
'        selection1.Clear()
salida:
    End Sub

http://www.coe.org/p/fo/et/thread=30413


what i remember , with old catia version , V5R14-R16  , besic search function was OK to select , hide

since V5R20 or V5R22 , basic search was very very very slow on big assembly

=> need to modify macro (see below)

 

 

Sub NoShowElement(Selection As String)
' passe en Nosho des elements

Dim Chaine As String
Chaine = ""
'selection des entites
If Selection = "BasicV4" Then
    Chaine = "(V4Model.AXS + (V4Model.CRV + (V4Model.LN + (V4Model.PLN + V4Model.PT)))),all"
End If
If Selection = "BasicV5" Then
    Chaine = "(CATAsmSearch.MfConstraint + CATPrtSearch.Plane + CATPrtSearch.AxisSystem),all"
End If

If Chaine = "" Then
    Exit Sub
End If


'Noshow
Dim MySelection
' Dim CATIA As INFITF.Application
Set CATIA = GetObject(, "CATIA.Application")

Dim HSOSynchronizedFilter(0)
Dim sel
Dim Status
Dim Message As String

Set sel = CATIA
sel.HSOSynchronized = False

Set MySelection = CATIA.ActiveDocument.Selection
MySelection.Clear


' cas de la part , on regarde si elemenet est visible


If Right(UCase(CATIA.ActiveDocument.Name), 7) = "CATPART" Then
   
    ' on veut savoir si les 3 plans XYZ sont déjà cachés
   
    Dim PlaneVisible As Boolean
    Dim mypart As Part
    Dim VisuAttr As CatVisPropertyShow
       
   
    PlaneVisible = False
    Set mypart = CATIA.ActiveDocument.Part
   
    MySelection.Clear
    MySelection.Add mypart.OriginElements.PlaneXY
    MySelection.VisProperties.GetShow VisuAttr
    If VisuAttr = 0 Then
        PlaneVisible = True
    End If
   
    MySelection.Clear
    MySelection.Add mypart.OriginElements.PlaneYZ
    MySelection.VisProperties.GetShow VisuAttr
    If VisuAttr = 0 Then
        PlaneVisible = True
    End If
   
    MySelection.Clear
    MySelection.Add mypart.OriginElements.PlaneZX
    MySelection.VisProperties.GetShow VisuAttr
    If VisuAttr = 0 Then
        PlaneVisible = True
    End If
       
    ' on regade aussi les AXIS
    Dim i As Integer
    If mypart.AxisSystems.Count > 0 Then
        For i = 1 To mypart.AxisSystems.Count
            MySelection.Clear
            MySelection.Add mypart.AxisSystems.Item(i)
            MySelection.VisProperties.GetShow VisuAttr
            If VisuAttr = 0 Then
                PlaneVisible = True
            End If
        Next i
    End If
   
    If PlaneVisible Then
        GoTo StartNoShow
    End If
   

End If


Message = "Voulez vous cacher les elements : Yes " & vbCrLf & "Montrer les elements : No " & vbCrLf & "Ne rien faire : Annuler "
Message = LoadResString(933) & vbCrLf & LoadResString(934) & vbCrLf & LoadResString(935)

   
Select Case MsgBox(Message, vbYesNoCancel, LoadResString(936))
 Case (vbYes)
StartNoShow:
    MySelection.Search Chaine
    MySelection.VisProperties.SetShow 1
    MySelection.Clear
    sel.HSOSynchronized = True
 Case (vbNo)
    Chaine = "(CATPrtSearch.Plane + CATPrtSearch.AxisSystem),all"
    MySelection.Search Chaine
    MySelection.VisProperties.SetShow 0
    MySelection.Clear
    sel.HSOSynchronized = True
 Case Else
 Exit Sub

End Select


'    HSOSynchronizedFilter(0) = "SetCATIADotHSOSynchronizedToTrue"
'    Status = sel.SelectElement2(HSOSynchronizedFilter, "", False)

sel.HSOSynchronized = True


End Sub

This macro is intended to "Hide all except Solids" (depending on your selection specification)

 

Sub CATMain()

'Hide all relevant elements i a part or product

Dim selection1 As Selection
Dim visPropertySet1 As VisPropertySet

Dim partdocument1 As Document
Set partdocument1 = CATIA.ActiveDocument

'Define your selections

Set selection1 = partdocument1.Selection
selection1.Search "((((((((CATStFreeStyleSearch.OpenBodyFeature + CATPrtSearch.OpenBodyFeature) + CATGmoSearch.OpenBodyFeature) + CATSpdSearch.OpenBodyFeature) + CATPrtSearch.Sketch + CATPrtSearch.Plane) + CATPrtSearch.MfConstraint) + CATPrtSearch.AxisSystem) + CATPrtSearch.Point) + CATPrtSearch.Line),all"

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetShow 1

selection1.Clear
End Sub

 

Well, I have modified the macro for V6 3DExperience 2016x. And it works just the same ...

 

Sub CATMain()

 Dim Editor1 As Editor
 Set Editor1 = CATIA.ActiveEditor

 Dim selection1 As Selection
 Set selection1 = Editor1.Selection

 Dim visPropertySet1 As VisPropertySet
 Set visPropertySet1 = selection1.VisProperties

 Dim partdocument1 As Object
 Set partdocument1 = Editor1.ActiveObject

'Define your selections

 Set selection1 = Editor1.Selection
     selection1.Search "((((((((CATStFreeStyleSearch.OpenBodyFeature + CATPrtSearch.OpenBodyFeature) + CATGmoSearch.OpenBodyFeature) + CATSpdSearch.OpenBodyFeature) + CATPrtSearch.Sketch + CATPrtSearch.Plane) + CATPrtSearch.MfConstraint) + CATPrtSearch.AxisSystem) + CATPrtSearch.Point) + CATPrtSearch.Line),all"

 Set visPropertySet1 = selection1.VisProperties
     visPropertySet1.SetShow 1
 selection1.Clear
 
End Sub

提速建议:

对各个Part分开查找,在Part内找到相关元素,再遍历进行隐藏/显示。这将比整体查找快100倍。 CATIA.HSOSynchronized = False ,以防止运行过程中频繁更新。这个方法也会避免查找相同Part的不同实例。


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空