Frame members View Reps

Frame members View Reps

suresh.r.ext
Contributor Contributor
1,049 Views
7 Replies
Message 1 of 8

Frame members View Reps

suresh.r.ext
Contributor
Contributor

hi Im trying to create view rep for each member in frame through vba or inventor rules. i have tried but assembly occurrence only created. frames are not detected in assembly occurrence .

 

image is the sample snips of frames, need your help guys.

 

image.png

0 Likes
Accepted solutions (1)
1,050 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Hi  @suresh.r.ext .

Can you supply the code your using? It is best to help you modify your code as it will help you understand the issues.

 

What might be wrong is whenever you create a view rep/activate one you need to set the occurrence visibility while looping through occurrences.

 

Syntax

Occurrance.Visible = True

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

suresh.r.ext
Contributor
Contributor
Hi ,
 
 
'create a design view representation for each unique part in the assembly 
 
'define current document
Dim openDoc As Document
openDoc = ThisDoc.Document
 
Dim oTrans As Transaction=ThisApplication.TransactionManager.StartTransaction(openDoc,"Create View Rep's")
 
Try
 
'set a reference to the assembly component definintion.
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
 
'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 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 oAsmCompDef.RepresentationsManager.DesignViewRepresentations
'set the list of names to the array list
NameList.Add(oViewRep.Name)
Next
 
'check for a Default view rep and create it if not found
If Not NameList.Contains("Default") Then
'create Default view rep 
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Default") 
oViewRep.ShowAll
oViewRep.Activate
End If
 
'zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
 
'look at all of the unique parts in the assembly
For Each docFile In openDoc.AllReferencedDocuments
If oCompDef.Occurrences.AllReferencedOccurrences(docFile).Count > 0 Then 'avoid to create a view rep for base part of derived parts
If Not docFile.componentdefinition.bomstructure = BOMStructureEnum.kPhantomBOMStructure Then
If docFile.DocumentType = 12290 Then '12290 is the part document enumurator
'locate the last backslash position in the full file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1) 
'remove path from part file name
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)         
'remove extension from part file name 
ShortName = Left(docFName,  Len(docFName) - 4)   
'check to see if the arraylist contains the desired view rep
If Not NameList.Contains(ShortName) Then
'create new View Rep 
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(ShortName)
oViewRep.Activate
oViewRep.Locked = False
Else If NameList.Contains(ShortName) Then
'reference existing View Rep 
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(ShortName) 
oViewRep.Activate
oViewRep.Locked = False
End If
Dim bSkip As Boolean=False
'look at all of the occurences
For Each oCompOcc In oCompDef.Occurrences.AllLeafOccurrences 
'locate the colon position in the occurence name
oCompOccPos = InStrRev(oCompOcc.Name, ":")
If oCompOccPos<2 Then oCompOccPos=Len(oCompOcc.Name)
'set occurence name to everything left of the colon
oOccName = Left(oCompOcc.Name, oCompOccPos -1) 
'set visible if name matches first occurence
      'If oCompOcc.Name = ShortName & ":1" And bSkip = False Then
If System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName) = ShortName  And bSkip=False Then
oCompOcc.Visible = True
ThisApplication.ActiveView.Update()
bSkip=True 'even if there is more than one occurrence named "xyz:1" in different subassys, we want only one occurence in our view rep
Else
oCompOcc.Visible = False
ThisApplication.ActiveView.Update()
End If
Next
End If
End If
'lock view rep
oViewRep.Locked = True
End If
Next
 
'set Default View Rep active
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
 
oTrans.End
 
Catch ex As Exception
MsgBox(ex.StackTrace  )'Message)
oTrans.Abort
End Try
0 Likes
Message 4 of 8

suresh.r.ext
Contributor
Contributor

@A.Acheson  Pls find the attachment for reference

 

0 Likes
Message 5 of 8

A.Acheson
Mentor
Mentor
Accepted solution

Hi @suresh.r.ext 

I reworked your original and this will give the following outcome. 

AAcheson_0-1686719739297.png

 

'create a design view representation for each unique part in the assembly 

'define current document
Dim oOpenDoc As Document = ThisDoc.Document

Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oOpenDoc,"Create View Rep's")

Try
	
	'set a reference to the assembly component definintion.
	'this assumes an assembly document is open.
	Dim oAsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

	'look at all of the components in the assembly
	Dim oCompDef As Inventor.ComponentDefinition = oOpenDoc.ComponentDefinition

	'define the first level components collection
	Dim oCompOcc As Inventor.ComponentOccurrence 

	'define view rep 
	Dim oViewRep As DesignViewRepresentation
	
	'define view reps 
	Dim oViewReps As DesignViewRepresentations = oAsmCompDef.RepresentationsManager.DesignViewRepresentations

	'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 oViewReps
		'set the list of names to the array list
		NameList.Add(oViewRep.Name)
	Next

	'check for a Default view rep and create it if not found
	If Not NameList.Contains("Default") Then
		'create Default view rep 
		oViewRep = oViewReps.Add("Default") 
		oViewRep.ShowAll
		oViewRep.Activate
	End If

	'zoom all
	ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute

	'look at all of the unique parts in the assembly
	For Each oRefDoc As Document In oOpenDoc.AllReferencedDocuments
		If oCompDef.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0 Then 'avoid to create a view rep for base part of derived parts
			If Not oRefDoc.componentdefinition.bomstructure = BOMStructureEnum.kPhantomBOMStructure Then
				If oRefDoc.DocumentType = 12290 Then '12290 is the part document enumurator
		 			Dim sShortName As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
					'check to see if the arraylist contains the desired view rep
					If Not NameList.Contains(sShortName) Then
						'create new View Rep 
						oViewRep = oViewReps.Add(sShortName)
					ElseIf NameList.Contains(sShortName) Then
						'reference existing View Rep 
						oViewRep = oViewReps.Item(sShortName) 
					End If
					
					oViewRep.Activate
					oViewRep.Locked = False
					
					Dim bSkip As Boolean = False
					'look at all of the occurences
					For Each oCompOcc In oCompDef.Occurrences.AllLeafOccurrences 
						'locate the colon position in the occurence name
						Dim oCompOccPos As Integer = InStrRev(oCompOcc.Name, ":")
						If oCompOccPos<2 Then oCompOccPos = Len(oCompOcc.Name)
						'set occurence name to everything left of the colon
						Dim oOccName As String = Left(oCompOcc.Name, oCompOccPos -1) 
						'set visible if name matches first occurence
				      	'If oCompOcc.Name = ShortName & ":1" And bSkip = False Then
						If System.IO.Path.GetFileNameWithoutExtension(oCompOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName) = sShortName  And bSkip=False Then
							oCompOcc.Visible = True
							ThisApplication.ActiveView.Update()
							bSkip = True 'even if there is more than one occurrence named "xyz:1" in different subassys, we want only one occurence in our view rep
						Else
							oCompOcc.Visible = False
							ThisApplication.ActiveView.Update()
						End If
					
					Next
					oViewRep.Locked = True
				End If
			End If
			
		End If
	
	Next

	'set Default View Rep active
	oViewReps.Item("Default").Activate

	oTrans.End

Catch ex As Exception
	MsgBox(ex.StackTrace)'Message)
	oTrans.Abort
End Try

 

 

Here is a shorter version that is working in a more target way to find  only frame generator parts.

Dim asmDoc As AssemblyDocument = ThisDoc.Document
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(asmDoc, "FG View Reps") 	

Dim viewReps As DesignViewRepresentations = asmDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations
Dim viewRep As DesignViewRepresentation

'Traverse all referenced documents		
For Each doc As Document In asmDoc.AllReferencedDocuments 
	If doc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _' Frame generator component
		AndAlso doc.DocumentType = DocumentTypeEnum.kPartDocumentObject _ 'Part
		AndAlso doc.IsModifiable _'Not read only CC/Library document
		AndAlso Not doc.DocumentInterests.HasInterest("SkeletonDoc") _'Not reference skeleton
		AndAlso asmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(doc).Count > 0 _'Exists in assembly (not derived base component)
		AndAlso Not doc.ComponentDefinition.Bomstructure = BOMStructureEnum.kPhantomBOMStructure Then
	
		Dim occ As ComponentOccurrence = asmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(doc).Item(1)
		Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(doc.FullFileName)

		'Select/Create view rep
		Try
			viewRep = viewReps(fileName)
		Catch
			viewRep = viewReps.Add(fileName)
		End Try
		
		viewRep.Activate
		viewRep.Locked = False
		viewRep.HideAll
		occ.Visible = True
		viewRep.Locked = True
		
	End If	
Next

'Create view rep
Try
	viewRep = viewReps("Default")
Catch
	viewRep = viewReps.Add("Default")
	viewRep.ShowAll
End Try

viewRep.Activate
viewRep.Locked = True

trans.End 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 8

alasdair_crawford
Contributor
Contributor

Hi, thanks for these codes, they are incredibly close to what I'm currently needing. 

The second code works perfectly for me to get views of frame members, whether I run it in the weldment assembly or in the frame assembly within that, but obviously only creates views for the frame members.

The first code works for any part in assemblies that don't have frames in, or will work in the frame assembly itself to create views for all the members, but comes up with errors when trying to run it in a weldment assembly that contains a frame. 

Is there a way to combine the two so that it will work in the top level weldment assembly and create views for all frame members and also for any other parts that are included?

 

Thanks in advance, what's already here has already been a great help!

Alasdair

0 Likes
Message 7 of 8

A.Acheson
Mentor
Mentor

Hi @alasdair_crawford 

 

If you don't want to specifically target frame generated parts then just remove those filters from the if statement. This will then target all part documents that are not read only. The start of the If statement then moves to replace the next AndAlso statement. 

 

 

'If doc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _' Frame generator component
		AndAlso doc.DocumentType = DocumentTypeEnum.kPartDocumentObject _ 'Part
		AndAlso doc.IsModifiable _'Not read only CC/Library document
		'AndAlso Not doc.DocumentInterests.HasInterest("SkeletonDoc") _'Not reference skeleton
		

 

 New filter setup

 

If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject _ 'Part
AndAlso doc.IsModifiable  Then 'Not read only CC/Library document

'DO SOMETHING HERE
End If 
		

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 8

alasdair_crawford
Contributor
Contributor

Thank you, that's working great. Really appreciate the help!