Area estensione modello piatto in m^2

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
@Spini

1. Aggiungi Regola1
2. Mettilo nel Event triggers
3. Crea Form

Tutto spiegato nel video di sotto.

Fammi sapere.

iLogic:
Codice:
' iLogic Rule: Aggiorna_Area_Totale
Dim partAreaPropName As String = "extents_area"
Dim drawingQtyPropName As String = "Qty"
Dim drawingTotalAreaPropName As String = "Total Area"

Dim oDoc As DrawingDocument
oDoc = ThisDrawing.Document

Dim oDrawingUserPropSet As PropertySet
Try
    oDrawingUserPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")
Catch
    MessageBox.Show("Il set di proprietà personalizzate del disegno 'Inventor User Defined Properties' non è stato trovato. Assicurarsi che le proprietà personalizzate siano utilizzate.", "Errore iLogic - Set Proprietà Mancante", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return
End Try

Dim qty As Double = 0.0
Dim oQtyProp As Inventor.Property = Nothing

Try
    oQtyProp = oDrawingUserPropSet.Item(drawingQtyPropName)
    
    If IsNumeric(oQtyProp.Value) Then
        qty = CDbl(oQtyProp.Value)
    Else
        MessageBox.Show("Il valore della proprietà '" & drawingQtyPropName & "' nel disegno non è numerico. Verrà utilizzato il valore predefinito 1.", "Avviso iLogic - Qty Non Numerica", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        qty = 1.0
    End If
Catch
    Try
        oQtyProp = oDrawingUserPropSet.Add(1.0, drawingQtyPropName)
        qty = 1.0
        MessageBox.Show("La proprietà personalizzata del disegno '" & drawingQtyPropName & "' non è stata trovata ed è stata creata con valore iniziale 1.", "Informazione iLogic - Qty Creata", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Catch ex As Exception
        MessageBox.Show("Impossibile creare la proprietà personalizzata del disegno '" & drawingQtyPropName & "': " & ex.Message, "Errore iLogic - Creazione Qty Fallita", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End Try
End Try

Dim area As Double = 0.0
Dim foundPartAndArea As Boolean = False

If oDoc.ReferencedDocuments.Count > 0 Then
    For Each refDoc As Document In oDoc.ReferencedDocuments
        If refDoc.DocumentType = kPartDocumentObject Then
            Dim oPartUserPropSet As PropertySet
            Try
                oPartUserPropSet = refDoc.PropertySets.Item("Inventor User Defined Properties")
            Catch
                Continue For
            End Try

            Dim oAreaProp As Inventor.Property = Nothing
            Try
                oAreaProp = oPartUserPropSet.Item(partAreaPropName)
                
                Dim sAreaValue As String = CStr(oAreaProp.Value).Trim()
                
                If sAreaValue.EndsWith(" m^2") Then
                    sAreaValue = Left(sAreaValue, sAreaValue.Length - 4)
                End If
                
                sAreaValue = Replace(sAreaValue, ",", ".")
                
                If IsNumeric(sAreaValue) Then
                    area = CDbl(sAreaValue)
                    foundPartAndArea = True
                    Exit For
                Else
                    MessageBox.Show("Il valore della proprietà '" & partAreaPropName & "' nella parte '" & refDoc.DisplayName & "' ('" & oAreaProp.Value & "') non è numerico o non convertibile anche dopo la pulizia del formato. Verrà ignorato.", "Avviso iLogic - Area Parte Non Valida", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    Continue For
                End If
            Catch
                Continue For
            End Try
        End If
    Next
End If

If Not foundPartAndArea Then
    MessageBox.Show("Impossibile trovare una parte referenziata con la proprietà personalizzata '" & partAreaPropName & "' con un valore numerico valido (o nel formato atteso 'X.XX m^2').", "Avviso iLogic - Area Parte Non Trovata", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End If

Dim totalArea As Double = area * qty

Dim oTotalAreaProp As Inventor.Property = Nothing
Try
    oTotalAreaProp = oDrawingUserPropSet.Item(drawingTotalAreaPropName)
    oTotalAreaProp.Value = totalArea
Catch
    Call oDrawingUserPropSet.Add(totalArea, drawingTotalAreaPropName)
End Try

 

Spini

Utente standard
professione: Perito meccanico
software: inventor
regione: Lombardia
Cast16 più o meno ho visto le tue indicazioni, ma forse non mi sono spegato bene io in quanto se ho capito le quantità dei pezzi vengono prese da idw, ma io ho un idw e 200 ipt quindi ogni ipt ha misure e quantità diverse. il cartiglio si ripete su tutti i fogli allo stesso modo. probabilmente penso che la regola vada su ogni ipt per farlo funzionare o sbaglio?
Grazie per avermi dedicato del tempo.
Rino
 

dsw

Rossano Praderi
professione: Libero Professionista
software: Vari
regione: Lombardia
Buongiorno Rossano
l'esempio che hai postato forse fatto con versione inventor superiore alla mia, io mi sono fermato alla 18, anche perchè volevo smettere già da tempo, penso quest'anno di fermarmi, per me sono 72 il 30 giugno. Se hai tempo mi devi spiegare operazione x operazione, uso poco inventor. Ti ho allegato anche un idw e relativa parte. Quel totale che volevo inserire nel cartiglio dovrebbe andare in quella casella vuota con scritto "AREA SVILUPPO TOTALE" mi deve dare il prodotto del numero pezzi x Area Sviluppo che trovi in una casella del cartiglio. La regola che mi hai allegato va inserita dove? Perchè se va bene nell'idw mi va bene per tutti i pannelli, sono circa 200 ora sono a circa a 80, ma se la devo inserire su ogni pannello e poi eseguirla si può fare ma ci vuole più tempo.
Ringrazio per il tempo che dedichi e ti saluto.
Rino Spini
Buona sera Rino,
quando scrivi "mi sono fermato alla 18" intendi dire la versione 2018(=22) o 18(=2014)?

Lo script ILogic è una regola esterna, devi copiare il testo, salvarlo in un file di testo con il nome che preferisci e con un estensione del file compatibile, come per esempio .txt (anche .vb va bene, ma è indifferente).

Per esempio puoi salvare la regola in un file chiamato "area_sviluppo_totale.txt", nella cartella delle regole esterne.

La regola che ho scritto aggiunge le IProperties solo nel file di modello (IPT) cosi puoi inserire l'IProperty personalizzata che ti interessa nel cartiglio o in una nota, a tuo piacimento.

Quando esegui questa regola aggiunge/aggiorna una parte delle IProperty che sono già presenti nel file di modello (IPT) ed aggiunge il prodotto dell'area moltiplicata per il numero dei pezzi(altra IProperty).

Ha visto i file che hai condiviso ed ho apportato alcune modifiche e corretto un baco nella regola originale che ho scritto.

Il risultato lo puoi vedere nell'immagine qui sotto
Immagine 2025-06-23 163647.png

La regola revisionata è quella di seguito, prova ad avviarla dalla messa in tavole(IDW) o dal modello (IPT) funziona uguale.....uguale.
Comunque testala bene e se qualche parte non ti è chiara chiedi pure.
Codice:
' Autore: Rossano Praderi
' Creato il: 21/06/2025
' Revisionato: 23/06/2025

Sub main
    Try
        ' PartDocument di riferimento
        Dim oDoc As Inventor.PartDocument = Nothing
        If (ThisDoc.Document.DocumentType.Equals(Inventor.DocumentTypeEnum.kDrawingDocumentObject))
            ' se il documento attivo è un DrawingDocument assegna ad oDoc il primo documento di riferimento
            oDoc = ThisDoc.Document.ReferencedDocuments.Item(1)
        ElseIf (ThisDoc.Document.DocumentType.Equals(Inventor.DocumentTypeEnum.kPartDocumentObject))
            ' se il documento attivo è un PartDocument assegna ad oDoc il documento attivo
            oDoc = ThisDoc.Document
        End If

        ' se oDoc è Nothing prosegue senza fare nulla
        If Not oDoc Is Nothing
            Dim shm As SheetMetalComponentDefinition = oDoc.ComponentDefinition
            ' Propertyset "Custom"
            Dim pSet As Inventor.PropertySet = oDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
           
            ' numero pezzi ***** DUE OPZIONI DISPONIBILI *****
            ' se il parametro "v" non è impostato, viene visualizzata la richiesta di inserire il numero pezzi solo quando l'IProperty non esiste e deve essere creata
            pz = CreateIfNotExists_Int(pSet, "PEZZI")
           
            ' se il parametro "v" viene impostato a -1, viene sempre chiesto di impostare il numero pezzi
            'pz = CreateIfNotExists_Int(pSet, "PEZZI", -1)
           
            ' extents_length
'            CreateIfNotExists(pSet, "extents_length", String.Concat(ToMeters(shm.FlatPattern.Length).ToString()," m")) ' LUNGHEZZA IN METRI
            CreateIfNotExists(pSet, "extents_length", String.Concat(shm.FlatPattern.Length, " mm")) ' LUNGHEZZA IN MILLIMETRI
           
            ' extents_width
'            CreateIfNotExists(pSet, "extents_width", String.Concat(ToMeters(shm.FlatPattern.Width).ToString()," m")) ' LARGHEZZA IN METRI
            CreateIfNotExists(pSet, "extents_width", String.Concat(shm.FlatPattern.Width, " mm")) ' LARGHEZZA IN MILLIMETRI
            ' area
            Area = ToMeters(shm.FlatPattern.Length * shm.FlatPattern.Width)
            CreateIfNotExists(pSet, "extents_area", String.Concat( Area, " m^2")) ' AREA IN METRI^2
           
            ' area totale - imposta ad 1 il numero pezzi se il valore è inferiore ad 1
            CreateIfNotExists(pSet, "extents_area_total", String.Concat( Area * Math.Max(1, pz)," m^2"))
        End If
    Catch
    End Try
End Sub

''' <summary>
''' Assegna il valore all'IPropertiy e se non esiste la crea(versione con InputBox per valore numerico intero)
''' </summary>
''' <param name="pSet">PropertySet di riferimento</param>
''' <param name="pName">Nome IProperty di riferimento</param>
''' <param name="v">Valore da assegnare all'IProperty di riferimento</param>
''' <returns>Restituisce un valore numerico intero</returns>
Private Function CreateIfNotExists_Int(ByRef pSet As Inventor.PropertySet, pName As String, Optional v As Integer = 0) As Integer
    Dim prop As Inventor.Property
    Try
        prop = pSet.Item(pName)
        v = prop.Value
    Catch
        v = -1
        prop = pSet.Add(v, pName)
    End Try
    if v = -1
        v = CInt(InputBox("Immettere un valore numerico", "Valore IProperty " & pName))
        prop.Value=v
    end if
    CreateIfNotExists_Int = v
End Function

''' <summary>
''' Assegna il valore all'IPropertiy e se non esiste la crea(versione senza InputBox)
''' </summary>
''' <param name="pSet">PropertySet di riferimento</param>
''' <param name="pName">Nome IProperty di riferimento</param>
''' <param name="v">Valore da assegnare all'IProperty di riferimento</param>
Private Sub CreateIfNotExists(ByRef pSet As Inventor.PropertySet, pName As String, v As Object)
    Dim prop As Inventor.Property
    Try
        prop = pSet.Item(pName)
        prop.Value = v
    Catch
        prop = pSet.Add(v, pName)
    End Try
End Sub

''' <summary>
''' Funzione per convertire un valore numerico double(con vigola mobile) da millimetri a metri
''' </summary>
''' <param name="v">Valore numerico con virgola da convertire</param>
''' <param name="nd">Numero di decimali d'arrotondamento, numero decimali di default è 3</param>
''' <returns></returns>
Private Function ToMeters(v As Double, Optional nd As Integer = 3) As Double
    ToMeters = Math.Round(ThisApplication.UnitsOfMeasure.ConvertUnits(v, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kMeterLengthUnits), nd)
End Function

PS: con questa regola non dovresti più aver bisogno della "Regola1" che è presente nel file IPT e dei relativi parametri ("extents_with", "extents_lenght" & "extents_area"), ma ho fatto solo un controllo veloce ed è meglio se fai una verifica.
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
Cast16 più o meno ho visto le tue indicazioni, ma forse non mi sono spegato bene io in quanto se ho capito le quantità dei pezzi vengono prese da idw, ma io ho un idw e 200 ipt quindi ogni ipt ha misure e quantità diverse. il cartiglio si ripete su tutti i fogli allo stesso modo. probabilmente penso che la regola vada su ogni ipt per farlo funzionare o sbaglio?
Grazie per avermi dedicato del tempo.
Rino
In quel caso - la quantita' viene preso dal iproperty "Pezzi" - ilogic diventa come di sotto. Quello che devi fare:
1. Run iLogic di sotto.
2. Metti quel "Total Area" nella Casella di testo come visto al minuto 3:17 nel video.

Il nuovo codice:
Codice:
' iLogic Rule: Aggiorna_Area_Totale_Da_Pezzi_Parte
Dim partAreaPropName As String = "extents_area"
Dim partPezziPropName As String = "PEZZI" ' Nuovo: Nome della proprietà QTY nella parte
Dim drawingTotalAreaPropName As String = "Total Area"

Dim oDoc As DrawingDocument
oDoc = ThisDrawing.Document

Dim oDrawingUserPropSet As PropertySet
Try
    oDrawingUserPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")
Catch
    MessageBox.Show("Il set di proprietà personalizzate del disegno 'Inventor User Defined Properties' non è stato trovato. Assicurarsi che le proprietà personalizzate siano utilizzate.", "Errore iLogic - Set Proprietà Mancante", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return
End Try

Dim area As Double = 0.0
Dim qty As Double = 0.0 ' Inizializza Qty qui
Dim foundPartAndArea As Boolean = False
Dim foundPartAndQty As Boolean = False

If oDoc.ReferencedDocuments.Count > 0 Then
    For Each refDoc As Document In oDoc.ReferencedDocuments
        If refDoc.DocumentType = kPartDocumentObject Then
            Dim oPartUserPropSet As PropertySet
            Try
                oPartUserPropSet = refDoc.PropertySets.Item("Inventor User Defined Properties")
            Catch
                Continue For ' Questa parte non ha proprietà definite dall'utente
            End Try

            ' --- Recupera "extents_area" dalla parte ---
            Dim oAreaProp As Inventor.Property = Nothing
            Try
                oAreaProp = oPartUserPropSet.Item(partAreaPropName)
                Dim sAreaValue As String = CStr(oAreaProp.Value).Trim()
                
                If sAreaValue.EndsWith(" m^2") Then
                    sAreaValue = Left(sAreaValue, sAreaValue.Length - 4)
                End If
                
                sAreaValue = Replace(sAreaValue, ",", ".")
                
                If IsNumeric(sAreaValue) Then
                    area = CDbl(sAreaValue)
                    foundPartAndArea = True
                Else
                    MessageBox.Show("Il valore della proprietà '" & partAreaPropName & "' nella parte '" & refDoc.DisplayName & "' ('" & oAreaProp.Value & "') non è numerico o non convertibile. Verrà ignorato.", "Avviso iLogic - Area Parte Non Valida", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            Catch
                ' Proprietà Area non trovata, continua
            End Try

            ' --- Recupera "PEZZI" dalla parte ---
            Dim oPezziProp As Inventor.Property = Nothing
            Try
                oPezziProp = oPartUserPropSet.Item(partPezziPropName)
                If IsNumeric(oPezziProp.Value) Then
                    qty = CDbl(oPezziProp.Value)
                    foundPartAndQty = True
                Else
                    MessageBox.Show("Il valore della proprietà '" & partPezziPropName & "' nella parte '" & refDoc.DisplayName & "' non è numerico. Verrà utilizzato il valore predefinito 1 per Qty.", "Avviso iLogic - Pezzi Parte Non Numerici", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    qty = 1.0
                End If
            Catch
                MessageBox.Show("La proprietà '" & partPezziPropName & "' non è stata trovata nella parte '" & refDoc.DisplayName & "'. Verrà utilizzato il valore predefinito 1 per Qty.", "Avviso iLogic - Pezzi Parte Mancanti", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                qty = 1.0
            End Try
            
            ' Se abbiamo trovato entrambi i valori dalla PRIMA parte, possiamo uscire dal ciclo
            If foundPartAndArea And foundPartAndQty Then
                Exit For
            End If
        End If
    Next
End If

If Not foundPartAndArea Then
    MessageBox.Show("Impossibile trovare una parte referenziata con la proprietà personalizzata '" & partAreaPropName & "' con un valore numerico valido (o nel formato atteso 'X.XX m^2').", "Avviso iLogic - Area Parte Non Trovata", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End If

If Not foundPartAndQty Then
    MessageBox.Show("Impossibile trovare una parte referenziata con la proprietà personalizzata '" & partPezziPropName & "' con un valore numerico valido. Utilizzo Qty = 1.", "Avviso iLogic - Pezzi Parte Non Trovati", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    qty = 1.0 ' Assicura che qty sia 1 se non trovata
End If

Dim totalArea As Double = area * qty

Dim oTotalAreaProp As Inventor.Property = Nothing
Try
    oTotalAreaProp = oDrawingUserPropSet.Item(drawingTotalAreaPropName)
    oTotalAreaProp.Value = totalArea
Catch
    Call oDrawingUserPropSet.Add(totalArea, drawingTotalAreaPropName)
End Try
 
Ultima modifica:

Statistiche forum

Discussioni
59,249
Messaggi
504,723
Utenti registrati
110,455
Ultimo utente registrato
Randyunari

Utenti online

Top