change size of active sheet

change size of active sheet

tkch.ndq
Participant Participant
4,736 Views
17 Replies
Message 1 of 18

change size of active sheet

tkch.ndq
Participant
Participant

Hi everyone, wish you all have good day.

 

I am beginner with ilogic Inventor and have an issue need your help if possible.

I only use sheet size: A0, A1, A2, A3, A4

I've created 5 title blocks with name: A0-TTBL, A1-TTBL, A2-TTBL, A3-TTBL, A4-TTBL

I've created 5 dimension styles with name: A0-DST, A1-DST, A2-DST, A3-DST, A4-DST

I've created 5 Leader styles with name: A0-LD, A1-LD, A2-LD, A3-LD, A4-LD

I've created 5 View Annotation styles with name: A0-VA, A1-VA, A2-VA, A3-VA, A4-VA

I'd like to click on itrigger when I need to change size of active sheet on IDW file then with a list A0, A1, A2, A3, A4 that I can choose the sheet size.

The default template is A3 sheet size with: title block A3-TTBL with dim style A3-DST with leader style A3-LD with View annotation style A3-AV

Is there any ilogic that can help me so when I change size of active sheet to other sizes then title block + dimension style + leader style + view annotation style are changed automatically too?

P/S: the border doesn't need to change

Please help me.

 

Thanks so much in advance!

0 Likes
Accepted solutions (1)
4,737 Views
17 Replies
Replies (17)
Message 2 of 18

A.Acheson
Mentor
Mentor

Welcome to the forum. 
Here is a document that should cover all that you need it may even be more than you need. Around Pg 13, I would start with the easy things like changing sheet size and adding the titleblock to match etc.

 Here is a rule although not in English has the general layout. 

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-rule-change-sheetsize-error/td-p/880696...

 

You will likely not find a complete rule tailored to your requirements but hopefully that will get you going in the right direction.

 

There is three types of code you will encounter in posts you will find pure ilogic(short snippets) these are located in your rule editor look for drawing  that represent larger pieces of code or  code to control the API via VB.Net or VBA language see help and sample location here.

Just be aware that forum post you come across are not all using the same methods. So if your using ilogic try and search using keywords ilogic. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 18

tkch.ndq
Participant
Participant

Thank you Alan Acheson!

 

I am trying to find helpful thing to use.

Do you know how to replace old dimension style, old leader style and old view annotation with new one by ilogic?

 

Thanks in advance!

0 Likes
Message 4 of 18

FINET_Laurent
Advisor
Advisor

It's explained in the first PDF he handed you.

Nice document though, could have been helpful when I started iLogic. 😂

 

Regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 5 of 18

Stakin
Collaborator
Collaborator
Dim odrawdoc As DrawingDocument 
odrawdoc=ThisApplication.ActiveDocument
Dim osheets As Sheets=odrawdoc.Sheets
Dim osheet As Sheet
Dim oviews As DrawingViews
Dim oview As DrawingView
osheet=odrawdoc.ActiveSheet()
oviews=oSheet.DrawingViews
Dim oBorderDef As BorderDefinition
rem If the sheet has the border or titleblock,you should delete them
	If Not osheet.Border Is Nothing Then
		osheet.Border.Delete
	End If
	If Not osheet.TitleBlock Is Nothing Then
		osheet.TitleBlock.Delete
	End If
rem Change the size of the sheet,such as
	osheet.Size= Inventor.DrawingSheetSizeEnum.kA3DrawingSheetSize
rem If the size of the sheet is not in the DrawingSheetSizeEnum Enumerator list,you should set it by yourself according your border setting.
	osheet.height=XXX
	oSheet.width=XXX
Rem if the sheetsize is not need modify ,Insert your border as you want
	oBorderDef = oDrawDoc.BorderDefinitions.Item("Your border name")
	osheet.AddBorder(oBorderDef, )
Rem Insert the titleblock
	oSheet.AddTitleBlock( "Your titleblock name" ,  ,  titleblockPrompt )
Message 6 of 18

Stakin
Collaborator
Collaborator
Rem Leaderstyle try this
Dim oleaderStyle As leaderStyle
oleaderStyle=oDrawDoc.LeaderStylesEnumerator.Item( "Your Style Name")
Dim oleadernote As LeaderNote
oleadernote.DimensionStyle.LeaderStyle=oleaderStyle

Rem DrawingViewLabelstyle try below
Dim oTextStyle As Inventor.TextStyle
Set oTextStyle = oPartDoc.TextStyles.Item("Your Style Name")
Dim oDrawingViewLabel As DrawingViewLabel
oDrawingViewLabel.TextStyle= oTextStyle

df

Message 7 of 18

Curtis_Waguespack
Consultant
Consultant
Message 8 of 18

tkch.ndq
Participant
Participant

Thank you very much for all your help till this moment!

I cannot use snippet (code) which you help, sorry but seem I need more time to learn with ilogic
Can somebody help me with an ilogic code or something in attachment file so I have a good example in future?

If possible, please help!
Thanks so much in advance!

0 Likes
Message 9 of 18

Stakin
Collaborator
Collaborator

If change the default dimensionstyle, All the sheets which  include in this drawing will changed.

So you must change the style for each dimension of the sheet you want to change.

Unless the drawing only have one sheet. 

0 Likes
Message 10 of 18

tkch.ndq
Participant
Participant

Thanks for your respond.

Normally the drawing has only 1 sheet.

Sometimes there are some sheets but they are always same dimension style and same paper size.

When we start the drawing we put the views in then we make dimension but when it's almost done then we realize that the paper we choose is not enough because of some extra thing like note or table. Sometimes this also because the model become bigger after changed. We always change each thing when change paper size but this take much time and easy to forget. That's why I asked for all your help!

Kind regards

0 Likes
Message 11 of 18

WCrihfield
Mentor
Mentor
Accepted solution

This can be a bigger job than you might think.  Just changing sheet sizes is one thing, and not too difficult.  Changing title blocks can be simple or complicated, depending on how you have things set-up and if they contain any prompted entries you need the code to fill in for you.  But updating all the different types of styles has the potential for being a much bigger and more complicated task than the other two...again depending on how you have things set-up.  To help make this whole styles part of this overall task much easier, I highly recommend than you first create a series of Drawing Standard Styles (DSS) (within your Styles Editor dialog box, they are the top item in the left hand side list, under the heading Standard).  One for each sheet size, since all those styles change with the sheet size.  Within each of these DSS you can set which ones of all the other types of styles you want it to use, by default, while it is active.  Name them similarly to how you named your other style variations.  In my code below, I'm expecting that you have created a set of these, and named them according to the following naming scheme:  "A0-DDS" (for use with A0 size sheets).  If you don't have those DSS set-up yet, and you just want to try out the part of the code where it changes the sheet size and title block, just comment out the last If...Then block of code within the Sub Main portion of the code, then it won't try to run those two other Subs.

Here is some pretty detailed iLogic code you can try out. 

 

 

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTBDefs As TitleBlockDefinitions = oDDoc.TitleBlockDefinitions

	Dim oSheetSizesList As New List(Of String)
	oSheetSizesList.AddRange({"A0", "A1", "A2", "A3", "A4" })
	Dim oChoice As String = InputListBox("Choose Sheet Size.", oSheetSizesList)
	MsgBox("You chose " & oChoice, , "")

	Dim oChangedSheetSize As Boolean = False
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		'run the Function defined below to update sheet sizes & title blocks
		oChangedSheetSize = UpdateSheet(oSheet, oChoice, oTBDefs)
	Next
	
	If oChangedSheetSize Then
		'run the Sub defined below to change the active drawing standard style
		ChangeStdStyle(oDDoc, oChoice)
		'run the Sub defined below to update all existing objects to conform to the new stantard styles
		UpdateStylesOfExisting(oDDoc, oChoice)
	End If
End Sub

Function UpdateSheet(oSht As Inventor.Sheet, oSize As String, oTBDs As TitleBlockDefinitions) As Boolean
	Dim oTargetSheetSize As DrawingSheetSizeEnum
	
	Select Case oSize
		Case "A0"
			'specify desired sheet size
			oTargetSheetSize = DrawingSheetSizeEnum.kA0DrawingSheetSize
		Case "A1"
			oTargetSheetSize = DrawingSheetSizeEnum.kA1DrawingSheetSize
		Case "A2"
			oTargetSheetSize = DrawingSheetSizeEnum.kA2DrawingSheetSize
		Case "A3"
			oTargetSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
		Case "A4"
			oTargetSheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize
	End Select
	
	If oSht.Size <> oTargetSheetSize Then
		oSht.Size = oTargetSheetSize
		oChangedSheetSize = True
	End If
	
	'now deal with changing the title block
	Dim oTBDef As TitleBlockDefinition
	Dim oTBDefName As String = oSize & "-TTBL"
	Try
		oTBDef = oTBDs.Item(oTBDefName)
	Catch
		MsgBox("Couldn't find a Title Block Definition named '" & oTBDefName & "'.", , "")
		Return False
		Exit Function
	End Try
	
	If oSht.TitleBlock Is Nothing Or _
		oSht.TitleBlock.Definition IsNot oTBDef Then
		'if there is already a title block on the sheet, this will remove/replace it
		oSht.AddTitleBlock(oTBDef)
	End If
End Function

Sub ChangeStdStyle(oDrawDoc As DrawingDocument, oSize As String)
	Dim oSMgr As DrawingStylesManager = oDrawDoc.StylesManager
	Dim oDSStyle As DrawingStandardStyle
	'naming scheme for your DrawingStandardStyles within your Styles Manager
	'<<<<< THESE DRAWING STANDARD STYLES MUST EXIST FIRST >>>>>>
	Dim oDSStyleName As String = oSize & "-DSS"
	Try
		oDSStyle = oSMgr.StandardStyles.Item(oDSStyleName)
	Catch
		MsgBox("Couldn't find a DrawingStandardStyle named '" & oDSStyleName & "'.", , "")
		Exit Sub
	End Try
	If oDSStyle IsNot Nothing Then
		oSMgr.ActiveStandardStyle = oDSStyle
	End If
End Sub

Sub UpdateStylesOfExisting(oDrawDoc As DrawingDocument, oSize As String)
	Dim oDSStyle As DrawingStandardStyle = oDrawDoc.StylesManager.ActiveStandardStyle
	'just changing the standard won't change these pre-existing objects, it will only effect new objects of these types you create
	
	For Each oSheet As Sheet In oDrawDoc.Sheets
		'update dimension styles to comply with new stantard
		For Each oGDim As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions
			'assumes the style you use for LinearDimensions is the same style used for all GeneralDimensions 
			oGDim.Style = oDSStyle.ActiveObjectDefaults.LinearDimensionStyle
		Next
		For Each oBLDimSet As BaselineDimensionSet In oSheet.DrawingDimensions.BaselineDimensionSets
			oBLDimSet.Style = oDSStyle.ActiveObjectDefaults.BaselineDimensionStyle
		Next
		For Each oChDimSet As ChainDimensionSet In oSheet.DrawingDimensions.ChainDimensionSets
			oChDimSet.Style = oDSStyle.ActiveObjectDefaults.ChainDimensionStyle
		Next
		For Each oOrdDimSet As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
			oOrdDimSet.Style = oDSStyle.ActiveObjectDefaults.OrdinateSetDimensionStyle
		Next
		
		'update leader styles
		For Each oLNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes
			oLNote.DimensionStyle = oDSStyle.ActiveObjectDefaults.LeaderTextStyle
		Next
		
		'update the view label styles
		For Each oView As DrawingView In oSheet.DrawingViews
			oView.Label.TextStyle = oDSStyle.ActiveObjectDefaults.ViewLabelStyle
		Next
	Next
End Sub

 

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 18

Stakin
Collaborator
Collaborator
Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTBDefs As TitleBlockDefinitions = oDDoc.TitleBlockDefinitions

	Dim oSheetSizesList As New List(Of String)
	oSheetSizesList.AddRange({"A0", "A1", "A2", "A3", "A4" })
	Dim oChoice As String = InputListBox("Choose Sheet Size.", oSheetSizesList)
	MsgBox("You chose " & oChoice, , "")

	Dim oChangedSheetSize As Boolean = False
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		'run the Function defined below to update sheet sizes & title blocks
		oChangedSheetSize = UpdateSheet(oSheet, oChoice, oTBDefs)
	Next

	Call ChangeStdStyle(oDDoc, oChoice)
	Call UpdateStylesOfExisting(oDDoc, oChoice)
End Sub

Function UpdateSheet(oSht As Inventor.Sheet, oSize As String, oTBDs As TitleBlockDefinitions) As Boolean
	Dim oTargetSheetSize As DrawingSheetSizeEnum
	
	Select Case oSize
		Case "A0"
			'specify desired sheet size
			oTargetSheetSize = DrawingSheetSizeEnum.kA0DrawingSheetSize
		Case "A1"
			oTargetSheetSize = DrawingSheetSizeEnum.kA1DrawingSheetSize
		Case "A2"
			oTargetSheetSize = DrawingSheetSizeEnum.kA2DrawingSheetSize
		Case "A3"
			oTargetSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
		Case "A4"
			oTargetSheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize
	End Select
	
	If oSht.Size <> oTargetSheetSize Then
		oSht.Size = oTargetSheetSize
		oChangedSheetSize = True
	End If
	
	'now deal with changing the title block
	Dim oTBDef As TitleBlockDefinition
	Dim oTBDefName As String = oSize & "-TTBL"
	Try
		oTBDef = oTBDs.Item(oTBDefName)
	Catch
		MsgBox("Couldn't find a Title Block Definition named '" & oTBDefName & "'.", , "")
		Return False
		Exit Function
	End Try
	If Not oSht.TitleBlock Is Nothing Then
		oSht.TitleBlock.Delete
	End If
	oSht.AddTitleBlock(oTBDef)
End Function

Sub ChangeStdStyle(oDrawDoc As DrawingDocument, oSize As String)
	Dim oSMgr As DrawingStylesManager = oDrawDoc.StylesManager
	Dim oDSStyle As DrawingStandardStyle
	'naming scheme for your DrawingStandardStyles within your Styles Manager
	'<<<<< THESE DRAWING STANDARD STYLES MUST EXIST FIRST >>>>>>
	Dim oDSStyleName As String = oSize & "-DSS"
	
	Try
		oDSStyle = oSMgr.StandardStyles.Item(oDSStyleName)
	Catch
		MsgBox("Couldn't find a DrawingStandardStyle named '" & oDSStyleName & "'.", , "")
		Exit Sub
	End Try
	If oDSStyle IsNot Nothing Then
		oSMgr.ActiveStandardStyle = oDSStyle
		
	End If
End Sub

Sub UpdateStylesOfExisting(oDrawDoc As DrawingDocument, oSize As String)
	Dim oDSStyle As DrawingStandardStyle = oDrawDoc.StylesManager.ActiveStandardStyle
	'just changing the standard won't change these pre-existing objects, it will only effect new objects of these types you create

	For Each oSheet As Sheet In oDrawDoc.Sheets
		'update dimension styles to comply with new stantard
		For Each oGDim As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions
			'assumes the style you use for LinearDimensions is the same style used for all GeneralDimensions 
			oGDim.Style = oDSStyle.ActiveObjectDefaults.LinearDimensionStyle
		Next
		For Each oBLDimSet As BaselineDimensionSet In oSheet.DrawingDimensions.BaselineDimensionSets
			oBLDimSet.Style = oDSStyle.ActiveObjectDefaults.BaselineDimensionStyle
		Next
		For Each oChDimSet As ChainDimensionSet In oSheet.DrawingDimensions.ChainDimensionSets
			oChDimSet.Style = oDSStyle.ActiveObjectDefaults.ChainDimensionStyle
		Next
		For Each oOrdDimSet As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
			oOrdDimSet.Style = oDSStyle.ActiveObjectDefaults.OrdinateSetDimensionStyle
		Next
		
		'update leader styles
		For Each oLNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes
			oLNote.DimensionStyle = oDSStyle.ActiveObjectDefaults.LeaderTextStyle
		Next
		
		'update the view label styles
		For Each oView As DrawingView In oSheet.DrawingViews
			oView.Label.TextStyle = oDSStyle.ActiveObjectDefaults.ViewLabelStyle
		Next
	Next
End Sub

@WCrihfield, I modify some of your code and the template of @tkch.ndq ,it  runs  perfectly.

It can do all the function @tkch.ndq want.

Just download the template ,and run the code.

Message 13 of 18

Stakin
Collaborator
Collaborator

Sorry,Please change the code as below, I modified some of it. @tkch.ndq @WCrihfield 

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTBDefs As TitleBlockDefinitions = oDDoc.TitleBlockDefinitions

	Dim oSheetSizesList As New List(Of String)
	oSheetSizesList.AddRange({"A0", "A1", "A2", "A3", "A4" })
	Dim oChoice As String = InputListBox("Choose Sheet Size.", oSheetSizesList)
	MsgBox("You chose " & oChoice, , "")

	Dim oChangedSheetSize As Boolean = False
	
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		'run the Function defined below to update sheet sizes & title blocks
		oChangedSheetSize = UpdateSheet(oSheet, oChoice, oTBDefs)
		If oChangedSheetSize Then
		'run the Sub defined below to change the active drawing standard style
			Call ChangeStdStyle(oDDoc, oChoice)
		'run the Sub defined below to update all existing objects to conform to the new stantard styles
			Call UpdateStylesOfExisting(oDDoc, oChoice)
		End If
	Next

'	Call ChangeStdStyle(oDDoc, oChoice)
'	Call UpdateStylesOfExisting(oDDoc, oChoice)
End Sub

Function UpdateSheet(oSht As Inventor.Sheet, oSize As String, oTBDs As TitleBlockDefinitions) As Boolean
	Dim oTargetSheetSize As DrawingSheetSizeEnum
	
	Select Case oSize
		Case "A0"
			'specify desired sheet size
			oTargetSheetSize = DrawingSheetSizeEnum.kA0DrawingSheetSize
		Case "A1"
			oTargetSheetSize = DrawingSheetSizeEnum.kA1DrawingSheetSize
		Case "A2"
			oTargetSheetSize = DrawingSheetSizeEnum.kA2DrawingSheetSize
		Case "A3"
			oTargetSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
		Case "A4"
			oTargetSheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize
	End Select
	Dim oChangedSheetSize As Boolean = False
	If oSht.Size <> oTargetSheetSize Then
		oSht.Size = oTargetSheetSize
		oChangedSheetSize = True
	End If
	
	'now deal with changing the title block
	Dim oTBDef As TitleBlockDefinition
	Dim oTBDefName As String = oSize & "-TTBL"
	Try
		oTBDef = oTBDs.Item(oTBDefName)
	Catch
		MsgBox("Couldn't find a Title Block Definition named '" & oTBDefName & "'.", , "")
		Return False
		Exit Function
	End Try
	If Not oSht.TitleBlock Is Nothing Then
		oSht.TitleBlock.Delete
	End If
	oSht.AddTitleBlock(oTBDef)
	UpdateSheet = oChangedSheetSize
	
End Function

Sub ChangeStdStyle(oDrawDoc As DrawingDocument, oSize As String)
	Dim oSMgr As DrawingStylesManager = oDrawDoc.StylesManager
	Dim oDSStyle As DrawingStandardStyle
	'naming scheme for your DrawingStandardStyles within your Styles Manager
	'<<<<< THESE DRAWING STANDARD STYLES MUST EXIST FIRST >>>>>>
	Dim oDSStyleName As String = oSize & "-DSS"
	If oSMgr.ActiveStandardStyle.Name <> oDSStyleName Then		
		Try
			oDSStyle = oSMgr.StandardStyles.Item(oDSStyleName)
		Catch
			MsgBox("Couldn't find a DrawingStandardStyle named '" & oDSStyleName & "'.", , "")
			Exit Sub
		End Try		
		If oDSStyle IsNot Nothing Then
			oSMgr.ActiveStandardStyle = oDSStyle		
		End If
	End If
	
End Sub

Sub UpdateStylesOfExisting(oDrawDoc As DrawingDocument, oSize As String)
	Dim oDSStyle As DrawingStandardStyle = oDrawDoc.StylesManager.ActiveStandardStyle
	'just changing the standard won't change these pre-existing objects, it will only effect new objects of these types you create
	Dim oSheet As Sheet
	oSheet= oDrawDoc.ActiveSheet
		'update dimension styles to comply with new stantard
		For Each oGDim As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions
			'assumes the style you use for LinearDimensions is the same style used for all GeneralDimensions 
			oGDim.Style = oDSStyle.ActiveObjectDefaults.LinearDimensionStyle
		Next
		For Each oBLDimSet As BaselineDimensionSet In oSheet.DrawingDimensions.BaselineDimensionSets
			oBLDimSet.Style = oDSStyle.ActiveObjectDefaults.BaselineDimensionStyle
		Next
		For Each oChDimSet As ChainDimensionSet In oSheet.DrawingDimensions.ChainDimensionSets
			oChDimSet.Style = oDSStyle.ActiveObjectDefaults.ChainDimensionStyle
		Next
		For Each oOrdDimSet As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
			oOrdDimSet.Style = oDSStyle.ActiveObjectDefaults.OrdinateSetDimensionStyle
		Next
		
		'update leader styles
		For Each oLNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes
			oLNote.DimensionStyle = oDSStyle.ActiveObjectDefaults.LeaderTextStyle
		Next
		
		'update the view label styles
		For Each oView As DrawingView In oSheet.DrawingViews
			oView.Label.TextStyle = oDSStyle.ActiveObjectDefaults.ViewLabelStyle
		Next
End Sub

 

0 Likes
Message 14 of 18

tkch.ndq
Participant
Participant

Really thank you for all your help! @WCrihfield @Stakin 

@Stakin 

The second completed code which you modified, I receive error message when I run it.

The first completed code you gave is almost perfect, this is really what I'd like to do. Thank you very much!

Can you please also help me to replace old section leader (SAMPLE SECTION) and old text (SAMPLE TEXT) in the new attachment bellow?

I see message bellow when I run the code, can you please help me how to fix it?

tkchndq_0-1625717216620.png

Thanks so much in advance!

0 Likes
Message 15 of 18

Stakin
Collaborator
Collaborator

The sketch note style and the general note style are changed, but I can‘t  find the way to change the view annotation style.By now,It can only  be changed manually.

The below code runs properly on my machine,please try it on yours.

Solved: iLogic - Replacing Datum ID and View Annotation Styles - Autodesk Community - Inventor

 

 

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTBDefs As TitleBlockDefinitions = oDDoc.TitleBlockDefinitions

	Dim oSheetSizesList As New List(Of String)
	oSheetSizesList.AddRange({"A0", "A1", "A2", "A3", "A4" })
	Dim oChoice As String = InputListBox("Choose Sheet Size.", oSheetSizesList)
	MsgBox("You chose " & oChoice, , "")

	Dim oChangedSheetSize As Boolean = False
	
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		'run the Function defined below to update sheet sizes & title blocks
		oChangedSheetSize = UpdateSheet(oSheet, oChoice, oTBDefs)
		If oChangedSheetSize Then
		'run the Sub defined below to change the active drawing standard style
			Call ChangeStdStyle(oDDoc, oChoice)
		'run the Sub defined below to update all existing objects to conform to the new stantard styles
			Call UpdateStylesOfExisting(oDDoc, oChoice)
		End If
	Next

'	Call ChangeStdStyle(oDDoc, oChoice)
'	Call UpdateStylesOfExisting(oDDoc, oChoice)
End Sub

Function UpdateSheet(oSht As Inventor.Sheet, oSize As String, oTBDs As TitleBlockDefinitions) As Boolean
	Dim oTargetSheetSize As DrawingSheetSizeEnum
	
	Select Case oSize
		Case "A0"
			'specify desired sheet size
			oTargetSheetSize = DrawingSheetSizeEnum.kA0DrawingSheetSize
		Case "A1"
			oTargetSheetSize = DrawingSheetSizeEnum.kA1DrawingSheetSize
		Case "A2"
			oTargetSheetSize = DrawingSheetSizeEnum.kA2DrawingSheetSize
		Case "A3"
			oTargetSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
		Case "A4"
			oTargetSheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize
	End Select
	Dim oChangedSheetSize As Boolean = False
	If oSht.Size <> oTargetSheetSize Then
		oSht.Size = oTargetSheetSize
		oChangedSheetSize = True
	End If
	
	'now deal with changing the title block
	Dim oTBDef As TitleBlockDefinition
	Dim oTBDefName As String = oSize & "-TTBL"
	Try
		oTBDef = oTBDs.Item(oTBDefName)
	Catch
		MsgBox("Couldn't find a Title Block Definition named '" & oTBDefName & "'.", , "")
		Return False
		Exit Function
	End Try
	If Not oSht.TitleBlock Is Nothing Then
		oSht.TitleBlock.Delete
	End If
	oSht.AddTitleBlock(oTBDef)
	UpdateSheet = oChangedSheetSize
	
End Function

