×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Multiple Selection but individual coloring

Multiple Selection but individual coloring

Multiple Selection but individual coloring

(OP)
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 --> VBSCRIPT

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 

RE: Multiple Selection but individual coloring

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

RE: Multiple Selection but individual coloring

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

RE: Multiple Selection but individual coloring

(OP)
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

RE: Multiple Selection but individual coloring

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

RE: Multiple Selection but individual coloring

(OP)
Hmmm... I'm not yet familiar with dictionaries so I don't know how they work, but I'll look into that. Thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources