- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
could someone assist please
I need some code that will look at an Inventor Drawing sheet and find text that uses a style (A) and change / update the text to use style (B)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @keithc03GZXH6 . This is code that copies the properties of one text style to another. You need to write the appropriate names for lines 4 and 5.
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oTM As TransactionManager = ThisApplication.TransactionManager
Dim oTS As TextStylesEnumerator = oDDoc.StylesManager.TextStyles
Dim sNameTextA As String = "Name text style A"
Dim sNameTextB As String = "Name text style B"
Dim oStyleA As TextStyle = oTS.Item(sNameTextA)
Dim oStyleB As TextStyle = oTS.Item(sNameTextB)
Dim newTM As Transaction = oTM.StartTransaction(oDDoc, "ChangeTextStyle")
If oStyleA.InUse Then
oStyleA.Bold = oStyleB.Bold
oStyleA.Color = oStyleB.Color
oStyleA.Font = oStyleB.Font
oStyleA.FontSize = oStyleB.FontSize
oStyleA.HorizontalJustification = oStyleB.HorizontalJustification
oStyleA.Italic = oStyleB.Italic
oStyleA.LineSpacing = oStyleB.LineSpacing
oStyleA.Rotation = oStyleB.Rotation
oStyleA.Underline = oStyleB.Underline
oStyleA.VerticalJustification = oStyleB.VerticalJustification
oStyleA.WidthScale = oStyleB.WidthScale
End If
newTM.End()
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Andrii
the code below used to work by giving a list of the available styles but i would like to specify the style by name and not pick from a list
where / what would I change
Sub Main If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "") Exit Sub End If Dim oDDoc As DrawingDocument = ThisDoc.Document Dim oSMgr As DrawingStylesManager = oDDoc.StylesManager Dim oSSNames As New List(Of String) For Each oSS As DrawingStandardStyle In oSMgr.StandardStyles oSSNames.Add(oSS.Name) Next Dim oSSName As String = InputListBox("Choose Standard Style For Active Sheet", oSSNames) If oSSName = "" Then Exit Sub Dim oDSS As DrawingStandardStyle = oSMgr.StandardStyles.Item(oSSName) Dim oSheet As Sheet = oDDoc.ActiveSheet SetSheetStandardStyle(oSheet, oDSS) If oDDoc.RequiresUpdate Then oDDoc.Update2(True) 'If oDDoc.Dirty Then oDDoc.Save End Sub Sub SetSheetStandardStyle(oSheet As Sheet, oDSS As DrawingStandardStyle) If IsNothing(oSheet) Or IsNothing(oDSS) Then Exit Sub Dim oDStyles As ObjectDefaultsStyle = oDSS.ActiveObjectDefaults Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions Dim oGDims As GeneralDimensions = oDDims.GeneralDimensions For Each oGDim As GeneralDimension In oGDims : oGDim.Style = oDStyles.LinearDimensionStyle : Next Dim oODims As OrdinateDimensions = oDDims.OrdinateDimensions For Each oODim As OrdinateDimension In oODims : oODim.Style = oDStyles.OrdinateDimensionStyle : Next Dim oODSs As OrdinateDimensionSets = oDDims.OrdinateDimensionSets For Each oODS As OrdinateDimensionSet In oODSs : oODS.Style = oDStyles.OrdinateSetDimensionStyle : Next Dim oCDSs As ChainDimensionSets = oDDims.ChainDimensionSets For Each oCDS As ChainDimensionSet In oCDSs : oCDS.Style = oDStyles.ChainDimensionStyle : Next Dim oBDSs As BaselineDimensionSets = oDDims.BaselineDimensionSets For Each oBDS As BaselineDimensionSet In oBDSs : oBDS.Style = oDStyles.BaselineDimensionStyle : Next Dim oDNotes As DrawingNotes = oSheet.DrawingNotes Dim oCNs As ChamferNotes = oDNotes.ChamferNotes For Each oCN As ChamferNote In oCNs : oCN.DimensionStyle = oDStyles.ChamferNoteStyle : Next Dim oGNs As GeneralNotes = oDNotes.GeneralNotes For Each oGN As GeneralNote In oGNs : oGN.TextStyle = oDStyles.GeneralNoteStyle : Next Dim oHTNs As HoleThreadNotes = oDNotes.HoleThreadNotes For Each oHTN As HoleThreadNote In oHTNs : oHTN.Style = oDStyles.HoleNoteStyle : Next Dim oLNs As LeaderNotes = oDNotes.LeaderNotes For Each oLN As LeaderNote In oLNs : oLN.DimensionStyle = oDStyles.LeaderTextStyle : Next Dim oPNs As PunchNotes = oDNotes.PunchNotes For Each oPN As PunchNote In oPNs : oPN.DimensionStyle = oDStyles.PunchNoteStyle : Next oSheet.Update End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you want to write a specific style in the code by name instead of selecting from a list, then you need to replace this code:
Dim oSSNames As New List(Of String) For Each oSS As DrawingStandardStyle In oSMgr.StandardStyles oSSNames.Add(oSS.Name) Next Dim oSSName As String = InputListBox("Choose Standard Style For Active Sheet", oSSNames) If oSSName = "" Then Exit Sub
with this:
Dim oSSName As String = "Name text style A"
The rule will look like this:
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSMgr As DrawingStylesManager = oDDoc.StylesManager
Dim oSSName As String = "Name text style A"
Dim oDSS As DrawingStandardStyle = oSMgr.StandardStyles.Item(oSSName)
Dim oSheet As Sheet = oDDoc.ActiveSheet
SetSheetStandardStyle(oSheet, oDSS)
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
'If oDDoc.Dirty Then oDDoc.Save
End Sub
Sub SetSheetStandardStyle(oSheet As Sheet, oDSS As DrawingStandardStyle)
If IsNothing(oSheet) Or IsNothing(oDSS) Then Exit Sub
Dim oDStyles As ObjectDefaultsStyle = oDSS.ActiveObjectDefaults
Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
Dim oGDims As GeneralDimensions = oDDims.GeneralDimensions
For Each oGDim As GeneralDimension In oGDims : oGDim.Style = oDStyles.LinearDimensionStyle : Next
Dim oODims As OrdinateDimensions = oDDims.OrdinateDimensions
For Each oODim As OrdinateDimension In oODims : oODim.Style = oDStyles.OrdinateDimensionStyle : Next
Dim oODSs As OrdinateDimensionSets = oDDims.OrdinateDimensionSets
For Each oODS As OrdinateDimensionSet In oODSs : oODS.Style = oDStyles.OrdinateSetDimensionStyle : Next
Dim oCDSs As ChainDimensionSets = oDDims.ChainDimensionSets
For Each oCDS As ChainDimensionSet In oCDSs : oCDS.Style = oDStyles.ChainDimensionStyle : Next
Dim oBDSs As BaselineDimensionSets = oDDims.BaselineDimensionSets
For Each oBDS As BaselineDimensionSet In oBDSs : oBDS.Style = oDStyles.BaselineDimensionStyle : Next
Dim oDNotes As DrawingNotes = oSheet.DrawingNotes
Dim oCNs As ChamferNotes = oDNotes.ChamferNotes
For Each oCN As ChamferNote In oCNs : oCN.DimensionStyle = oDStyles.ChamferNoteStyle : Next
Dim oGNs As GeneralNotes = oDNotes.GeneralNotes
For Each oGN As GeneralNote In oGNs : oGN.TextStyle = oDStyles.GeneralNoteStyle : Next
Dim oHTNs As HoleThreadNotes = oDNotes.HoleThreadNotes
For Each oHTN As HoleThreadNote In oHTNs : oHTN.Style = oDStyles.HoleNoteStyle : Next
Dim oLNs As LeaderNotes = oDNotes.LeaderNotes
For Each oLN As LeaderNote In oLNs : oLN.DimensionStyle = oDStyles.LeaderTextStyle : Next
Dim oPNs As PunchNotes = oDNotes.PunchNotes
For Each oPN As PunchNote In oPNs : oPN.DimensionStyle = oDStyles.PunchNoteStyle : Next
oSheet.Update
End Sub
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.