Measure distance between faces with attributes in a Assembly, problem????

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
HI everyone!
Hi have a assembly with several sub-assemblys , the sub-assemblys contain a assembly called a "Suporte rolos sup".
for example:
subassembly 1
- subassembly 1
- Suporte rolos sup
subassembly 2
- Suporte rolos sup
- subassembly 2
the assembly "Suporte rolos sup", has a attribute in a face.
so for every assembly "Suporte rolos sup" in the main assembly , i want to measure the distance between the face that has that attribute.
I'm trying to do that with the code bellow but the following error:
-run time error '5'
-invalide procedure,call or argument
is displayed in the line" Distance = ThisApplication.MeasureTools.GetMinimumDistance(oface1, oface2)"
Option explicit
Dim oface1 As Face
Dim oface2 As Face
Private Sub calc_esp_entre_estacoes()
Dim odoc As Inventor.Document
Set odoc = ThisApplication.ActiveDocument
Dim odoc_ass As Inventor.AssemblyDocument
If odoc.DocumentType = kAssemblyDocumentObject Then
Set odoc_ass = odoc
Else
MsgBox "O documento is not a assembly"
Exit Sub
End If
For i = 1 To odoc_ass.ComponentDefinition.Occurrences.Count
Dim Pos
Pos = InStr(odoc_ass.ComponentDefinition.Occurrences(i).Name, "Suporte rolos sup")
If Pos <> 0 Then
Dim odoc_atrib As Inventor.Document
Set odoc_atrib = odoc_ass.ComponentDefinition.Occurrences(i).Definition.Document
Call GetAttributeUsingManager(odoc_atrib)
End If
If odoc_ass.ComponentDefinition.Occurrences(i).DefinitionDocumentType = kAssemblyDocumentObject Then
Call subocc(odoc_ass.ComponentDefinition.Occurrences(i).Definition.Document)
End If
Next i
End Sub
Public Sub subocc(odoc As Inventor.AssemblyDocument)
Dim i As Integer
Dim Pos
Dim subdoc As Inventor.AssemblyDocument
For i = 1 To odoc.ComponentDefinition.Occurrences.Count
Pos = InStr(odoc.ComponentDefinition.Occurrences(i).Name, "Suporte rolos sup")
If Pos <> 0 Then
Dim odoc_atrib As Inventor.Document
Set odoc_atrib = odoc.ComponentDefinition.Occurrences(i).Definition.Document
Call GetAttributeUsingManager(odoc_atrib)
End If
If odoc.ComponentDefinition.Occurrences(i).DefinitionDocumentType = kAssemblyDocumentObject Then
Set subdoc = odoc.ComponentDefinition.Occurrences(i).Definition.Document
Call subocc(subdoc)
End If
Next i
End Sub
Public Sub GetAttributeUsingManager(doc As Inventor.Document)
' Get the active document. It can be any type of document.
'Dim doc As Document
'Set doc = ThisApplication.ActiveDocument
' Get the attribute manager.
Dim attribMgr As AttributeManager
Set attribMgr = doc.AttributeManager
' Find all attribute sets named "SampleSet".
Dim foundEntities As ObjectCollection
Set foundEntities = attribMgr.FindObjects("SampleSet")
If foundEntities.Count <> 0 Then
Dim foundEntity As Object
For Each foundEntity In foundEntities
If TypeOf foundEntity Is Face Then
If oface1 Is Nothing Then
Set oface1 = foundEntity
Exit For
End If
If Not (oface1 Is Nothing) Then Set oface2 = foundEntity
ElseIf TypeOf foundEntity Is Edge Then
End If
Next
End If
If (Not (oface1 Is Nothing)) And (Not (oface2 Is Nothing)) Then
Dim Distance As Double
Distance = ThisApplication.MeasureTools.GetMinimumDistance(oface1, oface2)
Distance = doc.UnitsOfMeasure.ConvertUnits(Distance, "cm", "mm")
ListBox3.AddItem (Distance)
Set oface1 = Nothing
Set oface2 = Nothing
End If
End Sub