Message 1 of 4

Not applicable
07-14-2016
01:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have the following piece of code that is not running in the order I would like it to.
It should basically change all hole settings to 'Major', run 'Analyze Interference', then changed all hole settings back to 'Tap Drill'.
But it runs 'Analyze Interference' first then changes the hole settings, I don't understand why.
I'm not sure how Sub Main works, my guess is that I should be calling the hole setting pieces of the code as Sub's, is that correct?
Sub Main ' ********** References ********* ' kThreadMajorDiameter 21761 ' kThreadMinorDiameter 21762 ' kThreadPitchDiameter 21763 ' kThreadTapDrillDiameter 21764 ' ********** Declarations iLogicVb.UpdateWhenDone = True Dim partDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument) ' Set Variable if the Current Doc Type is Part Dim assemDoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument) ' Set Variable if the Current Doc Type is Assembly ' ********** For a Component File If (partDoc IsNot Nothing) Then ' If this is a part document partDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type End If ' ********** For an Assembly File If (assemDoc IsNot Nothing)Then ' If this is an Assembly document assemDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole in the Assembly File Dim docFile As Document ' Declare a Variable for each referenced document to loop thru i = 0 For Each docFile In assemDoc.Allreferenceddocuments ' For all the documents referenced in the assembly If docFile.IsModifiable = True Then ' If the document is able to be modified Dim RefassemDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part Dim RefpartDoc As PartDocument = TryCast(docFile, PartDocument) ' Set Variable if the Current Doc Type is Assembly If (RefpartDoc IsNot Nothing) Then ' If this Doc is a Part RefpartDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type Else ' This Doc must be an assembly Dim RefAsmDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part Try RefAsmDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type Catch End Try End If End If Next End If 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) 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) Dim oResult As InterferenceResult Dim iCount As Integer iCount = 0 volume = InputBox("Set the minimum volume value (cm^3) to be excluded from the results", "Volume Threshold", "0.1") For Each oResult In oResults If oResult.Volume > volume Then iCount = iCount + 1 End If Next ' Display the results of the interference. MessageBox.Show(iCount & " Interferences found ","iLogic") iCount = 0 For Each oResult In oResults If oResult.Volume > volume Then iCount = iCount + 1 oResult.OccurrenceOne.SetRenderStyle(100609,oAsmDoc.RenderStyles.Item("Yellow")) oResult.OccurrenceTwo.SetRenderStyle(100609,oAsmDoc.RenderStyles.Item("Magenta")) 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) oResult.OccurrenceOne.AppearanceSourceType = 100612 'kPartAppearance oResult.OccurrenceTwo.AppearanceSourceType = 100612 'kPartAppearance ' End If Next ' ********** Declarations iLogicVb.UpdateWhenDone = True ' ********** For a Component File If (partDoc IsNot Nothing) Then ' If this is a part document partDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole Type End If ' ********** For an Assembly File If (assemDoc IsNot Nothing)Then ' If this is an Assembly document assemDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole in the Assembly File Dim docFile As Document ' Declare a Variable for each referenced document to loop thru i = 0 For Each docFile In assemDoc.Allreferenceddocuments ' For all the documents referenced in the assembly If docFile.IsModifiable = True Then ' If the document is able to be modified Dim RefassemDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part Dim RefpartDoc As PartDocument = TryCast(docFile, PartDocument) ' Set Variable if the Current Doc Type is Assembly If (RefpartDoc IsNot Nothing) Then ' If this Doc is a Part RefpartDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole Type Else ' This Doc must be an assembly Dim RefAsmDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part Try RefAsmDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole Type Catch End Try End If End If Next End If 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
Solved! Go to Solution.