Sostituzione Cartiglio

Adahm

Utente standard
Professione: Progettazione parametrica / Consulente di processo
Software: CatiaV5 / Inventor-Vault 2023
Regione: Lombardia
Ciao se hai molti file già fatti, io uso questa regola, e se rimetto mano ad un file fatto con template vecchi , clicco e cambia. Devi avere un template con il cartiglio che vuoi mettere , e poi sostituisci i percorsi.

Codice:
Public Sub Main ()

    'Check Title in active document
    Try
        Dim odrawdoc As DrawingDocument
            odrawdoc = ThisApplication.ActiveDocument
       
       
        ' Check if drawing deferupdate state is true
        If Not odrawdoc.DrawingSettings.DeferUpdates = "False" Then
           'ShowError("Can`t change Title because drawing file is Deferupdate")
            Exit Sub  
        End If      
   
        'Sostituisco i simboli nel disegno
        Try
            deletesymbols
            'CopySymbols
        Catch
           
        End Try
       
        Dim Title="cartiglio-2019"
        Call ReplaceTitle(Title)
   
    Catch
        MsgBox("Errore durante sostituzione cartiglio")
       
    End Try

   
End Sub

Sub ReplaceTitle(ByRef Title As String )

    Dim odrawdoc As DrawingDocument
    odrawdoc = ThisApplication.ActiveDocument
    Dim Template = "C:\Impostazioni_Inventor\2018\Templates\2019 Standard.idw"  
       

    Dim oTemplate As DrawingDocument
    Dim oSourceTitleBlockDef As TitleBlockDefinition
    Dim oNewTitleBlockDef As TitleBlockDefinition
    Dim oSheet = odrawdoc.ActiveSheet

    Try  
        'Apro il template      
        oTemplate = ThisApplication.Documents.Open(Template, False)
        'Aggancio la definizione del nuovo cartiglio
         oSourceTitleBlockDef = oTemplate.TitleBlockDefinitions.Item(Title)
        'Copio la definizinoe del cartiglio nel nuovo disegno
         oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc, True)
        'Chiudo il template
         oTemplate.Close
   
        'MsgBox("Tentativo di inserimento cartiglio "  & Title)
         
        'Inserimento cartiglio sul disegno
       
'        Dim i As Integer
'        Dim intPrompts As Integer = 0
'        For i = 1 To oNewTitleBlockDef.Sketch.TextBoxes.Count
'            Dim oText = oNewTitleBlockDef.Sketch.TextBoxes(i)          
'            If (oText.Text = "MY_PROMPT")          
'                intPrompts = intPrompts + 1
'            End If
'        Next
       
        'MsgBox ("Trovati " & intPrompts & " messaggi prompt")
       
        Dim oPrompts(2) As String
        oPrompts(0) = ""
        oPrompts(1) = ""
        oPrompts(2) = ""
        oSheet.TitleBlock.Delete()      
           oSheet.AddTitleBlock(oNewTitleBlockDef,,oPrompts)
       
        'MsgBox("Title Block changed to " & vbCr & Title)


    Catch ex As Exception
        MsgBox("Errore: " & ex.Message)
    End Try
   
   
End Sub

Sub deletesymbols

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSkSymDefs As SketchedSymbolDefinitions = oDoc.SketchedSymbolDefinitions
Dim oSkSymDef As SketchedSymbolDefinition

For Each oSkSymDef In oSkSymDefs
    If oSkSymDef.IsReferenced = False Then
        oSkSymDef.Delete
    End If
Next
   
End Sub

Sub CopySymbols
           
            Dim strSelectedStamp As String = "Result2"
           
            Dim strStampList As New ArrayList
           
            Dim strStampRequired As Boolean
            strStampRequired = True
            strStampList.Add("cartilgio-2019")
            'strStampList.Add("X OSSITAGLIO")
            'strStampList.Add("Test")
            strSelectedStamp = InputListBox("Please select a stamp.", strStampList, strSelectedStamp, "Stamp Selection", "Available Stamps")
            Dim strDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
            Dim SourceFile As String = "M:\_Impostazioni_Inventor\2018\Templates\2019 Standard.idw"
                   
            Dim strSourceIDW As DrawingDocument
            strSourceIDW = ThisApplication.Documents.Open(SourceFile, False)
            Dim symbolDef As SketchedSymbolDefinition
           
            Dim CopyFrom As SketchedSymbolDefinition
           

     Try
            For Each symbolDef In strSourceIDW.SketchedSymbolDefinitions
               
                    CopyFrom = (symbolDef.CopyTo(strDrawDoc, True))
               
            Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Title")

End Try
            strSourceIDW.Close()
    End Sub

Mi serviva giusto il pezzo di codice per copiare i simboli, grazie! 😅

Per quanto riguarda il percorso del file Standard.idw, lo si può recuperare tramite questo comando:

Codice:
sFolder = ThisApplication.FileOptions.TemplatesPath
 

summer2010

Utente poco attivo
Professione: disegnatore meccanico
Software: autocad e inventor
Regione: veneto
Buongiorno
Grazie Adahm , ho letto tutto e io ho provato a mettere solo queste 2 righe , ma no funziona..

io volevo solo sostituire/aggiornare il bordo e il cartiglio

grazie
 

Allegati

  • fser.JPG
    fser.JPG
    23.2 KB · Views : 5

Adahm

Utente standard
Professione: Progettazione parametrica / Consulente di processo
Software: CatiaV5 / Inventor-Vault 2023
Regione: Lombardia
Mi sembra che nel percorso ci sia una "\" di troppo: "Q:\\\"
 

Statistiche forum

Discussioni
56,403
Messaggi
481,032
Utenti registrati
97,888
Ultimo utente registrato
langella53

Utenti online


Top