Autodesk Ilogic view reps by material

Autodesk Ilogic view reps by material

DClunie
Contributor Contributor
353 Views
0 Replies
Message 1 of 1

Autodesk Ilogic view reps by material

DClunie
Contributor
Contributor

Hi All

 

i Am after help to create viewreps based on inventor material types .In the past i have posted some messages with some results but not quite doing what i want.

 

I am after a way of automating our viewrep stds what our company passes across to our dwgs so that we can speed up our process.

 

Brief description of what is needed

 

  1. Find all .ipts down all levels af assemblies
  2. We need to look for the following materials   ( "Timber " , "Pvcu" ,"Mdf" , "Mfc" , "steel") 
  3. When code finds all parts it turns off all parts that are not specified by search (or isolate any part with material type found)
  4. Create view rep called ("Common")
  5. Lock viewrep
  6. Return to Default view rep

I am a very basic learner on code and we have been given a lot of code by others that are willing to help but this task is beyond me.Attached is some great code that was written for me to do a very similar thing and  it creates view reps by a custom property called "DESC2".

 

This code works a treat for me but i would not know where to start to convert to what i need.

 

 

Any help on this will be appreciated

 

Sub Main
Dim propertyName As String = "DESC2"
Dim propertyValue As String = "BEVEL/"
Dim propertyValue2 as String = "ROUT/WRAP/"
Dim propertyValue3 as String = "ROUT/"
Dim propertyValue4 as String = "NOTCH/"
Dim propertyValue5 as String = "HP/"
Dim propertyValue6 as String = "HINGE/"
Dim propertyValue7 as String = "SLOT/"
Dim propertyValue8 as String = "ROUT/WRAP/HINGE/"


Dim oDoc As Inventor.AssemblyDocument
	oDoc = ThisApplication.ActiveDocument
	
Dim oCompDef As Inventor.ComponentDefinition
	oCompDef = oDoc.ComponentDefinition

'define view rep 
Dim oViewRep As DesignViewRepresentation
'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 oCompDef.RepresentationsManager.DesignViewRepresentations
	'set the list of names to the array list
	NameList.add(oViewRep.Name)
Next

Dim oCompOcc as ComponentOccurrence
Dim oCompOcc2 as ComponentOccurrence
	For Each oCompOcc In oCompDef.Occurrences
		If oCompOcc.SubOccurrences.Count = 0 Then
		'[
		Try
			OCompOccName = oCompOcc.Name
			If iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue2 _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue3 _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue4 _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue5 _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue6 _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue7 _
			Or iProperties.Value(oCompOccName ,"Custom",propertyName ) = propertyValue8 Then
				'check for a Test view rep and create it if not found
				If Not NameList.Contains(OCompOccName) Then
					'create Test view rep 
					oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Add(OCompOccName) 
					oViewRep.ShowAll
					oViewRep.Activate
				Else
					'reference existing View Rep 
					oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Item(OCompOccName) 
					oViewRep.Activate
					oViewRep.Locked = False
					oViewRep.ShowAll
				End If
				For Each oCompOcc2 In oCompDef.Occurrences
					Dim oCompOcc2Name As String
					oCompOcc2Name = oCompOcc2.Name
					If oCompOcc2.SubOccurrences.Count = 0 Then
						If oCompOcc2Name = oCompOccName Then
						oCompOcc2.Visible = True
						'MessageBox.Show(oCompOcc2Name, "Visible")
						ThisApplication.ActiveView.Update()
						Else
						oCompOcc2.Visible = False
						'MessageBox.Show(oCompOcc2Name, "Not Visible")
						ThisApplication.ActiveView.Update()
						End If
					Else
					    processSubOcc(oCompOcc2, oCompOccName)
					End If
				Next
				'lock view rep
				oViewRep.Locked = True
				'messagebox.Show("View locked", "Done")
			End If
		Catch ex As exception
		End Try
		']
		Else
		processAllSubOcc(oCompDef, oCompOcc, NameList, propertyName, propertyValue, propertyValue2, propertyValue3, propertyValue4, propertyValue5, propertyValue6, propertyValue7, propertyValue8 )
		End If
	Next
	'Master
oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default")
oViewRep.Activate
End Sub

' This function is called for processing sub assembly. It is called recursively
' to iterate through the entire assembly tree.
 Sub processAllSubOcc(ByVal oCompDef as ComponentDefinition, ByVal oCompOcc As ComponentOccurrence, ByVal NameList As ArrayList, ByRef propertyName As String,ByRef propertyValue As String, ByRef propertyValue2 as String,ByRef propertyValue3 as String,ByRef propertyValue4 as String,ByRef propertyValue5 as String,ByRef propertyValue6 as String,ByRef propertyValue7 as String,ByRef propertyValue8 as String)
    Dim oSubCompOcc As ComponentOccurrence

	For Each oSubCompOcc In oCompOcc.SubOccurrences
		If oSubCompOcc.SubOccurrences.Count = 0 Then
		'[
		Try
			oSubCompOccName = oSubCompOcc.Name
			If iProperties.Value(oSubCompOccName ,"Custom",propertyName ) = propertyValue Or iProperties.Value(oSubCompOccName ,"Custom",propertyName ) = propertyValue2 Then
				'check for a Test view rep and create it if not found
				If Not NameList.Contains(OSubCompOccName) Then
					'create Test view rep 
					oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Add(OSubCompOccName) 
					oViewRep.ShowAll
					oViewRep.Activate
				Else
					'reference existing View Rep 
					oViewRep = oCompDef.RepresentationsManager.DesignViewRepresentations.Item(OSubCompOccName) 
					oViewRep.Activate
					oViewRep.Locked = False
					oViewRep.ShowAll
				End If
				For Each oCompOcc2 In oCompDef.Occurrences
					Dim oCompOcc2Name As String
					oCompOcc2Name = oCompOcc2.Name
					If oCompOcc2.SubOccurrences.Count = 0 Then
						If oCompOcc2Name = oSubCompOccName Then
						oCompOcc2.Visible = True
						ThisApplication.ActiveView.Update()
						Else
						oCompOcc2.Visible = False
						ThisApplication.ActiveView.Update()
						End If
					Else
					    processSubOcc(oCompOcc2, oSubCompOccName)
					End If
				Next
				'lock view rep
				oViewRep.Locked = True
			End If
		Catch ex As exception
		End Try
		']
		Else
		processAllSubOcc(oCompDef, oCompOcc, NameList, propertyName, propertyValue, propertyValue2, propertyValue3, propertyValue4, propertyValue5, propertyValue6, propertyValue7, propertyValue8)
		End If
	Next
	
End Sub

 Sub processSubOcc(ByVal oCompOcc As ComponentOccurrence, _
                             ByRef oCompOccName As String)
    Dim oSubCompOcc As ComponentOccurrence

    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
		Dim oSubCompOccName As String
		oSubCompOccName = oSubCompOcc.Name
        If oSubCompOcc.SubOccurrences.Count = 0 Then
			If oSubCompOccName = oCompOccName Then
			oSubCompOcc.Visible = True
			ThisApplication.ActiveView.Update()
			Else
			oSubCompOcc.Visible = False
			ThisApplication.ActiveView.Update()
			End If
		Else
        	processSubOcc(oSubCompOcc, oCompOccName)
		End If
    Next
End Sub 

 

 

0 Likes
354 Views
0 Replies
Replies (0)