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: 

ActiveDesignViewRepresentation how to set it?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
gerard87
2671 Views, 9 Replies

ActiveDesignViewRepresentation how to set it?

Public Sub DebugObject_b()

    Dim oDoc As Document

    Set oDoc = ThisApplication.ActiveDocument

    Dim oObj As Object

    Set oObj = oDoc.SelectSet.Item(1)

   

  Call oObj.SetDesignViewRepresentation("Default")

Call oObj.SetLevelOfDetailRepresentation("ilogic")

  Debug.Print oObj.ActiveDesignViewRepresentation

  Debug.Print oObj.ActiveLevelOfDetailRepresentation

   

End Sub

 

 

i am trying to set the ActiveDesignViewRepresentation of a selected assembly but it just doesn't set? the activelevelofdetail is setting just fine. is the ActiveDesignViewRepresentation locked? because i can't change the empty string(it becomes empty when i switch visibbility on/off) to for example a string with value "Default"


9 REPLIES 9
Message 2 of 10

Hi gerard87, 

 

Here is a link that might help. It's written in iLogic, but you can adjust for straight VB as needed. Note it has an example file set attached.

http://forums.autodesk.com/t5/Autodesk-Inventor/pos-rep-view-rep-and-ilogic/m-p/3371837

 

There is also this link that has some example code that sets the view representation in a subassembly (again using iLogic):

http://forums.autodesk.com/t5/Autodesk-Inventor/iLogic-set-Design-View-Representation-by-material/td...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


Message 3 of 10

i see that you can set a design view of the main assembly like this but i want the code to run in the main assembly but set the design views of subassemblies. is this possible? because i can do it manually by right click on a subassembly -->represenations and set it.

 

 

code to set the design view of the mian assembly:

  Dim oDoc As Document
  Set oDoc = ThisApplication.ActiveDocument
 Dim oAsmCompDef As AssemblyComponentDefinition
 Set oAsmCompDef = oDoc.ComponentDefinition
Call oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate

 

 

 

Sub designview()

''------------------------------------------------

ThisApplication = InventorVb.Application

           

Dim oDoc As Document = ThisDoc.Document

Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition

Dim oCompOcc As Inventor.ComponentOccurrence

 

For Each oCompOcc in oCompDef.Occurrences

 

      oCompOcc. ' now i want to set the design view of a subassembly here but the SetDesignViewRepresentation()

doesn't set it.

           

Next 

      RuleParametersOutput() ' use this before DocumentUpdate

      InventorVb.DocumentUpdate() ' Update now

End Sub

Message 4 of 10

Hi gerard87,

 

Try something along these lines.

 

' set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define the Component Occurrence collection
Dim oCompOcc As Inventor.ComponentOccurrence 

'set top level view rep to Default
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate

For each oCompOcc in oAsmCompDef.Occurrences
'example: 
'CompOcc.SetDesignViewRepresentation("MyViewRep", "c:\Temp\PrivateVRepFile.idv", True) oCompOcc.SetDesignViewRepresentation("Red",, True) 'True sets the view rep to be associative Next

 I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 5 of 10

hoi.

 

thnx for your help, but if i try to set the design for an occurence with:

 

oCompOcc.SetDesignViewRepresentation("Default", True)  


'The activedesignviewrepresentation string of the occurence still remains empty? it just doesn't set it?

but if i try to set the level of detail for the occurence with:

SetLevelOfDetailRepresentation("Default")

The string is set to Default.

So is there a bug in the occurences were you just can't set the design view?


Message 6 of 10

Hi gerard87,

 

Try it with 2 commas:

 

oCompOcc.SetDesignViewRepresentation("Default",, True)  

 

Tthere are 3 variables:

  • The view rep name
  • The Private view rep file (if applicable)
  • The Boolean to set the Associative option

So you if you were to set the associative option to True, then you need the extra comma. Otherwise it reads False as the Private view rep file and fails.

 

When you specify just the view rep name like this:

 

oCompOcc.SetLevelOfDetailRepresentation("Default")

 the private view rep file variable is assumed to be N/A and the associative variable is automatically set to False.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


Message 7 of 10

ha:P yes that was it that extra "," in there:P

 

many thnx

Message 8 of 10

Hi Curtis,

Why when I try it 2 commas in VBA is rejected ?? (red line)

oCompOcc.SetDesignViewRepresentation("Default",, True)

 

Thanks in advance.

Cristiano Oliveira
Developer Addins | Consultant CAD/PLM | CAD Manager
https://www.ConsultCAD.com/


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 9 of 10

As much as i struggled to understand why my code was failing i finally came up with a solution for (Inventor 2017)

 

After i created the rule, i activated it in Event Triggers to be used after Open a document.

But because this can only run in Assy mode it creates errors in DWG and IPT(Derived)

My code takes care of that below while accomplishing everything you guys wanted to do above. Hope i helped somebody.

doc = ThisDoc.ModelDocument
'check to see that its not a derived document or drawing
If Not ThisApplication.ActiveDocumentType <> 
DocumentTypeEnum.kAssemblyDocumentObject Then
		' set a reference to the assembly component definintion.
		Dim oAsmCompDef As AssemblyComponentDefinition
		oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
		'define the Component Occurrence collection
		Dim oCompOcc As Inventor.ComponentOccurrence 
		'set top level view rep to Default
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
Else
  Exit Sub
End If
Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
Message 10 of 10
KenVaessen
in reply to: DeerSpotter

I used the code

 

doc = ThisDoc.ModelDocument
'check to see that its not a derived document or drawing
If Not ThisApplication.ActiveDocumentType <> 
DocumentTypeEnum.kAssemblyDocumentObject Then
		' set a reference to the assembly component definintion.
		Dim oAsmCompDef As AssemblyComponentDefinition
		oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
		'define the Component Occurrence collection
		Dim oCompOcc As Inventor.ComponentOccurrence 
		'set top level view rep to Configurator
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Configurator").Activate
Else
  Exit Sub
End If

 

but this doesn't change the representations of my subassemblies. Can someone help me?

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

Post to forums  

Autodesk Design & Make Report