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: 

Turn off Translucent using VBA

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
rrdeveloper
1618 Views, 9 Replies

Turn off Translucent using VBA

Hi All,

I'm trying to make a translucent part file to a opaque part file by using the below code

    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument
    oDocument.ActiveRenderStyle.Opacity = 1    'making the body opaque

 

But it doesnot help.Can someone please let me know how to do it through code.

 

PS: attached is the process of doing it manually

 

Thank You

Tags (1)
9 REPLIES 9
Message 2 of 10
JohanLarsson
in reply to: rrdeveloper

Like this?

 

Public Sub TranslucentTest()
    Dim app As Inventor.Application
    Set app = ThisApplication
    Dim partDoc As PartDocument
    Set partDoc = app.ActiveDocument
    Dim oWorkSurface As WorkSurface
    Set oWorkSurface = partDoc.ComponentDefinition.WorkSurfaces.Item(1)
    oWorkSurface.Translucent = False
   
End Sub

 

-------------------------------------------------------------------------
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Message 3 of 10
rrdeveloper
in reply to: JohanLarsson

Thank You.

I works as expected Woman Very Happy

Message 4 of 10
jalexander
in reply to: JohanLarsson

This works for part docs only, is there any way we can improve upon this to change all part surfaces in an assembly file instead of opening each part that has a surface individually?

Tags (2)
Message 5 of 10
rrdeveloper
in reply to: jalexander

Public Sub TranslucentTest()
      Dim app As Inventor.Application
      Set app = ThisApplication
        Dim oModel As AssemblyDocument
        Set oModel = ThisApplication.ActiveDocument '.iam file
        'or open the assembly file as below
        'Set oModel = ThisApplication.Documents.Open("D:\TestAssm.iam", False)
       'then identify each part in the assembly & set the surface to opaque
      Dim partDoc As PartDocument
      For i = 1 To oModel.ComponentDefinition.Occurrences.Count
       Set partDoc = oModel.ComponentDefinition.Occurrences.Item(i).Definition.Document
        Dim oWorkSurface As WorkSurface
        Set oWorkSurface = partDoc.ComponentDefinition.WorkSurfaces.Item(1)
        oWorkSurface.Translucent = False
       Next
  
End Sub

 

////////////////

The above code identifies each part in the assembly & changes its surface

Hope this helps

Message 6 of 10
dwweekly
in reply to: rrdeveloper

I tried it,

I have inventor 2012

 got an error

 

Runtime error '-2147467259 (80004005)':

Method 'Item' of object 'WorkSurfaces' failed

 

it highlighted

Set oWorkSurface = partDoc.ComponentDefinition.WorkSurfaces.Item(1)

 

any suggestions?

Message 7 of 10
dwweekly
in reply to: dwweekly

I found that it does not work in multiple sub assemblies, is there a change in code to go down thru multiple assemblies?
Message 8 of 10
dwweekly
in reply to: dwweekly

also it hangs on solid models...I think
Message 9 of 10

Hi,

 

Please find my code with recursive functionality.

 

Public Sub TranslucentToOpaqueAllParts()
    Dim app As Inventor.Application
    Set app = ThisApplication
    Dim oModel1 As AssemblyDocument
    Set oModel1 = ThisApplication.ActiveDocument
    
    TranslucentToOpaqueAllPartsRecurcivePart oModel1
End Sub
Private Sub TranslucentToOpaqueAllPartsRecurcivePart(oModel As AssemblyDocument)
    Dim partDoc As Document
        For i = 1 To oModel.ComponentDefinition.Occurrences.Count
            Set partDoc = oModel.ComponentDefinition.Occurrences.Item(i).Definition.Document
                If partDoc.DocumentType = kPartDocumentObject Then
                    Dim oWorkSurface As WorkSurface
                    Set oWorkSurface = partDoc.ComponentDefinition.WorkSurfaces.Item(1)
                    oWorkSurface.Translucent = False
                Else
                    changeInIamToOpaque partDoc
                End If
        Next
End Sub

 

 

Message 10 of 10
Stooie
in reply to: sebastien.forman

Obvious, Itinerant every surface.

 

Public Sub TranslucentToOpaqueAllParts()
Dim app As Inventor.Application
Set app = ThisApplication
Dim oModel1 As AssemblyDocument
Set oModel1 = ThisApplication.ActiveDocument

TranslucentToOpaqueAllPartsRecurcivePart oModel1
End Sub
Private Sub TranslucentToOpaqueAllPartsRecurcivePart(oModel As AssemblyDocument)
Dim partDoc As Document
For i = 1 To oModel.ComponentDefinition.Occurrences.Count
Set partDoc = oModel.ComponentDefinition.Occurrences.Item(i).Definition.Document
If partDoc.DocumentType = kPartDocumentObject Then
Dim oWorkSurface As WorkSurface
For Each oWorkSurface In partDoc.ComponentDefinition.WorkSurfaces
oWorkSurface.Translucent = False
Next
Else
'changeInIamToOpaque partDoc
End If
Next
End Sub

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

Post to forums  

Autodesk Design & Make Report