adds the weight in the active sheet

adds the weight in the active sheet

gleocata
Contributor Contributor
279 Views
3 Replies
Message 1 of 4

adds the weight in the active sheet

gleocata
Contributor
Contributor
' Verifica se il documento corrente è un file IDW
If ThisDoc.Document.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
    ' Ottieni il riferimento al documento del disegno
    Dim drawingDoc As DrawingDocument
    drawingDoc = ThisDoc.Document
    
    ' Ottieni il riferimento al foglio attivo
    Dim foglioAttivo As Sheet
    foglioAttivo = drawingDoc.ActiveSheet
    
    ' Verifica se un foglio è attivo
    If Not foglioAttivo Is Nothing Then
        ' Itera attraverso tutte le viste sul foglio
        For Each view As DrawingView In foglioAttivo.DrawingViews
            ' Ottieni il riferimento al documento di riferimento della vista
            Dim referenceDoc As Document
            referenceDoc = View.ReferencedDocument
            
            ' Verifica se il documento di riferimento è valido
            If Not referenceDoc Is Nothing Then
                ' Ottieni il riferimento al componente nella vista
                Dim componente As ComponentOccurrence
                componente = referenceDoc.ComponentDefinition.Occurrences(View.ReferencedOccurrenceName)
                
                ' Verifica se il componente è valido
                If Not componente Is Nothing Then
                    ' Ottieni il nome del componente
                    Dim nomeComponente As String
                    nomeComponente = componente.Name
                    
                    ' Calcola il peso del componente
                    Dim pesoComponente As Double
                    pesoComponente = componente.MassProperties.Mass
                    
                    ' Crea una iProperty personalizzata per il nome del componente con il suo peso
                    foglioAttivo.PropertySets.Item("Inventor User Defined Properties").Add(iPropName:=nomeComponente, iPropType:=Inventor.ValueTypeEnum.kDoubleType, iPropValue:=pesoComponente)
                End If
            End If
        Next
    Else
        ' Nessun foglio attivo nel documento
        MsgBox("Nessun foglio attivo nel documento.")
    End If
Else
    ' Il documento corrente non è un file IDW
    MsgBox("Il documento corrente non è un file IDW.")
End If

Hi everyone
I would need to add the weight of the components present in the active sheet even if they are not an assembly.
I found an ilogic rule but it doesn't work, can anyone help me understand the error. 

Thanks to all

0 Likes
280 Views
3 Replies
Replies (3)
Message 2 of 4

Frederick_Law
Mentor
Mentor

The program add mass to iProperty.

 

Just use text, leader text, Sketch Symbol or add text to titleblock:

DrawingMass-01.jpg

0 Likes
Message 3 of 4

gleocata
Contributor
Contributor
I know this solution, and I thank you for the suggestion, but it is not what I'm looking for, because then I would have to connect a text leader to each view. but I would have to do the sum by hand.
0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

Hi @gleocata 

 

I'm not sure where this line comes from but you can't get an occurrence object directly from the view. See Drawing view object here

 

Dim componente As ComponentOccurrence
                componente = referenceDoc.ComponentDefinition.Occurrences(View.ReferencedOccurrenceName)

 

 

From the previously received referenced document you can get the component definition and then it's massproperties and then mass. And because both part and assembly component defi ition are derived classes you can just type componentdefinition and it will look at parts and assemblies. Can you share your source for the ilogic code? We might find better context of how it was constructed from there. 

Syntax

PartDocument.ComponentDefinition()

As PartComponentDefinition

Syntax

PartComponentDefinition.MassProperties() As MassProperties

Syntax

MassProperties.Mass() As Double

 

Dim docMass as Double = referenceDoc.ComponentDefinition.MassProperties.Mass

 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes