Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Applying asset to client feature - client graphics failure

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
nmunro
1990 Views, 2 Replies

Applying asset to client feature - client graphics failure

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

        


https://c3mcad.com

2 REPLIES 2
Message 2 of 3
rogmitch
in reply to: nmunro

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

Message 3 of 3
nmunro
in reply to: nmunro

It does work, the appearance must be assigned to the GraphicsNode object containing the surface body.

 

Neil

 

        


https://c3mcad.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report