Sub ChangeStdStyle(oDrawDoc As DrawingDocument, oSize As String)
	Dim oSMgr As DrawingStylesManager = oDrawDoc.StylesManager
	Dim oDSStyle As DrawingStandardStyle
	'naming scheme for your DrawingStandardStyles within your Styles Manager
	'<<<<< THESE DRAWING STANDARD STYLES MUST EXIST FIRST >>>>>>
	Dim oDSStyleName As String = oSize & "-DSS"
	If oSMgr.ActiveStandardStyle.Name <> oDSStyleName Then		
		Try
			oDSStyle = oSMgr.StandardStyles.Item(oDSStyleName)
		Catch
			MsgBox("Couldn't find a DrawingStandardStyle named '" & oDSStyleName & "'.", , "")
			Exit Sub
		End Try		
		If oDSStyle IsNot Nothing Then
			oSMgr.ActiveStandardStyle = oDSStyle		
		End If
	End If
	
End Sub

Sub UpdateStylesOfExisting(oDrawDoc As DrawingDocument, oSize As String)
	Dim oDSStyle As DrawingStandardStyle = oDrawDoc.StylesManager.ActiveStandardStyle
	'just changing the standard won't change these pre-existing objects, it will only effect new objects of these types you create
	Dim oSheet As Sheet
	oSheet = oDrawDoc.ActiveSheet
	
		'update dimension styles to comply with new stantard
		For Each oGDim As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions
			'assumes the style you use for LinearDimensions is the same style used for all GeneralDimensions 
			oGDim.Style = oDSStyle.ActiveObjectDefaults.LinearDimensionStyle
		Next
		
		For Each oBLDimSet As BaselineDimensionSet In oSheet.DrawingDimensions.BaselineDimensionSets
			oBLDimSet.Style = oDSStyle.ActiveObjectDefaults.BaselineDimensionStyle
		Next
		For Each oChDimSet As ChainDimensionSet In oSheet.DrawingDimensions.ChainDimensionSets
			oChDimSet.Style = oDSStyle.ActiveObjectDefaults.ChainDimensionStyle
		Next
		
		For Each oOrdDimSet As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
			oOrdDimSet.Style = oDSStyle.ActiveObjectDefaults.OrdinateSetDimensionStyle
		Next
		
		'update leader styles
		For Each oLNote As LeaderNote In oSheet.DrawingNotes.LeaderNotes
			oLNote.DimensionStyle = oDSStyle.ActiveObjectDefaults.LeaderTextStyle
		Next
		For Each oGNote As GeneralNote In oSheet.DrawingNotes.GeneralNotes
			oGNote.TextStyle  = oDSStyle.ActiveObjectDefaults.GeneralNoteStyle
		Next
		

		
		For Each oDrawingsketch As DrawingSketch In oSheet.Sketches
			For Each oTextBox As TextBox In oDrawingsketch.TextBoxes
				oTextBox.Style = oDSStyle.ActiveObjectDefaults.SketchTextStyle
			Next
		Next
		
		'update the view label styles
		For Each oView As DrawingView In oSheet.DrawingViews
		
			oView.Label.TextStyle = oDSStyle.ActiveObjectDefaults.ViewLabelStyle
		Next
		
End Sub

 

 

 

 

0 Likes
Message 16 of 18

Stakin
Collaborator
Collaborator

Please change 

		For Each oDrawingsketch As DrawingSketch In oSheet.Sketches
			For Each oTextBox As TextBox In oDrawingsketch.TextBoxes
				oTextBox.Style = oDSStyle.ActiveObjectDefaults.SketchTextStyle
			Next
		Next

To

		For Each oDrawingsketch As DrawingSketch In oSheet.Sketches
			For Each oTextBox As TextBox In oDrawingsketch.TextBoxes
				oTextBox.Style = oDSStyle.ActiveObjectDefaults.SketchTextStyle
			Next
			oDrawingsketch.Edit
			oDrawingsketch.ExitEdit
		Next

 

0 Likes
Message 17 of 18

tkch.ndq
Participant
Participant

Thank you very much for all your help!

My issue is solved.

Wish you all have nice day!

 

0 Likes
Message 18 of 18

Stakin
Collaborator
Collaborator

You're welcome. It's a pleasure to help. But your template is very special. It is usually to modify the scale of the drawing, not the font or symbol size. Your template file is very large, which leads to the large size of the drawing file.

I suggest that you also accept @WCrihfield @ reply as a solution. After all, all these are modified in @WCrihfield @ code.

0 Likes