Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA VBA Script - Implicit vs Explicit Selection

Status
Not open for further replies.

Sandy_Man

Mechanical
Jun 7, 2024
3
I am writing some code that takes the users selection and changes the colour of the feature randomly.

Ideally I would like the user to be able to select the feature from the tree or the geometry itself, and the macro behave in the same way: as an explicit selection. Currently if the user selects the geometry only the selected patch of the feature changes colour, I would like it to behave as if the user has selected the element in the tree.

I would also ideally like the macro to be able to accept user pre-selection, my current version does achieve this.

As a bonus, if the code could change if the user is at the product level to change the colour of the PartBody it would be great!

Having this selection issue solved would help massively for a few other macro projects I have in mind, any help would be greatly appreciated.

Current code below for reference:



Sub CATMain()

Dim UserSel
Dim rcol As Integer
Dim gcol As Integer
Dim bcol As Integer
Dim MyObjectName
Dim InputObject(0)
Dim Status
Dim RandNum As Integer


rcol = 0
gcol = 0
bcol = 0
Set UserSel = CATIA.ActiveEditor.Selection
Set MyEditor = CATIA.ActiveEditor
InputObject(0) = "AnyObject"
Set UselLB = UserSel



oStatus = UselLB.SelectElement(InputObject, "Select geometry to change its colour", True)
If (oStatus = "Normal") Then
RandNum = Int((255 * Rnd) + 1)
rcol = RandNum
RandNum = Int((255 * Rnd) + 1)
gcol = RandNum
RandNum = Int((255 * Rnd) + 1)
bcol = RandNum
UselLB.VisProperties.SetRealColor rcol, gcol, bcol, 0
Else
Exit Sub
End If

UselLB.Clear



End Sub

 
Replies continue below

Recommended for you

in "User Selection Filter" there is a command that selects whole features, even if you click on a patch:
"Feature Element Filter". You can engage it prior to user-selection:
Code:
CATIA.StartCommand "Feature Element Filter"
But this will only be valid whilst nothing is selected prior to running the code. Same line is used to disengage the command.


regards,
LWolf
 
Thanks LWolf,

If I were to need pre-selection to be possible, do you think there would be a way for the code to differentiate between an implicit ("face", "edge", etc.) selection and an explicit ("Extrude.1") selection? And then maybe run an if statement to select the implicit selections parents, otherwise running the code as normal?
 
all BReps tend to be very long names... so yeah it is possible to infer whether the selection was made on a topology/implicit element (face, edge or vertex) or proper/explicit.

regards,
LWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor