In the CATIA Object Model there is a special object called “Selection”, which belongs to the different documents. This “Selection” object is a container
that holds anything that is currently selected in a session of CATIA V5. It is accessed by:
Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection
So, for example, if nothing is selected, the selection is empty or if you select 1, 2, or more objects, then the selection object contains 1, 2, or more objects.
One of the most common uses of selecting an object in CATIA is to search through that object. Interactively in CATIA you can search for elements or element groups using the Edit + Search pulldown menu. You can do the same thing through VB using the Selection object.You can search by several different methods including “Name”, “Type”, “Color”, etc. – all the same search options available interactively.
If you want to select all points named “CENTER_PT” you can select the active document as your selection and search it for a specific name:
Sub CATMain()
Dim objSel As Selection
Set objSel =CATIA.ActiveDocument.Selection
objSel.Search(“Name=CENTER_PT*,all”)
objcount = objSel.count
msgbox objcount
End Sub
Once the search command has been issued, you can then loop through the selection object to get the items that have been found using a For Loop. For example, if I wanted to add a number 1 through the point count to the end of the point name I code add this code:
Dim i As Integer
For i = 1 to objSel.Count
objSel.Item(i).Value.Name = objSel.Item(i).Value.Name&i
Next ‘i
Where to search?
You may have noticed the ,all or ,sel. There are multiple ways to search:
- Everywhere: shortcut “all”
- InWorkbench: shortcut “in”
- FromWorkbench: shortcut “from”
- FromSelection: shortcut “sel”
- VisibleOnScreen: shortcut “scr”
Example:
‘hide constraints
selection1.Search “CATAsmSearch.MfConstraint,scr”
Set visPropertySet1 = Selection1.visProperties
VisPropertySet1.SetShow 1
Selection1.Clear
After that I can do more complicated tasks like adding an axis system to each point or turning the points to the color red or deleting them but that is a task for another time.
Go back to the CATIA Catscript articles.
I have this code from a blog:
Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
selection1.Search “CATPrtSearch.Plane.Visibility=Visible,all”
I can’t find out info about how to create the search string – especially about the keyword ‘CATPrtSearch’. I have searched internet and the ‘CAA 5 Visual basic help’ manual.
please help.
Thanks for the comment. CATPrtSearch will search an individual CATIA part for specified geometry. For example, if you wanted to find all axis systems you could change the above code to CATPrtSearch.AxisSystem or all sketches to CATPrtSearch.Sketch. To take it a step further you can search for only the visible features: CATPrtSearch.AxisSystem.Visibilty=Visible.
I hope that helps. Are you trying to do something specific?
Hello,
is it possible to select another document as selection? I mean for example PartBody instead of whole CATIA.Active.Document? How does the code look like in such a case?
Trials with my own combinations aren’t successfully, so please help. 😉
Hi Ana,
I’ve only ever used Selection paired with CATIA.ActiveDocument. But from there you can narrow it to a specific type of object. What are you trying to do exactly?
sStatus=Selection.SelectElement2(sFilter, “select and axis”, False)
Set axissyst = Selection.Item(1).Value
Thanks a lot for your answer.
I’ve just considered if it is possible to automatically find all edges in solid which is located in chosen Body (for example I have 3 Bodies: PartBody, Body1 and Body2 and I want to find edges only from Body2). The formula you’ve written is for selecting objects manually, isn’t it? I know I forgot about writting that I wanted to search automatically.
Hello sir ,
from last few days i m trying to make a Script for cleaning the parts using catdua,but i failed plz help…
Hi Swapnil,
As far as I know the CATDUA interface has not yet been exposed to the public so I am unable to help you on this one. Sorry!
Maybe someone else has a workaround. Try posting your question in one of the forums listed on my resources page.
-Emmett
how did you proceed to make a code as even I’m trying to write a code for it
and I’m unable to get any idea
Hi Emmett,
How can i rename all the parts in a product,
also i need to rename instance name too.
Please suggest.
Vik
Hi all,
anybody online nd cn see my post.
i need an urgent help. I need a macro to copy a partbody from one part and paste it to another aprt with pastespecial option. I tried making a macro but partbody is getting copied into the same part from where i am copying.
Please help.
Thanks
Vik
There is an example of how to do exactly that in my book. -Emmett
oSelection.Clear
oSelection.Add oLine
oSelection.Copy
oSelection.Clear
oSelection.Add GeometricalSetOrBodyWhereitIsToBeSaved
‘To paste “AsResultWithLink”
oSelection.PasteSpecial “CATPrtResult”
oSelection.Clear
Is there any way to find deactivated or failed component in product using Script.
Swapnil, check the downloads page as the there is a macro you can download to do exactly that: https://www.scripting4v5.com/downloads/
oSelection.Clear
oSelection.Add oLine
oSelection.Copy
oSelection.Clear
oSelection.Add GeometricalSetOrBodyWhereitIsToBeSaved
‘To paste “AsResultWithLink”
oSelection.PasteSpecial “CATPrtResult”
oSelection.Clear
Hi!
I have a vbscript code for find any callout in drafting.
oSelection.Search (“Name=Callout*;all”)
When I debugging this, CATIA selected all callouts in drafting sheet, but i can’t get any information from selection. All objects in selection defined by active view.
Is it possible to get the callout-object in vbscript?
Sorry for my English 🙂
Hello Emmett Some Specific Questions!!
is it possible to select some specific assy and then measure all the weld lenght involved in that assy? so, then send the amount of weld leght to excel?
Hi Sergio. Selecting a specific assembly is easy, as is exporting information to Excel. The only thing I am not sure of is the length – what kind of geometry is the weld? Can you post an image?
Thanks, Emmett
Great article, very useful. I have been trying to use this same function to find products having a given PartNumber. I have have tried PartNumber=… and Product.PartNumber=…. Is it possible to make a search for part numbers?
Hello emmett sorry for the delay
geometry would be a “Line” it can be measured in catia
if geometry were Solids it cant be measured in catia.
what i want to do is to select an assembly in catia then select specific weld lenghts involved in that assembly and then run a macro to make a sum in excel.
right now what i do is to sum manually every single weld lenght it take a lot of time for me.
so i have some experience with Excel VBA but not a lot experience in Catia Script
my question is Could be possible to do what i mentioned ?
thank you for your help
Hi there !
I’m currently using a vbscript file to use some sendkeys with catia. In my program I call the startcommand function to make a serie of planar sections according to severals planes. My problem is that as I want to call only once the planar section command (because it is just faster like that) I need to be able to select the different planes one by one after applying the planarsections command for each plane. And it doesn’t take it in account… I can see that in my tree the plane has been selected but it has not been taken in account to perform the next planar section that will use the plane selected for the first section… Do you have an idea that would permit me to something like activate the plane so that the planar section knows that it is the one I have selected ?
Hello everyone, I search to write a Script for hide every points, lines, plans,….In a part ,I will make a listbox for that.
I managed to create a Script who can hide only for example “Point.1” but not all the point in the bodies or on a set.
Thanks for your anwser and sorry for my bad english (I’m French).
Hi Emmett,
You note example how to hide constraints.
I would like to hide Geometrical Sets and Annotation sets
How will it be this command:)
-selection1.Search “CATAsmSearch.MfConstraint,scr”
-selection1.Search “CATAsmSearch.AnnotationSet,all”?
thank you in advance
hello,
how to count number of circles in a selected area in CATdrawing using macro
sir,
i have part body , i have intersected with offset plane and intersection appears on the part body. upto this i had done coding. now i want to extract this intersection using coding. i already tried of recording macro for this it is showing
set reference1=createreffromBref(bref(part,%5096))
this is not exact line but looks like this
i want to know why this number is used and how to determine this num . this number is changing continuously .
Hi, assuming i have the names of a few surfaces in different parts of an assembly with many products, how would i go about it in a macro coding? My search trials keeps on getting errors…
HI,
Is it possible to search within a body/hybrid body from a macro?
Example: I have 10 points. 5 in Gset1 and 5 in GSet2, with other reference geometries.
I want to delete all the points in GSet2 only. Naturally, I’d set ‘Look into’ to GSet2 selection. But is it possible to expose this ‘Look into’ to automation?
I tried this, but didn’t work:
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(“GSet2”)
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Add hybridBody1
Dim selection2 As Selection
Set selection2 = partDocument1.Selection
selection2.Search “(CATGmoSearch.GSMIntersect + CATGmoSearch.Intersect), selection1”
Any idea?
I’m new to CATIA VBA, I’m not getting why i’m facing an error when I ran below code .
Sub CATMain()
Dim sSel As Selection
Set sSel = CATIA.ActiveDocument.Selection
Dim oProduct As Product
sSel.Search “Name=’ProductName’,all”
‘ Its highlighting the products when I searched but when I execute below line its ‘ ‘ throwing an error.
sSel.Cut
End Sub
Please Suggest!
Hi All,
I’m trying to figure out how to use the “SwitchOn” function for annotation sets. I’m able to access the visProperties for it but no matter what I try, I can’t switch the Annotations to “On”. Is there a specific syntax or path required to access the annotationset features?
Thanks,
I want to search the holes of Dia 10, but only successfully searched the original holes, the RectPattern holes failed, How to search the RectPattern holes?
Hello,
I’m new working with macros, I’m working with one and I need to get de planes from axis systems selected by the user, I have tried several ways and looked in internet however I can’t find anything, I changed the selected code and I saw that the planes are planar faces, I tried to look for planar face with the search method but I just got error that the method failed,
I’m wondering how I can do this and I hope someone can help me
Thanks!
I am looking for search function in active sheet as with active document it is searching element type im all sheets in active document
How to find any spline in CATIA Part model open in a simple catia interface screen?
Please provide me a macro catscript for this because I am unable to get code due to very liitle information is available about this.
Hi can you help me with a macros to select deactivated parts from a product
How to Select the Draft sheet in V4 and copy / paste those in New V5 drawing sheet.
here is my code , please help.
Sub CATMain()
Dim MySelection As Object
Set MySelection = CATIA.ActiveDocument.Selection
MySelection.Copy
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = documents1.Add(“Drawing”)
Dim oSel As Selection
Set oSel = CATIA.ActiveDocument.Selection
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
MySelection.Paste
End Sub
Hi,
Is it possible to get coordinate for points in a drawing View.
I’ve a search criteria based on that I selected required points.
For i = 1 To pointSel.Count
Set Point1 = pointSel.Item(i)
‘Point1.GetCoordinates (coord)
Next i
I couldn’t able to get the coordinates.
Hello,
I would want to know for the function Selection.search where we can find all the syntax like and specifically this kind of example “CATPrtSearch….or CATGmoSearch.GSMIntersect or CATAsmSearch.AnnotationSet etc….” I don’t find anything for these kind of search in the V5automation
Hi
could you please help me to know
is it possible to make “selection.search.draft,all” with filtering out deactivated drafts?
I am unable to filter out deactivated drafts from it
How to change the group of hole colour in part body in catia. please send me vb macro.
I wanted to call a product or a part separately from the model which contains multiple number of products and parts inside it. How can I write the code to call products/parts separately in 3d experience part design using VB.net. Can someone answer my question?
How do I select an object and make it active so I can do a CATIA.StartCommand(“Reframe On”) and have it zoom on that
object, I can select the object and it turns orange in the tree, but it
is not orange on the graphical screen, and it needs to be for the Reframe On to work.
Hiii 🙂
In your Book you describe the “Search” method for Selection, Help of CATIA describe nothing about type and other for this fonction….
But you speak too “FindObject” method, soo, what use??? “Search” method or “FindObject” method??? It is same???
Thx.
i need to filter text with catoblong with text frame
Hello sir, I would like to know how to search a subset of a certain assembly with search and put it in selsction.