Inventor Customization

Inventor Customization

Reply
Valued Contributor
theo.bot
Posts: 65
Registered: ‎09-30-2005
Message 1 of 7 (660 Views)
Accepted Solution

Control visibility of parts in darwing view

660 Views, 6 Replies
09-16-2011 03:30 AM

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

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,

ADN Support Specialist
xiaodong.liang
Posts: 1,301
Registered: ‎06-12-2011
Message 2 of 7 (646 Views)

Re: Control visibility of parts in darwing view

09-16-2011 11:54 AM in reply to: theo.bot

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Distinguished Contributor
ADNpati
Posts: 126
Registered: ‎07-01-2012
Message 3 of 7 (514 Views)

Re: Control visibility of parts in darwing view

10-14-2012 06:50 PM in reply to: xiaodong.liang

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.

Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------
ADN Support Specialist
xiaodong.liang
Posts: 1,301
Registered: ‎06-12-2011
Message 4 of 7 (497 Views)

Re: Control visibility of parts in darwing view

10-19-2012 02:06 AM in reply to: theo.bot

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.



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Distinguished Contributor
ADNpati
Posts: 126
Registered: ‎07-01-2012
Message 5 of 7 (486 Views)

Re: Control visibility of parts in darwing view

10-21-2012 03:05 PM in reply to: xiaodong.liang

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.

Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------
ADN Support Specialist
Vladimir.Ananyev
Posts: 491
Registered: ‎08-14-2012
Message 6 of 7 (462 Views)

Re: Control visibility of parts in darwing view

10-30-2012 01:19 AM in reply to: ADNpati

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

Distinguished Contributor
ADNpati
Posts: 126
Registered: ‎07-01-2012
Message 7 of 7 (453 Views)

Re: Control visibility of parts in darwing view

10-30-2012 01:47 PM in reply to: Vladimir.Ananyev

Perfecto !!!!!! 

Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.