Although the object seems to support the new asset api, when applying an appearance asset to a surfacebody that is included as client graphics for a client feature, it fails (VBA reports an internal error and the object browser confirms). Am I doing something wrong here? The code runs fine without the highlighted line. Setting the color of the surfacegraphics object works well but is not really sufficient for my purposes.
To test, have a part document open and a workpoint selected before running the vba macro.
Any suggestions appreciated.
Neil
Public Sub ClientFeat()
Dim doc As PartDocument
Set doc = ThisDocument
Dim ss As SelectSet
Set ss = doc.SelectSet
Dim wp As WorkPoint
Set wp = ss.Item(1)
Dim compDef As PartComponentDefinition
Set compDef = doc.ComponentDefinition
Dim feats As PartFeatures
Set feats = compDef.Features
Dim cfDef As ClientFeatureDefinition
Set cfDef = feats.ClientFeatures.CreateDefinition()
Call cfDef.ClientFeatureElements.Add(wp, True)
Dim cf As ClientFeature
Set cf = feats.ClientFeatures.Add(cfDef, "testClientFeature")
cf.Name = "TestClientFeature1"
Set cfDef = cf.Definition
On Error Resume Next
Dim oClientGraphics As ClientGraphics
Set oClientGraphics = cfDef.ClientGraphicsCollection.Item("TestGraphicsID")
If Err.Number = 0 Then
On Error GoTo 0
' An existing client graphics object was successfully obtained so clean up.
oClientGraphics.Delete
' update the display to see the results.
ThisApplication.ActiveView.Update
Else
Err.Clear
On Error GoTo 0
' Set a reference to the transient geometry object for user later.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
' Create the ClientGraphics object.
Set oClientGraphics = cfDef.ClientGraphicsCollection.Add("TestGraphicsID")
' Create a new graphics node within the client graphics objects.
Dim oSurfacesNode As GraphicsNode
Set oSurfacesNode = oClientGraphics.AddNode(1)
' Create transient BRep object for later use.
Dim oTransientBRep As TransientBRep
Set oTransientBRep = ThisApplication.TransientBRep
' Create a point representing the center of the sphere
Dim oCen As Point
Set oCen = oTransGeom.CreatePoint(wp.Point.X, wp.Point.Y, wp.Point.Z)
' Create a transient sphere body
Dim oBall As SurfaceBody
Set oBall = oTransientBRep.CreateSolidSphere(oCen, 1#)
' Create client graphics based on the transient body
Dim oSurfaceGraphics As SurfaceGraphics
Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBall)
' Get the Clear(Yellow) appearance asset from the part.
Dim localAsset As Asset
Set localAsset = doc.AppearanceAssets.Item("InvGen-043")
' ********************************************************
' Apply appearance to surface body (FAILS)
oSurfaceGraphics.Body.Appearance = localAsset
' ********************************************************
End If
' Update the view
ThisApplication.ActiveView.Update
End Sub
Solved! Go to Solution.
Solved by nmunro. Go to Solution.
Hi Neil,
All I can say is that this may be a hiccup in the API. When I enter 'Apperance' using Intellisense in 'oSurfaceGraphics.Body.Appearance = localAsset'
I actually get
'oSurfaceGraphics.Body.appearance = localAsset
which does not look correct..
Regards,
Roger Mitchell
IV 2014 Prof SP1
It does work, the appearance must be assigned to the GraphicsNode object containing the surface body.
Neil
Can't find what you're looking for? Ask the community or share your knowledge.