If no interference then Delete - Revit export - simplification

If no interference then Delete - Revit export - simplification

andrew_canfield
Collaborator Collaborator
628 Views
7 Replies
Message 1 of 8

If no interference then Delete - Revit export - simplification

andrew_canfield
Collaborator
Collaborator

Take an assembly made up of 100mm^3 cubes - packed together occupying 5m^3 (the size of your model to export)

 

Place your model inside the cubes.

 

Run the code which tests each cube for interference - if yes, keep the cube, no, delete the cube.

 

The result is a 'Minecraft' version of the model - this can be derived to remove seams between faces, then exported to Revit.

 

(Shrinkwrapping current models is producing too large a file, a simplifying by hand would be time consuming).

 

I wish I could code this!

 

 

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

LukeDavenport
Collaborator
Collaborator

Hi Andrew,

While I'm intrigued by the idea - and it would definitely be a fun coding project - if you had the cube size small enough to give a decent geometric representation of the shape, you'd probably have quite a lot of cube faces, making a large file size, which might end up defeating the object of the exercise. I wonder if a balance between cube size and file size would be possible?

 

Love the idea though! Tempted just to do it for fun.

Luke

0 Likes
Message 3 of 8

andrew_canfield
Collaborator
Collaborator

I guess tweaking the cube size could be an option, program creep already!

 

I've found this:

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-and-analyze-interference/td-p/3414039 

 

Which half way there..i think! 

0 Likes
Message 4 of 8

andrew_canfield
Collaborator
Collaborator

If could cycle through an assembly - turn every part red.

 

Run the code copied from before:

 

I've commented out the message box & turned all the parts yellow.

 

SyntaxEditor Code Snippet

Sub Main
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

' Add each occurrence in the assembly to the object collection.
Dim oCheckSet As ObjectCollection
oCheckSet= ThisApplication.TransientObjects.CreateObjectCollection
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmCompDef.Occurrences
oCheckSet.Add (oOcc)

'Component.Color(FullOccurrenceName(oCheckSet.oOcc)) = "Blue"
Next

' Call the AnalyzeInterference method, passing in a single' collection. This will cause it to compare everything against' everything else.
Dim oResults As InterferenceResults
oResults = oAsmCompDef.AnalyzeInterference(oCheckSet)

' Display the results of the interference.
MessageBox.Show(oResults.Count & " Interferences found ","iLogic")

Dim oResult As InterferenceResult
Dim iCount As Integer
iCount = 0
For Each oResult In oResults
iCount = iCount + 1
Component.Color(FullOccurrenceName(oResult.OccurrenceOne)) = "Yellow"
Component.Color(FullOccurrenceName(oResult.OccurrenceTwo)) = "Yellow"
'MessageBox.Show("     " & FullOccurrenceName(oResult.OccurrenceOne) & "      (colored yellow)" _'& vbLf & "interferes with " _'& vbLf & "     " & FullOccurrenceName(oResult.OccurrenceTwo) & "      (colored magenta)" _'& vbLf & "" _'& vbLf & "Volume: " & Round(oResult.Volume,5) & " cm^3", _'" Interference "& iCount)'Component.Color(FullOccurrenceName(oResult.OccurrenceOne)) = "As Material"'Component.Color(FullOccurrenceName(oResult.OccurrenceTwo)) = "As Material"

Next

End Sub

' Used to display the full path of an occurrence. This is the path of the' occurrence within the assembly structure.
Private Function FullOccurrenceName(Occ As ComponentOccurrence) As String
Dim i As Integer
For i = 1 To Occ.OccurrencePath.Count
If i = 1 Then
FullOccurrenceName = Occ.OccurrencePath.Item(i).Name
Else
FullOccurrenceName = FullOccurrenceName & "\" & Occ.OccurrencePath.Item(i).Name
End If
Next
End Function

 

Then delete all the red parts..

 

How do you cycle through an assembly, change a parts color & then delete a part which is red?

 

0 Likes
Message 5 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@andrew_canfield,

 

Try below iLogic to change color of parts in Assembly.

 

Color_Name = "Yellow"
Dim doc = ThisDoc.Document
Dim oDef As Inventor.AssemblyComponentDefinition 
oDef = doc.componentdefinition

For Each occ As Inventor.ComponentOccurrence In oDef.Occurrences.AllLeafOccurrences 
	Component.Color(occ.Name) = Color_Name
Next

Try below iLogic to delete part if part color is red.

 

Color_Name = "Red"
Dim doc = ThisDoc.Document
Dim oDef As Inventor.AssemblyComponentDefinition 
oDef = doc.componentdefinition

For Each occ As Inventor.ComponentOccurrence In oDef.Occurrences.AllLeafOccurrences 
	If Component.Color(occ.Name) = Color_Name Then
		occ.Delete()
	End If
Next

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 8

andrew_canfield
Collaborator
Collaborator

 

 

 

Thankyou.

 

 

Part inserted in red blocksPart inserted in red blocksPart inserted in red blocksPart inserted in red blocksanything with interference turned yellowanything with interference turned yellowRed blocks deleted - simple substitute next :)Red blocks deleted - simple substitute next 🙂

0 Likes
Message 7 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@andrew_canfield

 

Looks cool!!!

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 8

andrew_canfield
Collaborator
Collaborator

A slightly more rigorous test 1000 part assembly - took a while to process but the concept works.

 

Below the derived part is 26MB (LHS) & simplified blocked version 1MB (RHS)

 

Smaller cubes would improve the resolution.

 

Could someone take it further, make it faster?

 

 

 

 

b4.JPG

 

 

 

Regards

 

Andrew

0 Likes