solid bodies

solid bodies

Cosmin_V
Advocate Advocate
662 Views
3 Replies
Message 1 of 4

solid bodies

Cosmin_V
Advocate
Advocate

Hi Everybody

 

I have a piece of rule I need a little help with it.

The rule should check all parts, and if the part is in "reference" then I need all solid bodies to be visible in that part.

now it turns the visibility on always.

Can this be done?

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition
	Dim oAssyDoc As AssemblyDocument
		oAssyDoc = ThisApplication.ActiveDocument
		Dim oDoc As Document = ThisDoc.Document
			For Each oDoc In oAssyDoc.AllReferencedDocuments
		        For Each SB In oDoc.ComponentDefinition.SurfaceBodies
					For Each oOcc As ComponentOccurrence In oCompDef.Occurrences.AllLeafOccurrences
						If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
							SB.Visible = True
						    End If
						If oOcc.BOMStructure <> BOMStructureEnum.kReferenceBOMStructure Then
							
						    End If
					Next
		        Next
			Next

 

0 Likes
Accepted solutions (1)
663 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor

Hi @Cosmin_V . Please try this code:

 

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
	If oOccs.AllReferencedOccurrences(oRefDoc).Count = 0 Or _
		Not oRefDoc.IsModifiable Or
		Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	Dim oPartDoc As PartDocument = oRefDoc
	Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	If oPartDef.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
		For i As Integer = 1 To oPartDef.SurfaceBodies.Count
			oPartDef.SurfaceBodies(i).Visible = True
		Next
	End If
	For Each oOcc As ComponentOccurrence In oOccs.AllReferencedOccurrences(oRefDoc)
		If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
			For i As Integer = 1 To oPartDef.SurfaceBodies.Count
				oPartDef.SurfaceBodies(i).Visible = True
			Next
		End If		
	Next
Next

 

Update.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 4

Cosmin_V
Advocate
Advocate

tanks @Andrii_Humeniuk 

 

It is almost good, what if the part it is "Normal"

But in to the assembly level it is set to be in "reference"?

0 Likes
Message 4 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

I found what the problem was. Try this code:

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
	If oOccs.AllReferencedOccurrences(oRefDoc).Count = 0 Or _
		Not oRefDoc.IsModifiable Or
		Not oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
	Dim oPartDoc As PartDocument = oRefDoc
	Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	If oPartDef.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
		For i As Integer = 1 To oPartDef.SurfaceBodies.Count
			oPartDef.SurfaceBodies(i).Visible = True
		Next
	End If
	For Each oOcc As ComponentOccurrence In oOccs.AllReferencedOccurrences(oRefDoc)
		If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
			For i As Integer = 1 To oPartDef.SurfaceBodies.Count
				oOcc.SurfaceBodies(i).Visible = True
			Next
		End If		
	Next
Next

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes