• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor

    Reply
    Mentor
    rhasell
    Posts: 194
    Registered: ‎05-23-2007
    Accepted Solution

    View Representation updates

    297 Views, 5 Replies
    04-30-2012 05:18 PM

    Hi all

     

    Info:

    I used to use "Level of detail" to hide components etc for detailing purposes, thanks to the forum, I now use "Representations"

     

    Amongs a few customised views, I have a set search for fastners.

     

    Question:

    Is there a way to automate the search (Saved search) and then switch off the visibilty of the items?

    Preferably some iLogic code?

     

    I have to run the search quite a few times during the design/detailing process, and sometimes things slip through the cracks, esp when I change fastners. (Note, All the fastners are extracted from the CC and saved with a new name and details.) It would be great to just run a rule.

     

    Thanks.

     

    Regards
    Reg

    Autodesk Product Design Suite Premium 2013 sp1.1 (1)
    Intel Core i7 (950@3.07GHz)
    Windows 7x64 (Home)
    12GB Ram
    Nvidia GeForce GTX 560 Ti (1Gig - Ver:314.07)
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: View Representation updates

    05-02-2012 07:41 AM in reply to: rhasell

    Hi rhasell,

     

    Here is a rule that will create a view rep and  turn off the visibility of components based upon a Custom iProperty value.

     

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

     

    'define View Rep name
    Dim oNewVRep as Object
    oNewVRep = "Fasteners Off"
    'define custom iProp value to look for
    Dim oComparator as Object
    oComparator = "Bolt"
    
    ' set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    Dim oViewRep As DesignViewRepresentation
    
    'Look for an existing View Rep of the same name and delete it if found
    For Each oViewRep in oAsmCompDef.RepresentationsManager.DesignViewRepresentations
    	If oViewRep.Name = "Master"  Then
    	'set the Master View Rep to be active
    	oViewRep.Activate
    	'if Master is already active, skip error
    	On error Resume Next
    	'look for same name view rep
    	Else if oViewRep.Name = oNewVRep  Then
    	'delete same name view rep if found
    	oViewRep.Delete
    	Else 
    	End if
    Next
    
    'create new View Rep
    oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(oNewVRep)      
    
    'define current document
    Dim openDoc As Document
    openDoc = ThisDoc.Document
    
    'look at all of the components in the assembly
    Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition
    'define the first level components collection
    Dim oCompOcc As Inventor.ComponentOccurrence 
    'define the next level components collection
    Dim oSubCompOcc As Inventor.ComponentOccurrence
    'Turn off the visibility of parts in the top level assembly that include a
    'custom iProp designating them as fasteners
    For each oCompOcc in oCompDef.Occurrences
    	'set visible if custom iProp does not match comparator value
    	If iProperties.Value(oCompOcc.name, "Custom", "TYPE") <> oComparator  Then
    	'Turn the visibility on
    	oCompOcc.Visible = True
    	Else
    	'Turn the visibility off
    	oCompOcc.Visible = False
    	End If
    	'Turn off the visibility of parts in the second level assembly that include a
    	'custom iProp designating them as fasteners
        	For Each oSubCompOcc In oCompOcc.SubOccurrences
    		'set visible if custom iProp does not match comparator value
    		If iProperties.Value(oSubCompOcc.name, "Custom", "TYPE") <> oComparator  Then
    		'Turn the visibility on
    		oSubCompOcc.Visible = True
    		Else
    		'Turn the visibility off
    		oSubCompOcc.Visible = False
    	End If
    
        	Next
    Next	
     


      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Mentor
    rhasell
    Posts: 194
    Registered: ‎05-23-2007

    Re: View Representation updates

    05-02-2012 04:25 PM in reply to: Curtis_Waguespack

    Thanks so much for the prompt response.

     

    I have one more addition,

    I have applied a "Custom", "TYPE" setting to all my components, (The reason for this is sorting the BOM in a sequential order.)

     

    eg

    Bolts = "BOLT"

    Nut = "NUT"

    Washer = "WASHER"

    Extrsusion = "XTR"

    Tubes = "CHS"

    etc.

     

    Can I add the additional oComparitor of "NUT" and "WASHER" to the list?

     

    I played around a bit with the code, but you have a far superior knowledge of the process, I am a noob when it comes to iLogic.

     

    Thank you.

     

    Regards
    Reg

    Autodesk Product Design Suite Premium 2013 sp1.1 (1)
    Intel Core i7 (950@3.07GHz)
    Windows 7x64 (Home)
    12GB Ram
    Nvidia GeForce GTX 560 Ti (1Gig - Ver:314.07)
    Please use plain text.
    Mentor
    rhasell
    Posts: 194
    Registered: ‎05-23-2007

    Re: View Representation updates

    05-02-2012 05:25 PM in reply to: rhasell

    Hi

     

    I am trying to attach a test assembly, but it keeps on timing out (720k)?

     

    I noticied that is does not run in the sub assemblies.

    Thanks

     

    Regards
    Reg

    Autodesk Product Design Suite Premium 2013 sp1.1 (1)
    Intel Core i7 (950@3.07GHz)
    Windows 7x64 (Home)
    12GB Ram
    Nvidia GeForce GTX 560 Ti (1Gig - Ver:314.07)
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: View Representation updates

    05-03-2012 09:56 AM in reply to: rhasell

    Hi rhasell,

     

    Here is an updated version.

     

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


     

    'create comparator list
    oStringArray = new string(){"Bolts", "Nuts", "Washers", "Extrusions", "Tubes"}
    
    'get input from user
    oList = InputListBox("Select a type", oStringArray, "Bolts", "iLogic", "Available Types")
    
    'define custom iProp value to look for
    Dim oComparator as Object
    If oList = "Bolts" Then
    oComparator = "BOLT"
    Else if oList = "Nuts" Then
    oComparator = "NUT"
    Else if oList = "Washers" Then
    oComparator = "WASHER"
    Else if oList = "Extrusion" Then
    oComparator = "XTR"
    Else if oList = "Tubes" Then
    oComparator = "CHS"
    Else
    End if
    
    'set a reference to the assembly component definintion.
    'This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    'define view rep 
    Dim oViewRep As DesignViewRepresentation
    'define view rep to use
    Dim sVRep as String
    sVRep = "Fasteners Off"
    
    'define an arraylist to hold the list of  view rep names
    Dim NameList As New ArrayList()
    
    'Look at the view reps in the assembly
    For Each oViewRep in oAsmCompDef.RepresentationsManager.DesignViewRepresentations
    'set the list of names to the array list
    NameList.add(oViewRep.Name)
    Next
    
    'check to see if the arraylist contains the desired view rep
    If Not NameList.Contains(sVRep) Then
    	'create new View Rep
    	oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(sVRep)
    	oViewRep.Activate
    Else if NameList.Contains(sVRep) Then
    	'set existing view rep active
    	oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(sVRep) 
    	oViewRep.Activate	
    End If
    
    'define current document
    Dim openDoc As Document
    openDoc = ThisDoc.Document
    
    'look at all of the components in the assembly
    Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition
    'define the first level components collection
    Dim oCompOcc As Inventor.ComponentOccurrence 
    'define the next level components collection
    Dim oSubCompOcc As Inventor.ComponentOccurrence
    
    'Turn off the visibility of parts in the top level assembly that include a
    'custom iProp designating them as fasteners
    For each oCompOcc in oCompDef.Occurrences
    
    	Try 
    	'set visible if custom iProp does not match comparator value
    	If iProperties.Value(oCompOcc.name, "Custom", "TYPE") <> oComparator  Then
    	'do nothing
    	Else
    	'Turn the visibility off
    	oCompOcc.Visible = False
    	End If
    	Catch
    	'assume error means iProperty not found	
    	End Try
    
    
    	'Turn off the visibility of parts in the second level assembly that include a
    	'custom iProp designating them as fasteners
        	For Each oSubCompOcc In oCompOcc.SubOccurrences
    	
    		Try
    		'set visible if custom iProp does not match comparator value
    		If iProperties.Value(oSubCompOcc.name, "Custom", "TYPE") <> oComparator  Then
    		'do nothing
    		Else		
    		'Turn the visibility off
    		oSubCompOcc.Visible = False
    		End If
    		Catch
    		'assume error means iProperty not found	
    		End Try
        	Next
    Next	

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Mentor
    rhasell
    Posts: 194
    Registered: ‎05-23-2007

    Re: View Representation updates

    05-03-2012 04:34 PM in reply to: Curtis_Waguespack

    Thanks for your help mate.

     

    Regards
    Reg

    Autodesk Product Design Suite Premium 2013 sp1.1 (1)
    Intel Core i7 (950@3.07GHz)
    Windows 7x64 (Home)
    12GB Ram
    Nvidia GeForce GTX 560 Ti (1Gig - Ver:314.07)
    Please use plain text.