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: 

iLogic View Representation

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
phillip.shields
6736 Views, 16 Replies

iLogic View Representation

I have several assemblies that have invisible parts in them. When I place these assemblies into a parent assembly and toggle the visability off/on my invisible parts show up. Is there an iLogic code I could run that would activate the default view representation in all of those assemblies instead of the default "Master" view rep? Here is the code I've written so far:

 

Dim aDoc As AssemblyDocument


aDoc = ThisApplication.ActiveDocument


Dim iDoc As Document


For Each iDoc In aDoc.AllReferencedDocuments


Dim ocompdef As ComponentDefinition


ocompdef = iDoc.ComponentDefinition

 

ocompdef.RepresentationsManager.DesignViewRepresentations.Item("TEST").Activate


Next

 

Any help would be greatly appreciated.I've also attached photos

16 REPLIES 16
Message 2 of 17

Hi,

 

"SetDesignViewRepresentation" works for setting occurance view in an assembly.

 

Dim doc as AssemblyDocument = ThisDoc.Document  
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence

For Each oCompOcc in oAsmCompDef.Occurrences
oCompOcc.SetDesignViewRepresentation("Default", True)
Next

ThisApplication.ActiveView.Fit
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 3 of 17

Thank you very much that is exactly what I'm looking for.

Message 4 of 17

As a follow up, that code worked for a while but infrequently I get this error message.1.png

Message 5 of 17
jtylerbc
in reply to: phillip.shields


@atotiace wrote:

As a follow up, that code worked for a while but infrequently I get this error message.



I took a look at this code because it seemed similar to something I've been looking for a way to do.  I think you are seeing that error message because the view representation you are trying to set doesn't exist in some of the files.

 

In particular, the code that Carthik_Babu provided references the "Default" view representation.  There is a Default view rep in assemblies, but there is not a representation by that name in part files unless you have created it yourself.

Message 6 of 17
jtylerbc
in reply to: Carthik_Babu

Carthik_Babu,

 

How is your code intended to work?

 

I have been looking for a way to set all components in an assembly to a particular view representation and set them as Associative.  When I was first looking at your posted code, I thought that was what it would do, but my results were different.

 

Instead, what I actually seem to be getting is that the components get an assembly-level appearance override that matches the color of the target view representation, but the representation of the component actually gets set to Master.  Is that the way this is supposed to behave?

 

FYI, I'm still running Inventor 2013 here.  If this is something that doesn't work properly without 2014 I can just wait to implement it until our next upgrade

Message 7 of 17
phillip.shields
in reply to: jtylerbc

I using inventor 2012 and this code is supposed to take all subassemblies that are set to "Master" and set them to be "Default". I have a lot of invisible parts in my assemblies therefore when the subassemblies get set to "Master" they show all parts even the invisible ones. I found a fix to the error message I was getting because I think you're right when it found a part file it will try to set it to "Default" view rep even when one doesn't exist in the part file. 

 

Dim doc As AssemblyDocument = ThisDoc.Document  
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc in oAsmCompDef.Occurrences
oCompOcc.SetDesignViewRepresentation("Default",, True)
On Error Resume Next
Next

ThisApplication.ActiveView.Fit


Message 8 of 17
jtylerbc
in reply to: phillip.shields

Not sure why, but this message posted blank at first.  Hopefully this time it will work.

 

I was trying to modify the code to accomplish something I've been looking for a way to do for a while.  It almost (but not quite) worked, which is what my questions were regarding.  While trying to do so, I changed the name of the view rep in the code to my intended one, and the error went away.

 

If you actually need your code to set assemblies to Default and parts to Master, you could use an If/Then to check whether the component is an assembly or part file, and set the view rep accordingly.

Message 9 of 17
philshields05
in reply to: jtylerbc

I ran into this problem again some months later and you're right you need to distinguish between "Part" and "Assembly" occurences therefore I came up with the following code:

 

Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As ComponentDefinition  
oAsmCompDef = aDoc.ComponentDefinition 
Dim oCompOcc As Inventor.ComponentOccurrence
Dim iDoc As Document
For Each iDoc In aDoc.AllReferencedDocuments

If iDoc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Then 
	
		oCompOcc.SetDesignViewRepresentation("Default", True)

Else

End If

On Error Resume Next
Next

ThisApplication.ActiveView.Fit

 Let me know if this helps you out any.

Message 10 of 17

Not sure if you needed this still but I finally figured out how to properly distinguish between a component occurence subassembly and part(it also makes sure the components that are visible get changed to "default" and not the ones I've made invisible or "suppressed"):

 

Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
oAsmCompDef = doc.ComponentDefinition

For Each oCompOcc in oAsmCompDef.Occurrences

	If oCompOcc.Visible = True Then
	
		If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
		
			oCompOcc.SetDesignViewRepresentation("Default", True)

		Else

		End If
	
	Else
	
	End If

On Error Resume Next

Next

 

Message 11 of 17
jR0sal3s
in reply to: philshields05

i tried to copy and paste your code in a vba environment (Inventor 2017)...it has issues with "oCompOcc.SetDesignViewRepresentation("Default", True)"

...?

Message 12 of 17
jR0sal3s
in reply to: jR0sal3s

Finally...tweak it a bit to run in VBA environment..well at least for anybody, who may still find this useful...

 

Public Sub test_VRSubComponent()

Dim aDoc As AssemblyDocument
Set aDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
Set oAsmCompDef = aDoc.ComponentDefinition


For Each oCompOcc In oAsmCompDef.Occurrences

If oCompOcc.Visible = True Then

If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then


Call oCompOcc.SetDesignViewRepresentation("SH - MB", , True)


Else

End If

Else

End If

On Error Resume Next

Next


End Sub

Message 13 of 17
jR0sal3s
in reply to: jR0sal3s

Finally...tweak it a bit to run in VBA environment..well at least for anybody, who may still find this useful...

 

Public Sub test_VRSubComponent()

Dim aDoc As AssemblyDocument
Set aDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
Set oAsmCompDef = aDoc.ComponentDefinition


For Each oCompOcc In oAsmCompDef.Occurrences

If oCompOcc.Visible = True Then

If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then


Call oCompOcc.SetDesignViewRepresentation("SH - MB", , True)


Else

End If

Else

End If

On Error Resume Next

Next


End Sub

Message 14 of 17
RoyWickrama_RWEI
in reply to: jR0sal3s

Your code was helpful. Thanks.

It does well, I suggest you accept it as a solution. It will be highlighted with the green border and more viewers look at it.

Message 15 of 17
jR0sal3s
in reply to: RoyWickrama_RWEI

Thanks. But i couldnt

Message 16 of 17
jR0sal3s
in reply to: RoyWickrama_RWEI

Thanks. But i couldnt nad m glad it helps somehow

Message 17 of 17

'Representation op Configurator en associative 
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
oAsmCompDef = doc.ComponentDefinition
For Each oCompOcc In oAsmCompDef.Occurrences
If oCompOcc.Visible = True Then
If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
oCompOcc.SetDesignViewRepresentation("Default",, True)
Else
End If
Else
End If
On Error Resume Next
Next
ThisApplication.ActiveView.Fit

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

Post to forums