In the assembly drawing, a ModelGeometry.ContainingOccurrence error occurs.

In the assembly drawing, a ModelGeometry.ContainingOccurrence error occurs.

BenAtok
Explorer Explorer
360 Views
4 Replies
Message 1 of 5

In the assembly drawing, a ModelGeometry.ContainingOccurrence error occurs.

BenAtok
Explorer
Explorer

Hello,

I'm trying to write a program that checks which parts are not ballooned in the BOM and then goes through all the drawing curves in the assembly drawing to balloon them. However, an error occurs when attempting to get ModelGeometry from DrawingCurve (line 38). Can someone help me resolve this issue?

Public Sub CheckPartsList()

    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    Dim oPartsList As PartsList
    Set oPartsList = oActiveSheet.PartsLists(1)
    
    Dim oPartslistRow As PartsListRow
    Dim lstOfComponents As String
    
    For Each oPartslistRow In oPartsList.PartsListRows
    
        If oPartslistRow.Ballooned = False Then
            Dim ItemNumber As String
            ItemNumber = oPartslistRow.Item(5).Value
            lstOfComponents = ItemNumber
        End If
        
    Next
    
    Dim oDrawView As DrawingView
    Set oDrawView = oActiveSheet.DrawingViews.Item(1)
    
    Dim oDrawCurves As DrawingCurvesEnumerator
    Set oDrawCurves = oDrawView.DrawingCurves
    
    Dim oDrawCurve As DrawingCurve
    Dim oCurveModelGeometry As Object
    Dim oCurveContainingOccurence As Object
    Dim PartNameFromCurve
    
    For Each oDrawCurve In oDrawCurves
    
        Set oCurveModelGeometry = oDrawCurve.ModelGeometry 
        
        '-------------delet part name from ":"
        Set oCurveContainingOccurence = oCurveModelGeometry.ContainingOccurrence
        PartNameFromCurve = oCurveContainingOccurence.Name
        colonPosition = InStr(PartNameFromCurve, ":")
        
        If colonPosition > 0 Then
            ConfiguredPartNameFromCurve = Left(PartNameFromCurve, colonPosition - 1)
        Else
            ConfiguredPartNameFromCurve = PartNameFromCurve
        End If
        '---------------------------
        
        '-----------compare part name from BOM and Drawingcurve
        If ConfiguredPartNameFromCurve = lstOfComponents Then
            MsgBox (PartNameFromCurve)
            Exit For
        End If
        '---------------------------
        
    Next
    Stop
    
End Sub

 

laurynasmedzevicius_0-1725367558744.png

 

0 Likes
Accepted solutions (2)
361 Views
4 Replies
Replies (4)
Message 2 of 5

jjstr8
Collaborator
Collaborator
Accepted solution

It looks like DrawingCurves is also returning Interference Edges.  They don't belong to a model, hence the error.  Add a check for oDrawCurve.ProjectedCurveType <> kUnknownCurve2d before getting ModelGeometry.

0 Likes
Message 3 of 5

Michael.Navara
Advisor
Advisor
Accepted solution

Iteration over drawing curves and check which model belongs to is highway to hell.

Much better is to get component from PartsListRow and obtain its drawing curves. The sample below show you just "HOW TO" . It is not full implementation. It just selects one of many drawing curves which belongs to un-balloned component.

 

Public Sub CheckPartsList()

    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet

    Dim oPartsList As PartsList
    Set oPartsList = oActiveSheet.PartsLists(1)

    Dim oPartslistRow As PartsListRow

    Dim asm As AssemblyDocument
    Set asm = oPartsList.ReferencedDocumentDescriptor.ReferencedDocument

    For Each oPartslistRow In oPartsList.PartsListRows

        If Not oPartslistRow.Ballooned Then

            Dim drawingBomRow As drawingBomRow
            Set drawingBomRow = oPartslistRow.ReferencedRows(1)
            
            Dim bomRow As bomRow
            Set bomRow = drawingBomRow.bomRow
            
            Dim compDef As ComponentDefinition
            Set compDef = bomRow.ComponentDefinitions(1)
            
            Dim occurrences As ComponentOccurrencesEnumerator
            Set occurrences = asm.ComponentDefinition.occurrences.AllReferencedOccurrences(compDef)
            
            Dim drawingCurvesEnumerator As drawingCurvesEnumerator
            Set drawingCurvesEnumerator = oActiveSheet.DrawingViews(1).DrawingCurves(occurrences(1))

            Call oDrawDoc.SelectSet.Clear
            Call oDrawDoc.SelectSet.Select(drawingCurvesEnumerator(1).Segments(1))

            MsgBox ("Continue")
        End If
    Next
    
End Sub

 

 

0 Likes
Message 4 of 5

BenAtok
Explorer
Explorer
Thank you, it works perfectly. Maybe you can tell me more about why it's bad to iterate over drawing curves and check for which model it belongs? Is the process too slow or can too many errors accrue?
0 Likes
Message 5 of 5

Michael.Navara
Advisor
Advisor

There are several reasons

1. Performance. I worked on drawings with ten-thousands of drawing curves. Iteration over this collection spends a lot of time.

2. Drawing curves are not persistent objects. Sometimes it can be replaced with the new drawing curve for some reason. (Historical experience, it is hard to prepare working dataset but it happens sometimes)