Hello,
Is it possible, via VB, to modify solidbodies color ?
Actually, I need to modify part color. But in some cases, the part color and the solidbody color are not the same. So I need to modify the Solidbody color, to match the part color.
I found the bodies in ComponentDefinition.SurfaceBodies, but I can't find something like ComponentDefinition.SurfaceBodies.Item(1).color.
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
Dim oPartDoc As Inventor.PartDocument Set oPartDoc = ThisApplication.ActiveDocument Dim oPartDef As PartComponentDefinition Set oPartDef = oDoc.ComponentDefinition Dim oBody As SurfaceBody Set oBody = oPartDef.SurfaceBodies.Item(1) Dim ors As RenderStyle Set ors = oPartDoc.RenderStyles.Item("RED") Call oBody.SetRenderStyle(kOverrideRenderStyle, ors)
Try this
Public Sub SetBodyColor() Dim partDoc As PartDocument Set partDoc = ThisApplication.ActiveDocument Dim body As SurfaceBody For Each body In partDoc.ComponentDefinition.SurfaceBodies ' Get the Autodesk Material Library. Dim lib As AssetLibrary Set lib = ThisApplication.AssetLibraries.item("AD121259-C03E-4A1D-92D8-59A22B4807AD") ' Randomly generate an index for an item within the libary. Dim index As Long index = Int((lib.AppearanceAssets.Count * Rnd) + 1) ' Get the random appearance. Dim libAppearance As Asset Set libAppearance = lib.AppearanceAssets.item(index) ' Get the local version of the appearance, if it exists. Dim localAppearance As Asset On Error Resume Next Set localAppearance = partDoc.AppearanceAssets.item(libAppearance.Name) If Err.Number <> 0 Then ' Copy the asset into the part. Set localAppearance = libAppearance.CopyTo(partDoc) End If On Error GoTo 0 ' Assign the appearance to the body. body.appearance = localAppearance Next End Sub
The previous post will work. The previous RenderStyle API is no longer officially supported as of Inventor 2014, but it does continue to work. If you want to use the new appeaerances, the sample below illustrates that.