Richiesta creazione regola i-logic

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
Salve a tutti, mi rivolgo agli utenti di buon cuore, che abbiano una buona competenza nella programmazione e creazione delle regole i-logic e che abbiano la buona volontà di aiutarmi e che abbiano buon tempo da dedicarci.
Il sottoscritto ha provato a creare sta regola con Gemini e con Copilot, ma non ne hanno cavato un ragno dal buco.
Allora il punto è il seguente: nelle ultime versioni di Inventor, credo a partire dalla 2025, è possibile (vivaddio) inserire nel testo dell'etichetta di una vista della messa in tavola, alcune proprietà relative all'elenco parti (BOM). In particolare risulta molto utile la possibilità di inserire il parametro del numero di elemento tratto dall'elenco parti.
Faccio un esempio per essere più chiaro.
Ammettiamo che ho una carpenteria complessa, o un telaio complesso e che io abbia la necessità di mettere in tavola, ad esempio, una piasta forata contenuta nel telaio, per poterla quotare con maggior chiarezza. Quindi creo una vista in cui si vede solo quella piastra, che ha un detrminato numero di item nella BOM della tavola di disegno. Ora rimane il problema di legare quella vista di quella determinata piastra, al corrispettivo numero di elemento della BOM. Inventor ti consente di editare l'etichetta della vista, e di inserire il corrispettivo numero di parte, sciegliendolo dall'elenco parti. Solo che sta procedura è abbastanza laboriosa e noiosa da fare, per ogni particolare. Quindi chiedevo una regola ilogic che automatizzase il processo, lasciando all'operatore solo il compito di inserire il numero di "item" da associare alla vista selezionata e poi sto valore compare nell'etichetta della vista. Di conseguenza l'etichetta della vista dovrebbe essere un testo del tipo: Vista particolare n° "item" scala 1:5. Ecco quel valore "item" dovrebbe essere associato all'elenco parti e scelto dall'utente.
Spero di esere stato chiaro nella mia richiesta, che sicuramente sarà utile a molti che utilizzano invetor per progettare carpenterie e telai complessi
 
Ultima modifica:

Sleepers

Utente Standard
professione: Disegnatore
software: Inventor 2026, AutoCAD (Mechanical) 2022
regione: Lombardia
Il sottoscritto ha provato a creare sta regola con Gemini e con Copilot, ma non ne hanno cavato un ragno dal buco.

Non conosco iLogic e non posso aiutarti :-(

Però sono riuscito dopo anni a sistemare una regola che non funzionava a dovere, usando Claude (Gemini e ChatGPT avevano fallito, in precedenza); ho impiegato una mezz'oretta con aggiustamenti e spiegazioni varie passo passo, ma alla fine ce l'ho fatta.

Per la cronaca, ne avevo parlato qui Riordinare tabella fori
 

Catafratto

Utente Standard
professione: Disegnatore/progettista
software: Inventor 2024
regione: Veneto
Con "Item" intendi il classico "Pos", la posizione nell'elenco numerato?
Il numero di posizione nel cartiglio della tavola e quello della BOM di Inventor coincidono o vengono editati localmente nel cartiglio?
 

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
Con "Item" intendi il classico "Pos", la posizione nell'elenco numerato?
Il numero di posizione nel cartiglio della tavola e quello della BOM di Inventor coincidono o vengono editati localmente nel cartiglio?
esatto intendo il classico Pos. I numeri coincidono con la BOM, a meno che non vengano forzati sovrascrivendoli.
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
Salve a tutti, mi rivolgo agli utenti di buon cuore, che abbiano una buona competenza nella programmazione e creazione delle regole i-logic e che abbiano la buona volontà di aiutarmi e che abbiano buon tempo da dedicarci.
Il sottoscritto ha provato a creare sta regola con Gemini e con Copilot, ma non ne hanno cavato un ragno dal buco.
Allora il punto è il seguente: nelle ultime versioni di Inventor, credo a partire dalla 2025, è possibile (vivaddio) inserire nel testo dell'etichetta di una vista della messa in tavola, alcune proprietà relative all'elenco parti (BOM). In particolare risulta molto utile la possibilità di inserire il parametro del numero di elemento tratto dall'elenco parti.
Faccio un esempio per essere più chiaro.
Ammettiamo che ho una carpenteria complessa, o un telaio complesso e che io abbia la necessità di mettere in tavola, ad esempio, una piasta forata contenuta nel telaio, per poterla quotare con maggior chiarezza. Quindi creo una vista in cui si vede solo quella piastra, che ha un detrminato numero di item nella BOM della tavola di disegno. Ora rimane il problema di legare quella vista di quella determinata piastra, al corrispettivo numero di elemento della BOM. Inventor ti consente di editare l'etichetta della vista, e di inserire il corrispettivo numero di parte, sciegliendolo dall'elenco parti. Solo che sta procedura è abbastanza laboriosa e noiosa da fare, per ogni particolare. Quindi chiedevo una regola ilogic che automatizzase il processo, lasciando all'operatore solo il compito di inserire il numero di "item" da associare alla vista selezionata e poi sto valore compare nell'etichetta della vista. Di conseguenza l'etichetta della vista dovrebbe essere un testo del tipo: Vista particolare n° "item" scala 1:5. Ecco quel valore "item" dovrebbe essere associato all'elenco parti e scelto dall'utente.
Spero di esere stato chiaro nella mia richiesta, che sicuramente sarà utile a molti che utilizzano invetor per progettare carpenterie e telai complessi
Questo credo che fa quello che stai chiedendo - item e scala. Non lo uso da molto tempo ma l'ho provato e sembra che funzioni. Sembra che sai come aggiungere altri dati (PN, materiale, spessore...), altrimenti fammi sapere.
Codice:
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheets As Sheets
Dim Sheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
  
        'Get the full filename Of the view model
        Dim oModelFileName As String
        oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        'MessageBox.Show("view model name" & oModelFileName, "Title")

        Dim oPartList As PartsList
            'try and get the parts list form the table of this sheet
            Try
                oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
            Catch 'on error try and search all sheets for first found parts list           
                'iterate trough each sheet
                Dim i As Long
                For i = 1 To oDrawDoc.Sheets.Count
                    If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
                Next   
                oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
                'MessageBox.Show("parts list found on: " & i, "Title")
            End Try
              
            ' Iterate through the contents of the parts list.
            Dim j As Long
            For j = 1 To oPartList.PartsListRows.Count
                ' Get the current row.
                Dim oRow As PartsListRow
                oRow = oPartList.PartsListRows.Item(j)
                'get filename of model in row
                Dim oRowFileName As String
                oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
                'compare the filenames
                'Performs a text comparison, based on a case-insensitive text sort order
                'If strings equal returns 0
                If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then
                    'Get the value of Item from the Parts List
                    'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    oCell  = oPartList.PartsListRows.Item(j).Item("Item") 'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    'get the value of text in cell
                    Dim oItemValue As String
                    oItemValue = oCell.Value
                  
                    'Show the view label
                    oView.ShowLabel = True
                    'format the text first line
                    oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"
                    'format the text second line
                    oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
                  
                    'add to the view label
                    oView.Label.FormattedText =  oStringItem & oStringScale
                End If
            Next
      Next
Next

1780484282731.png
1780484357356.png
 

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
Ecco si il risultato che
Questo credo che fa quello che stai chiedendo - item e scala. Non lo uso da molto tempo ma l'ho provato e sembra che funzioni. Sembra che sai come aggiungere altri dati (PN, materiale, spessore...), altrimenti fammi sapere.
Codice:
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheets As Sheets
Dim Sheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
 
        'Get the full filename Of the view model
        Dim oModelFileName As String
        oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        'MessageBox.Show("view model name" & oModelFileName, "Title")

        Dim oPartList As PartsList
            'try and get the parts list form the table of this sheet
            Try
                oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
            Catch 'on error try and search all sheets for first found parts list         
                'iterate trough each sheet
                Dim i As Long
                For i = 1 To oDrawDoc.Sheets.Count
                    If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
                Next 
                oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
                'MessageBox.Show("parts list found on: " & i, "Title")
            End Try
            
            ' Iterate through the contents of the parts list.
            Dim j As Long
            For j = 1 To oPartList.PartsListRows.Count
                ' Get the current row.
                Dim oRow As PartsListRow
                oRow = oPartList.PartsListRows.Item(j)
                'get filename of model in row
                Dim oRowFileName As String
                oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
                'compare the filenames
                'Performs a text comparison, based on a case-insensitive text sort order
                'If strings equal returns 0
                If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then
                    'Get the value of Item from the Parts List
                    'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    oCell  = oPartList.PartsListRows.Item(j).Item("Item") 'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    'get the value of text in cell
                    Dim oItemValue As String
                    oItemValue = oCell.Value
                
                    'Show the view label
                    oView.ShowLabel = True
                    'format the text first line
                    oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"
                    'format the text second line
                    oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
                
                    'add to the view label
                    oView.Label.FormattedText =  oStringItem & oStringScale
                End If
            Next
      Next
Next

Visualizza allegato 77072
Visualizza allegato 77073
Ecco sì il risultato che ottieni è esattamente quello che vorrei, solo che ho provato, ma a me non lo fa, anzi quando lancio la regola non succede nulla. come mai?
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
Ecco si il risultato che

Ecco sì il risultato che ottieni è esattamente quello che vorrei, solo che ho provato, ma a me non lo fa, anzi quando lancio la regola non succede nulla. come mai?
Strano. Quello che mi viene in mente e' la lingua.
Prova a cambiare questa linea:
oCell = oPartList.PartsListRows.Item(j).Item("Item")

in

oCell = oPartList.PartsListRows.Item(j).Item("Pos")

o quello che si vede in tuo Part List
 

Catafratto

Utente Standard
professione: Disegnatore/progettista
software: Inventor 2024
regione: Veneto
Se non interpreto male il codice la regola ha bisogno che la vista del particolare sia una vista apposita, creata nella stessa tavola con solo la parte che si vuole "pallinare"; forse (io farei così) @infallibile_GF crea i vari particolari prendendoli dall'assieme stesso e gioca con le viste...
 

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
Strano. Quello che mi viene in mente e' la lingua.
Prova a cambiare questa linea:
oCell = oPartList.PartsListRows.Item(j).Item("Item")

in

oCell = oPartList.PartsListRows.Item(j).Item("Pos")

o quello che si vede in tuo Part List
ancora nulla, non compare nemmeno nessuna messageBOx
 

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
adesso modificando item con Pos poi mi da un errore alla riga 63:
Parametro non corretto. (0x80070057 (E_INVALIDARG))
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
Prova questo

oCell = oPartList.PartsListRows.Item(j).Item(1)

Comunque giusto per capirci la procedura dovrebbe essere:

1. nel disegno c'è una vista di assieme ed il suo elenco parti
2. si inserisce la vista di uno dei componenti
3. esegui la regola che attiva View Label con Numero Item o Elemento come nel elenco parti.
 

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
niente da fare. Mi dice errore nell'ultima riga della regola:
oView.Label.FormattedText = oStringItem & oStringScale
il risultato è che attiva la visibilità dell'etichetta, ma non inserisce il numero di item
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
Prova - solo come un test - questo:


Codice:
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheets As Sheets
Dim Sheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
  
        'Get the full filename Of the view model
        Dim oModelFileName As String
        oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        'MessageBox.Show("view model name" & oModelFileName, "Title")

        Dim oPartList As PartsList
            'try and get the parts list form the table of this sheet
            Try
                oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
            Catch 'on error try and search all sheets for first found parts list           
                'iterate trough each sheet
                Dim i As Long
                For i = 1 To oDrawDoc.Sheets.Count
                    If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
                Next   
                oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
                'MessageBox.Show("parts list found on: " & i, "Title")
            End Try
              
            ' Iterate through the contents of the parts list.
            Dim j As Long
            For j = 1 To oPartList.PartsListRows.Count
                ' Get the current row.
                Dim oRow As PartsListRow
                oRow = oPartList.PartsListRows.Item(j)
                'get filename of model in row
                Dim oRowFileName As String
                oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
                'compare the filenames
                'Performs a text comparison, based on a case-insensitive text sort order
                'If strings equal returns 0
                If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then
                    'Get the value of Item from the Parts List
                    'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    oCell  = oPartList.PartsListRows.Item(j).Item("Item") 'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    'get the value of text in cell
                    Dim oItemValue As String
                    oItemValue = oCell.Value
                  
                   oView.ShowLabel = True
oView.Label.FormattedText = "TEST"
                End If
            Next
      Next
Next
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
niente da fare. Mi dice errore nell'ultima riga della regola:
oView.Label.FormattedText = oStringItem & oStringScale
il risultato è che attiva la visibilità dell'etichetta, ma non inserisce il numero di item
Oppure prova questo qui con debug messages:
Codice:
' ============================================================
' iLogic Rule: Set View Labels from Parts List (DEBUG v2)
' ============================================================

' --- Declare all variables at top to avoid scope conflicts ---
Dim oDrawDoc As DrawingDocument
Dim oPartList As PartsList
Dim partsListSheet As String
Dim itemColIndex As Long
Dim colNames As String
Dim totalViews As Long
Dim matchedViews As Long
Dim skippedViews As Long
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oModelFileName As String
Dim oRowFileName As String
Dim oItemValue As String
Dim oScaleStr As String
Dim oStringItem As String
Dim oStringScale As String

' ============================================================
' STEP 1 — Check active document
' ============================================================
MessageBox.Show("Checking for active drawing document...", "Debug [1/6]")
Try
    oDrawDoc = ThisApplication.ActiveDocument
    If Not TypeOf oDrawDoc Is DrawingDocument Then
        MessageBox.Show("ERROR: Active document is not a Drawing." & vbCrLf & _
                        "Please open a drawing document first.", "Debug [1/6] FAILED")
        Exit Sub
    End If
Catch ex As Exception
    MessageBox.Show("ERROR getting active document:" & vbCrLf & ex.Message, "Debug [1/6] FAILED")
    Exit Sub
End Try
MessageBox.Show("OK — Drawing found: " & vbCrLf & oDrawDoc.FullFileName, "Debug [1/6]")

' ============================================================
' STEP 2 — Find parts list
' ============================================================
MessageBox.Show("Searching for Parts List...", "Debug [2/6]")
Try
    oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
    partsListSheet = oDrawDoc.ActiveSheet.Name
Catch
    Dim i As Long
    Dim found As Boolean = False
    For i = 1 To oDrawDoc.Sheets.Count
        If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then
            oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
            partsListSheet = oDrawDoc.Sheets.Item(i).Name
            found = True
            Exit For
        End If
    Next
    If Not found Then
        MessageBox.Show("ERROR: No Parts List found on any sheet.", "Debug [2/6] FAILED")
        Exit Sub
    End If
End Try
MessageBox.Show("OK — Parts List found on sheet: " & partsListSheet & vbCrLf & _
                "Rows: " & oPartList.PartsListRows.Count, "Debug [2/6]")

' ============================================================
' STEP 3 — List all column names (to identify Item column)
' ============================================================
MessageBox.Show("Reading Parts List columns...", "Debug [3/6]")
colNames = ""
Dim c As Long
For c = 1 To oPartList.PartsListColumns.Count
    colNames = colNames & c & ": " & oPartList.PartsListColumns.Item(c).Title & vbCrLf
Next
' Default to column 1. User can change this number based on message output.
itemColIndex = 1
MessageBox.Show("OK — Columns found:" & vbCrLf & colNames & vbCrLf & _
                "Using column index: " & itemColIndex & vbCrLf & _
                "(Edit itemColIndex in rule if wrong)", "Debug [3/6]")

' ============================================================
' STEP 4 — Check sheets have views
' ============================================================
MessageBox.Show("Checking sheets for drawing views...", "Debug [4/6]")
Dim totalSheets As Long = oDrawDoc.Sheets.Count
Dim sheetsWithViews As Long = 0
For Each oSheet In oDrawDoc.Sheets
    If oSheet.DrawingViews.Count > 0 Then sheetsWithViews = sheetsWithViews + 1
Next
MessageBox.Show("OK — Sheets: " & totalSheets & vbCrLf & _
                "Sheets with views: " & sheetsWithViews, "Debug [4/6]")

' ============================================================
' STEP 5 — Iterate views and set labels
' ============================================================
MessageBox.Show("Starting view iteration...", "Debug [5/6]")
totalViews = 0
matchedViews = 0
skippedViews = 0

For Each oSheet In oDrawDoc.Sheets
    For Each oView In oSheet.DrawingViews
        totalViews = totalViews + 1

        ' Get view model filename
        Try
            oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        Catch
            skippedViews = skippedViews + 1
            Continue For
        End Try

        ' Match against parts list rows
        Dim j As Long
        For j = 1 To oPartList.PartsListRows.Count
            Try
                oRowFileName = oPartList.PartsListRows.Item(j).ReferencedFiles.Item(1).FullFileName
            Catch
                Continue For
            End Try

            If StrComp(oModelFileName, oRowFileName, CompareMethod.Text) = 0 Then

                ' Get item cell value
                Try
                    oItemValue = oPartList.PartsListRows.Item(j).Item(itemColIndex).Value
                Catch ex As Exception
                    MessageBox.Show("ERROR reading cell value:" & vbCrLf & ex.Message & vbCrLf & _
                                    "View: " & oView.Name & vbCrLf & _
                                    "Row: " & j & ", Column index: " & itemColIndex, _
                                    "Debug [5/6] FAILED")
                    Continue For
                End Try

                ' Get scale as plain string
                Try
                    oScaleStr = oView.Scale.ToString
                Catch
                    oScaleStr = "?"
                End Try

                ' Show what we are about to write
                MessageBox.Show("Setting label for view: " & oView.Name & vbCrLf & _
                                "File: " & IO.Path.GetFileName(oModelFileName) & vbCrLf & _
                                "Item value: " & oItemValue & vbCrLf & _
                                "Scale: " & oScaleStr, "Debug [5/6]")

                ' Build and apply label
                Try
                    oView.ShowLabel = True
                    oStringItem = " ITEM " & _
                                  oItemValue & " "
                    oStringScale = "
(Scala " & _
                                   oScaleStr & ")"
                    oView.Label.FormattedText = oStringItem & oStringScale
                    matchedViews = matchedViews + 1
                    MessageBox.Show("OK — Label set successfully.", "Debug [5/6]")
                Catch ex As Exception
                    MessageBox.Show("ERROR on FormattedText:" & vbCrLf & ex.Message & vbCrLf & _
                                    "String attempted:" & vbCrLf & _
                                    oStringItem & oStringScale, "Debug [5/6] FAILED")
                End Try
                Exit For
            End If
        Next
    Next
Next

' ============================================================
' STEP 6 — Summary
' ============================================================
MessageBox.Show("Run complete." & vbCrLf & vbCrLf & _
                "Total views:             " & totalViews & vbCrLf & _
                "Labels updated:          " & matchedViews & vbCrLf & _
                "Skipped (no model ref):  " & skippedViews & vbCrLf & _
                "No BOM match:            " & (totalViews - matchedViews - skippedViews), _
                "Debug [6/6] — Summary")
 

infallibile_GF

Utente attivo
professione: Disegnatore / Progettista
software: Autocad Inventor
regione: Lombardia
Ottimo, l'ultimo codice che hai scritto funziona, ora bisognerebeb togliere tutti i pulsanti per premere ok.
Solo due appunti per renderla perfetta:
1 la scala quando è inferiore del valore 1:1 invece di riportare la corretta dicitura tipo 1:2, mi riporta il valore 0,5, cioè fa la divisione.
2 Seconda cosa da perfezionare è che se modifico l'ordine degli item della BOM, il numero corrispondente nella vista non viene aggiornato in automatico, ma bisogna lanciare nuovamente la regola, stesso discorso se si modifica il valore della scala della vista.
CMQ già così è tanta roba
 

Cast16

Utente Standard
professione: Design Engineer
software: Inventor, Autocad, Solid Edge
regione: UK
aggiornamento automatico è una limitazione delle regole iLogic: vengono eseguite solo su richiesta.

la regola con la scala in frazione:


Codice:
' ============================================================
' iLogic Rule: Set View Labels from Parts List
' Final v5 — plain ratio scale string, no XML scale tag
' ============================================================

' --- All variables declared at top ---
Dim oDrawDoc As DrawingDocument
Dim oPartList As PartsList
Dim itemColIndex As Long
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oModelFileName As String
Dim oRowFileName As String
Dim oItemValue As String
Dim oScaleStr As String
Dim oStringItem As String
Dim oStringScale As String

' ============================================================
' PASSO 1 — Verifica documento attivo
' ============================================================
Try
    oDrawDoc = ThisApplication.ActiveDocument
    If Not TypeOf oDrawDoc Is DrawingDocument Then
        MessageBox.Show("Il documento attivo non è una Messa in Tavola. Aprire prima una tavola.", _
                        "iLogic — Errore")
        Exit Sub
    End If
Catch ex As Exception
    MessageBox.Show("Errore nel recupero del documento attivo:" & vbCrLf & ex.Message, _
                    "iLogic — Errore")
    Exit Sub
End Try

' ============================================================
' PASSO 2 — Ricerca Elenco Parti (prima nel foglio attivo, poi in tutti i fogli)
' ============================================================
Try
    oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
Catch
    Dim i As Long
    Dim found As Boolean = False
    For i = 1 To oDrawDoc.Sheets.Count
        If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then
            oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
            found = True
            Exit For
        End If
    Next
    If Not found Then
        MessageBox.Show("Nessun Elenco Parti trovato in nessun foglio.", "iLogic — Errore")
        Exit Sub
    End If
End Try

' ============================================================
' PASSO 3 — Imposta l'indice della colonna Elemento
' La colonna 1 è quella standard per Elemento/Pos./Voce nella maggior parte dei modelli.
' Modificare itemColIndex se nella propria BOM si trova in una posizione diversa.
' ============================================================
itemColIndex = 1

' ============================================================
' PASSO 4 — Scorre le viste e imposta le etichette
' ============================================================
For Each oSheet In oDrawDoc.Sheets
    For Each oView In oSheet.DrawingViews

        ' Recupera il nome file del modello della vista
        ' Salta le viste senza riferimento a un modello
        Try
            oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        Catch
            Continue For
        End Try

        ' Confronta con le righe dell'Elenco Parti
        Dim j As Long
        For j = 1 To oPartList.PartsListRows.Count
            Try
                oRowFileName = oPartList.PartsListRows.Item(j).ReferencedFiles.Item(1).FullFileName
            Catch
                Continue For
            End Try

            If StrComp(oModelFileName, oRowFileName, CompareMethod.Text) = 0 Then

                ' Recupera il valore della cella Elemento
                Try
                    oItemValue = oPartList.PartsListRows.Item(j).Item(itemColIndex).Value
                Catch
                    Continue For
                End Try

                ' --- Converte la scala decimale in formato ratio ---
              
              
                Try
                    Dim dScale As Double = oView.Scale
                    If Math.Abs(dScale - 1.0) < 0.0001 Then
                        ' Scala 1:1
                        oScaleStr = "1:1"
                    ElseIf dScale > 1.0 Then
                        ' Ingrandimento es. 2:1, 5:1
                        Dim numer As Long = Math.Round(dScale)
                        oScaleStr = numer.ToString( _
                                    System.Globalization.CultureInfo.InvariantCulture) & ":1"
                    Else
                        ' Riduzione es. 1:2, 1:5, 1:10
                        Dim denom As Long = Math.Round(1.0 / dScale)
                        oScaleStr = "1:" & denom.ToString( _
                                    System.Globalization.CultureInfo.InvariantCulture)
                    End If
                Catch
                    oScaleStr = "?"
                End Try

                ' --- Costruisce e applica l'etichetta ---
                oStringItem = " ITEM " & _
                              oItemValue & " "
                oStringScale = "
(" & _
                               oScaleStr & ")"

                Try
                    oView.ShowLabel = True
                    oView.Label.FormattedText = oStringItem & oStringScale
                Catch ex As Exception
                    ' Errore silenzioso — impossibile impostare l'etichetta della vista
                End Try

                Exit For
            End If
        Next
    Next
Next
 

Statistiche forum

Discussioni
59,286
Messaggi
506,305
Utenti registrati
111,427
Ultimo utente registrato
Sopra95

Utenti online

Nessun utente è online al momento.
Top