Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 531

Client feature visibility in design view representa​tions

$
0
0

By Xiaodong Liang

Question:
I have an assembly with a client feature that contains client graphics. I have exposed the visibility (ClientFeature.Definition.ClientGraphicsCollection​[1].Visible) to the user via a context menu option. Changing the visibility currently affects all view representations. Is there a way to associate the visibility with each design view representation?

Solution:
Client Feature is API specific. UI does not know it. So the default mechanism of design view representation does not cover the feature. But you can control this by RepresentationEvents. OnActivateDesignView. The following is a demo VBA, including a macro which creates the client feature.

 

‘****module: create client feature ************

Sub CGInClientFeatureTest()

Dim oDoc As AssemblyDocument

Set oDoc = ThisApplication.ActiveDocument

 

‘create client feature definition

Dim oClientFeatureDef As ClientFeatureDefinition

Set oClientFeatureDef = oDoc.ComponentDefinition.Features.ClientFeatures.CreateDefinition("ClientFeatureTest")

 

‘create client feature

Dim oClientFeature As ClientFeature

Set oClientFeature = oDoc.ComponentDefinition.Features.ClientFeatures.Add(oClientFeatureDef, "ClientIDString")

 

‘create graphics for client feature

Dim oCGCol As ClientGraphicsCollection

Set oCGCol = oClientFeatureDef.ClientGraphicsCollection

 

Dim oCG As ClientGraphics

On Error Resume Next

Set oCG = oCGCol.Item("CGWithCF")

If oCG Is Nothing Then

Set oCG = oCGCol.Add("CGWithCF")

End If

 

‘create node

Dim oSurfacesNode As GraphicsNode

Set oSurfacesNode = oCG.AddNode(1)

 

Dim oTransientBRep As TransientBRep

Set oTransientBRep = ThisApplication.TransientBRep

 

' Create a point representing the center of the bottom of the cone

Dim oBottom As Point

Set oBottom = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)

 

' Create a point representing the tip of the cone

Dim oTop As Point

Set oTop = ThisApplication.TransientGeometry.CreatePoint(0, 10, 0)

 

' Create a transient cone body

Dim oBody As SurfaceBody

Set oBody = oTransientBRep.CreateSolidCylinderCone(oBottom, oTop, 5, 5, 0)

 

' Reset the top point indicating the center of the top of the cylinder

Set oTop = ThisApplication.TransientGeometry.CreatePoint(0, -40, 0)

 

' Create a transient cylinder body

Dim oCylBody As SurfaceBody

Set oCylBody = oTransientBRep.CreateSolidCylinderCone(oBottom, oTop, 2.5, 2.5, 2.5)

 

' Union the cone and cylinder bodies

Call oTransientBRep.DoBoolean(oBody, oCylBody, kBooleanTypeUnion)

 

' Create client graphics based on the transient body

Dim oSurfaceGraphics As SurfaceGraphics

Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)

 

ThisApplication.ActiveView.Update

End Sub

 

‘*******module: start/stop RepresentationEvents event*******

Dim oCls As clsREvents

Sub startE()

    Set oCls = New clsREvents

End Sub

 

Sub stopE()

    Set oCls = Nothing

End Sub

 

‘*****Class: RepresentationEvents**************

Private WithEvents ReEvts As RepresentationEvents

 

Private Sub Class_Initialize()

   

    Set ReEvts = ThisApplication.RepresentationEvents

End Sub

 

Private Sub Class_Terminate()

    Set ReEvts = Nothing

End Sub

 

 

Private Sub ReEvts_OnActivateDesignView(ByVal DocumentObject As Document, ByVal Representation As DesignViewRepresentation, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)

 

    Dim oDoc As AssemblyDocument

Set oDoc = ThisApplication.ActiveDocument

 

‘get Client Feature

    Dim oClientFeature As ClientFeature

Set oClientFeature = oDoc.ComponentDefinition.Features.ClientFeatures(1)      

    

  If Representation.Name = "Master" Then

oClientFeature.Definition.ClientGraphicsCollection(1).Visible = kAllGraphicsVisible

  End If

 

  If Representation.Name = "View1" Then

oClientFeature.Definition.ClientGraphicsCollection(1).Visible = kNoGraphicsVisible

  End If 

 

End Sub

Untitled


Viewing all articles
Browse latest Browse all 531

Trending Articles