Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
ndillner343SKL
276 Views, 3 Replies

Copy Styles From Template File

Good Afternoon,

 

I'm trying to copy styles from a template file and add/update the local styles. 

 

I found similar code written by @WCrihfield and tweaked it to be what I'm looking for. But it doesn't appear to be overriding the existing styles. 

 

Reference:

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-load-a-style-in-templates-autom...

 

Dim oTDDoc As DrawingDocument = ThisApplication.Documents.Open(oTFN, False)
Dim oTStylesMgr As DrawingStylesManager = oTDDoc.StylesManager 
Dim oStylesMgr As DrawingStylesManager = oDDoc.StylesManager 
Dim oStyle As Style

For Each oTStyle As Style In oTStylesMgr.Styles
	MsgBox(oTStyle.Name)
	If oTStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
		oTStyle.ConvertToLocal
	ElseIf oTStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation Or _
		   oTStyle.StyleLocation = StyleLocationEnum.kLocalStyleLocation Then
		oStyle = oStylesMgr.Styles.Item(oTStyle.Name)
		Dim oTSCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
		oTSCol.Add(oTStyle)
		oTStylesMgr.ReplaceStyles(oTSCol, oStyle, True)
	End If
Next

 

 

WCrihfield
in reply to: ndillner343SKL

Hi @ndillner343SKL.  I do not believe it will work that way.  Generally, we do not just copy styles from a template drawing file into our other drawings, we copy things like TitleBlockDefinition, BorderDefinition, SketchedSymbolDefinition, and SheetFormat type objects from a template to other drawings.  If we want styles in our other drawings, we make sure they have been saved up into the 'global' styles library first.  Then we can open our other drawings, and use the 'UpdateFromGlobal' method on any styles that are already present in the drawing, and currently being used, then we can create copies of the library styles down into the local drawing, if we want to use them in that drawing.  If your template drawing contains some styles that you want to use in your other drawings, and they have not yet been saved up into the global styles library, then you should open that template drawing and save its styles into the global library, so that they will be available to your other drawings.  There are methods for creating a local copy of a library style, and methods for copying an existing local style, to create another, but not a method for copying a style from one drawing to another directly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Walliguy
in reply to: ndillner343SKL

Hey,

 

Not sure if this helps, the C# code below is what we have used to update styles.

 

        /// <summary>
        /// Updates any outdated style to the global styles.
        /// </summary>
        /// <param name="drawingDocument">Docuemtn to be updtated</param>
        private void UpdateStyles(DrawingDocument drawingDocument)
        {
            Styles styles = drawingDocument.StylesManager.Styles;
            foreach (Inventor.Style style in styles)
            {
                if (!style.UpToDate)
                    style.UpdateFromGlobal();
            }
        }

 

Chris

There is a tool installed doing this for you.

 

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Autodesk Inventor ###\Tools\Drawing Resource Transfer Wizard ####

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !