Adahm
Guest
I just needed the code piece to copy the symbols, thank you!hello if you have many files already made, I use this rule, and if I remove hand to a file made with old templates, I click and change. You have to have a template with the paper you want to put, and then replace the paths.
Code: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
regarding the path of the standard.idw file, you can recover it through this command:
Code:
sfolder = thisapplication.fileoptions.templatespath