VisProperties.SetRealColor doesn't work

Eduardo Falcão

VisProperties.SetRealColor doesn't work

Hi guys,

I have stored in the [CATselec] a collection of Fill shapes. I would like to go through this collection items and change the color of each Fill. The macro ran without error, but the color wasn’t changed. Why?

 

 

 

 

'creating the circles ----------------------------------------------------------------------------------------------------------------------------
For i = 1 To 100
ReDim Preserve CAT3Dcircle(i)
Set CAT3Dcircle(i) = W3D.AddNewCircleCtrRad(Ref(i), CATplane, False, CircleRad)
HYbody.AppendHybridShape CAT3Dcircle(i)
Set Ref(i) = Cpart.CreateReferenceFromObject(CAT3Dcircle(i)) 'Change the reference to the circle
Next i
'creating the fills and add them to the selection collection --------------------------------------------------------------------------------------
For i = 1 To 100
ReDim Preserve CATfill(i)
Set CATfill(i) = W3D.AddNewFill
CATfill(i).AddBound Ref(i)
HYbody.AppendHybridShape CATfill(i)
CATselec.Add CATfill(i)
Cpart.UpdateObject CATfill(i)
Next i
'changing the collor on the selected elements -----------------------------------------------------------------------------------------------------
Dim Nselec As Selection
Set Nselec = Nselec.Selection
Nselec.Clear
For i = 1 To CATselec.Count2
Nselec.Add CATselec.Item2(i).Value
R = Int(Rnd * 255)
G = Int(Rnd * 255)
B = Int(Rnd * 255)
Nselec.VisProperties.SetRealColor R, G, B, 0
Nselec.Clear
Next i
Cpart.Update
CPdoc.Save
CATIA.Visible = True
End Sub

 

Thanks in advance

Renaud D'Andre, eng.

RE: VisProperties.SetRealColor doesn't work
(in response to Eduardo Falcão)

Hi,

I see 2 things:

  • You are using 2 selection objects, Nselec and CATselec. In my experience, that's not gonna work.
  • These lines don't make sense:

Dim Nselec As Selection
Set Nselec = Nselec.Selection

 

I would replace the CATselect with a collection to store the CATFill(i).

 

dim oCollection
Set oCollection = New Collection

[...]

CATselec.Add CATfill(i)

oCollection.add CATfill(i)

[...]

For i = 1 To CATselec.Count2

Nselec.Add CATselec.Item2(i).Value

For each oItem in oCollection

Nselec.Add oItem

[...]

Next i

next

 

In general, I stopped using "ReDim Preserve" and just use collection, easy and clean.

Hope that helps!

Renaud D'Andre, eng.

RE: VisProperties.SetRealColor doesn't work
(in response to Renaud D'Andre, eng.)

Also, I always put the inheritance at 1.

[...].VisProperties.SetRealColor R, G, B, 1