Change part to (bleu) clear

Change part to (bleu) clear

Anonymous
Not applicable
420 Views
11 Replies
Message 1 of 12

Change part to (bleu) clear

Anonymous
Not applicable
In an assy I frequently put parts as a clear color like blue (clear).
Anyone having a macro to do that just by selecting the parts and then click on the macro or so?
0 Likes
421 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Something like the following? (Select the occurrences in the assembly to
change the color of, and run the macro)...

Sub OccurrenceColor()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oOccurrences As ObjectCollection
Set oOccurrences =
ThisApplication.TransientObjects.CreateObjectCollection

Dim oOcc As ComponentOccurrence

For Each oOcc In oDoc.SelectSet
oOccurrences.Add oOcc
Next

Dim oRS As RenderStyle
Set oRS = oDoc.RenderStyles.Item("Blue (Clear)")
For Each oOcc In oOccurrences
Call oOcc.SetRenderStyle(kOverrideRenderStyle, oRS)
Next

End Sub

wrote in message news:5245890@discussion.autodesk.com...
In an assy I frequently put parts as a clear color like blue (clear).
Anyone having a macro to do that just by selecting the parts and then click
on the macro or so?
0 Likes
Message 3 of 12

Anonymous
Not applicable
It probably doesn't work in IV10 no? I get the 438 error.
Object doesn't support this property or methode.

I will check later in IV11, thanks already for the quick reply!
0 Likes
Message 4 of 12

Anonymous
Not applicable
Ah, yes ,that code will only work in R11. For R10, try replacing the
following line of code:

Call oOcc.SetRenderStyle(kOverrideRenderStyle, oRS)

with

oOcc.RenderStyle = oRS

Sanjay-


wrote in message news:5247083@discussion.autodesk.com...
It probably doesn't work in IV10 no? I get the 438 error.
Object doesn't support this property or methode.

I will check later in IV11, thanks already for the quick reply!
0 Likes
Message 5 of 12

Anonymous
Not applicable
YES! that did it!
I'll make it more advanced now by adding a form where I can select the style. Something like 2 clear colors and the as material for instance.

This makes my work again a little faster, so I can spend more time at the cofee machine!
0 Likes
Message 6 of 12

Anonymous
Not applicable
Ok,
I added a form and some colors to it.
Now the strange thing is I can add as much colors as I whant. But "As Material" never works! It debugs!
What's the reason?

Private Sub CmdChange_Click()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oOccurrences As ObjectCollection
Set oOccurrences = ThisApplication.TransientObjects.CreateObjectCollection

Dim oOcc As ComponentOccurrence

For Each oOcc In oDoc.SelectSet
oOccurrences.Add oOcc
Next

Dim oRS As RenderStyle

If opbBlueClear = True Then
Set oRS = oDoc.RenderStyles.Item("Blue (Clear)")
Else
If opbGreenClear = True Then
Set oRS = oDoc.RenderStyles.Item("Green (Clear)")
Else
Set oRS = oDoc.RenderStyles.Item("As Material")
End If
End If

For Each oOcc In oOccurrences
oOcc.RenderStyle = oRS
Next

End Sub

Message was edited by: Stefaan Boel Message was edited by: Stefaan Boel
0 Likes
Message 7 of 12

Anonymous
Not applicable

Change to

Set oOcc.SetRenderStyle(kPartRenderStyle)

Wayne
0 Likes
Message 8 of 12

Anonymous
Not applicable
Try this.

< Set oRS = oDoc.RenderStyles.Item("As Material")

Change to

Set oRS = oOcc.SetRenderStyle(kPartRenderStyle)

Wayne
0 Likes
Message 9 of 12

Anonymous
Not applicable
The equivalent to this in R10 is:

Set oOcc.RenderStyle = Nothing

When you set the color of an occurrence you're overriding the color defined
in the part. This is removing the override so it goes back to the part
color.
--
Brian Ekins
Autodesk Inventor API


wrote in message news:5250314@discussion.autodesk.com...
Try this.

< Set oRS = oDoc.RenderStyles.Item("As Material")

Change to

Set oRS = oOcc.SetRenderStyle(kPartRenderStyle)

Wayne
0 Likes
Message 10 of 12

Anonymous
Not applicable
Sorry wayne, still using IV10, thx anyway!
Brian,
I had to remove the Set to make it work.
So it becomes:
For Each oOcc In oOccurrences
oOcc.RenderStyle = Nothing
Next

If I keep set, it doesn't work

regards,
Stefaan
0 Likes
Message 11 of 12

Anonymous
Not applicable
The use of the Set keyword is somewhat inconcistent. The general rule is
whenever you are assigning something to an object you need to use Set.
That's one of the nice features of VB.Net is that Set is no longer used.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 12 of 12

Anonymous
Not applicable
Brian,
Could you give any info on this topic:

http://discussion.autodesk.com/thread.jspa?messageID=5251777⋁

Thanks
Wayne
0 Likes