Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Multiple Selection but individual coloring

Status
Not open for further replies.

Reubot

Aerospace
Apr 25, 2017
5
Hello everyone,

I am trying to apply a coloring scheme to a selection of elements but I'm having some trouble. Maybe someone can help?
Problem is as follows:
I want to select a whole bunch of thickness features all with different values, Then I want to assign a color to the thickness feature based on its thickness value. I plan to use an array to define the coloring scheme in RGB values, but I have not gotten that far yet.

Up to now I have used the selectelement3 tool to make a multiselection of the thickness features and just written a simple for loop to cyle through all the features. I though I would be able to apply the visproperties method to change the color of each thickness individually but I am getting an error message that the object does not support this property r method.

In the code below I made a simple rule for the coloring just to check whether anything changes. Please ignore the minimal error handling attempt...im still pretty new at this.

Can anyone help?


Code:
Language="VBSCRIPT"

Sub CATMain()

On Error Resume Next

'*******************************************
' Initiate and selection
'*******************************************
Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

If Err.Number > 0 Then

	MsgBox "Active Document is not a part document!"

Else

	On Error GOTO 0

	Set selection1 = partDocument1.Selection
	selection1.Clear

	'*******************************************
	' Select Features
	'*******************************************

	Dim strArray(0)
	strArray(0) = "Thickness" 'Selection Filter

	sStatus = selection1.SelectElement3(strArray, "Select Items", False, CATMultiSelTriggWhenUserValidatesSelection, False)


	'********************************************
	' Define coloring scheme
	'********************************************
'Create color scheme


	'**********************************************
	' Color the features
	'**********************************************

	For i = 1 To selection1.Count
	
		'Set length = selection1.Item(i).Value.Offset
		'strLength = length.Value * (-1)
		'Coloring formula
		R=10*i
		G=0
		B=10
		
		selection1.Item(i).Value.VisProperties.SetRealColor R, G, B, 1

	Next
  
	'***********************************************
	' Update the part
	'***********************************************
	part1.Update 


End If

End Sub
 
Replies continue below

Recommended for you

Hi, it is the entire selection that will change color, i.e
selection1.VisProperties.SetRealColor r, g, b, 1
NOT the individual elements... so you will have to alter your approach to only select one Thickness at a time...

regards,
LWolf
 
I guess the problem comes from

Code:
selection1.Item(i).Value.VisProperties.SetRealColor R, G, B, 1

Visproperties is a Property of Selection.

so you have to pass your selection to something else, an array would do. then clear selection.

then loop the array and add to selection the single element and color it using selection.visproperties... then clear selection for the next element in array.

Eric N.
indocti discant et ament meminisse periti
 
Thanks for the replies guys!

@itsmyjob. I actually just tried this and it worked pretty well except for two things:

1. Currently I loop through the array and then in order to select the individual feature I use the search method. This works pretty well but it is not very efficient. Any suggestions on how to improve this?

2. The features I am selecting sometimes have the same name, so when I search for a certain feature I sometimes select multiple features instead of just the specific one and (re)color them. I solved this now by assigning a temporary identification code to the name of all selected features (hat is all features are renamed with a 'unique' name, then I process them (apply correct color) and when that's done I name it back to the original name (which was stored in the array. This works fine, but again doesn't seem very efficient to me and leaves me wondering if there isn't a better way...Ideas?

thanks again!

-R
 
regarding your first question: why don't you use dictionary and store the entire selection1.item(i) in it?
later you can just select that particular dictionary entry...

regards,
LWolf
 
Hmmm... I'm not yet familiar with dictionaries so I don't know how they work, but I'll look into that. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor