Control visibility of parts in darwing view

Control visibility of parts in darwing view

theo_bot
Advocate Advocate
2,398 Views
6 Replies
Message 1 of 7

Control visibility of parts in darwing view

theo_bot
Advocate
Advocate

Dear,

 

I'm creating a small product configurator usig ilogic. It all works fine, but i've i challange:

 

controlling the visibility of the components in a drawing view

 

In simple words, every occourense of my assembly has an custum Ipropertie calles "Positie". there where 4 values (Bodem, Zij, Kop, Deksel and Overig)

 

In a drawing view i only want to see the parts that has a spesific value of the ipropertie "Positie".

 

I found a sample code for VBA, but I cann't get it worked in ilogic.:

 


Sub HideSecond()
'Assumes you have an open drawing
'Assumes that view 1 of the active sheet is an assembly
'Turns off visibility of assembly's second component in open drawing's first view

'Get the drawing document
Dim oDrawingDocument As Inventor.DrawingDocument
Set oDrawingDocument = ThisApplication.ActiveDocument

'Get the first view
Dim oView As Inventor.DrawingView
Set oView = oDrawingDocument.ActiveSheet.DrawingViews.Item(1)

'Get the assembly document referenced by the view
Dim oAssemblyDocument As Inventor.AssemblyDocument
Set oAssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocum​ent

'Get the second component occurrence of the assembly document
Dim oSecondOccurrence As Inventor.ComponentOccurrence
Set oSecondOccurrence = oAssemblyDocument.ComponentDefinition.Occurrences.​Item(2)

'Turn off visibility of the second occurrence
oView.SetVisibility oSecondOccurrence, False
End Sub

 

 

Can someone give me a hind to turn this into ilogic and add the option to check the ipropertie to turn on the visibility

 

Kind regards,

 

theo Bot

0 Likes
Accepted solutions (1)
2,399 Views
6 Replies
Replies (6)
Message 2 of 7

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

I pasted the VBA code to iLogic. After I modified according to the error messages iLogic provides, the rule works.

 

 

'Get the drawing document
Dim oDrawingDocument As Inventor.DrawingDocument
  oDrawingDocument = ThisApplication.ActiveDocument

 

'Get the first view
Dim oView As Inventor.DrawingView
  oView = oDrawingDocument.ActiveSheet.DrawingViews.Item(1)

 

'Get the assembly document referenced by the view
Dim oAssemblyDocument As Inventor.AssemblyDocument
  oAssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument

 

'Get the second component occurrence of the assembly document
Dim oSecondOccurrence As Inventor.ComponentOccurrence


  oSecondOccurrence = oAssemblyDocument.ComponentDefinition.Occurrences.Item(2)

'Turn off visibility of the second occurrence
oView.SetVisibility (oSecondOccurrence, False)

 

Best regards,

 
autodesk_logo_signature.png

Xiaodong Liang

Developer Consultant

Autodesk Developer Technical Services

0 Likes
Message 3 of 7

Anonymous
Not applicable

Turning off the visibility of Skecthc in Occureneces in Main Assembly":::::::::::

 

Sub FzAsmOn()
Call SetVisibleOn(False)
End Sub


Private Sub SetVisibleOn(bflag)
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oOccDef As Inventor.ComponentDefinition
Set oOccDef = oDoc.ComponentDefinition
Dim oAsmDoc As Document
Dim oOcc As ComponentOccurrence

 


Dim oSks As PlanarSketches

Dim oSketch As PlanarSketch
For i = 1 To oDoc.ComponentDefinition.occurrences.Count

If oDoc.ComponentDefinition.occurrences(i).Definition.Type = kAssemblyComponentDefinitionObject Then
Set oAsmDoc = oDoc.ComponentDefinition.occurrences(i).Definition.Document

Set oSks = oAsmDoc.ComponentDefinition.Sketches
End If

For Each oSketch In oSks

oSketch.visible =  Flase

 

Next
Next

'oDoc.Update
End Sub

 

 

Can you please check the code and please let me know themodifications

 

Because Sktches are not turning off...

 

Please hve a look. and make coode to turn the sketches off.

 

Thanks.

0 Likes
Message 4 of 7

xiaodong_liang
Autodesk Support
Autodesk Support

The code looks fine to me. Did you meet any problem? Note: In default, a new assembly has not any sketches until you add it.

0 Likes
Message 5 of 7

Anonymous
Not applicable

Hello Xiaodong Liang,

 

Morning,

 

If there are any sketches in assembly, which is(assembly) as occurrence in the main assembly, those sketches are not turnign off and on.

 

Please find the attachment JPG file, Ithis is a ssample asssembly. I am writing for a machice assembly having thousands of occurrences.

 

In Assembly2:1, I wolud like to toggle sketch "Sketch 1" on and off as well as "Sketch 2" in Assembly4:1.

 

Code is runnig but the sketches are turning off and on.

 

Is there any other way to do it??? Is it possibe??

 

Let me know your openion.

 

Thenaks.

0 Likes
Message 6 of 7

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

Sketches from subassemblies are represented in the parent assembly context by their proxy objects.

That is why we should use a bit more complex procedure: 

1) get the reference to the sketch in subassembly context

2) create sketch proxy object for this sketch in the context of parent assembly

3) change visibility of this proxy object.

 

The following VBA sample illustrates this idea.

It toggles the visibility of planar sketches in all subassemblies on the first hierarchy level.

Private Sub Test_SubAssemblySketches()

  Dim oAssyDoc As AssemblyDocument
  Set oAssyDoc = ThisApplication.ActiveDocument

  Dim oAssyDef As AssemblyComponentDefinition
  Set oAssyDef = oAssyDoc.ComponentDefinition
  
  'toggle visibility of sketches in the main assembly
  Dim oSk As Sketch
  For Each oSk In oAssyDef.Sketches
    oSk.Visible = Not oSk.Visible
  Next
  
  'process all subassemblies
  Dim oOcc As ComponentOccurrence
  For Each oOcc In oAssyDef.Occurrences
    If oOcc.Definition.Type = kAssemblyComponentDefinitionObject Then
      Dim oDef As AssemblyComponentDefinition
      Set oDef = oOcc.Definition
      'toggle visibility of sketches in subassemblies
      Dim oSkProxy As PlanarSketchProxy
      For Each oSk In oDef.Sketches
        Call oOcc.CreateGeometryProxy(oSk, oSkProxy)
        oSkProxy.Visible = Not oSkProxy.Visible
      Next
    End If
  Next 'oOcc
  
End Sub 

For multi-level main assembly you should implement recursive assembly structure traversal.

You may find an article “Working with proxies through the API” in the Inventor API Help.

Best regards,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 7 of 7

Anonymous
Not applicable

Perfecto !!!!!! 

0 Likes