Looking for a snippet of code that will copy the view label "layout" from the current drawing template to older drawings

Looking for a snippet of code that will copy the view label "layout" from the current drawing template to older drawings

chris
Advisor Advisor
159 Views
2 Replies
Message 1 of 3

Looking for a snippet of code that will copy the view label "layout" from the current drawing template to older drawings

chris
Advisor
Advisor

What I am trying to do is copy the view label layout from our newer drawing template into older drawings that are being "copy design'd".

 

Currently I am having to hand type all of these and there doesn't seem to be a way to update the older drawing "styles" to the new drawing styles "with" the updated view label layout, without of course opening each drawing and copying it in "by hand".

 

A little iLogic help would be appreciated... 

 

The current layout is as follows:

 

<Part Number> <Description>

SCALE: <Scale>

EST> WEIGHT: <Mass>

QTY> REQUIRED: <prompted entry>

0 Likes
160 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @chris.  Once again, pretty busy at work, and computer 'buffering' while processing a large assembly, so no chance to create a quick code at the moment, so I decided to post Links to the code path needed to get the job done.  Links below:

DrawingDocument.StylesManager 

DrawingStylesManager 

DrawingStylesManager.ActiveStandardStyle 

DrawingStandardStyle 

DrawingStandardStyle.GetViewLabelDefaults 

DrawingStandardStyle.SetViewLabelDefaults 

But perhaps the more proper way to handle this would be to save the DrawingStandardStyle from within your newer template up to the global style library, to make it available to all other drawings.  Then, when you open older drawings, either copy that style from the global styles library, or if the same style name as used in older ones, update existing style in older drawings to match style in style library.

DrawingStandardStyle.SaveToGlobal 

DrawingStandardStyle.UpdateFromGlobal 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Here is an example iLogic rule for taking the 'longer route' alluded to by my first several links above.  Likely not very ideal way to do it, but here it is anyways.  Be careful, because I have not tested this yet myself, because I have no use for it.  I included some comments within the code to attempt to explain what the lines of code are supposed to be doing.

Sub Main
	'<<<< CHANGE THESE NEXT TWO LINES AS NEEDED >>>
	Dim sTemplateDrawing As String = "C:\Temp\My Drawing Template.idw"
	Dim sDwgStdStyleName As String = "Drawing Standard Style Name"
	
	'<<< now open template drawing (invisibly), so we can copy style from it
	'first make sure specified template file exists
	If Not System.IO.File.Exists(sTemplateDrawing) Then
		MsgBox("Drawing Template File Not Found!", vbCritical, "Template Not Found")
		Return
	End If
	'open the template drawing invisibly, so that we can access its contents
	Dim oTemplate As DrawingDocument = ThisApplication.Documents.Open(sTemplateDrawing, False)
	'get specified DrawingStandardStyle object from it
	Dim oTemplateStdStyles As DrawingStandardStylesEnumerator = oTemplate.StylesManager.StandardStyles
	'create variable to hold DrawingStandardStyle when found
	Dim oTemplateStdStyle As DrawingStandardStyle = Nothing
	Try 'try to get that style using the specified name
		oTemplateStdStyle = oTemplateStdStyles.Item(sDwgStdStyleName)
	Catch 'don't react to any error
	End Try
	'if not found, let user know, then exit rule
	If oTemplateStdStyle Is Nothing Then
		MsgBox("DrawingStandardStyle named '" & sDwgStdStyleName & "' could not be found in template!", _
		vbCritical, "Source DrawingStandardStyle Not Found")
		Return
	End If
	
	'<<< get current drawing - assuming current Document is an older drawing that you want to update
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	'<<< get old drawing's DrawingStylesManager
	Dim oStMgr As DrawingStylesManager = oDDoc.StylesManager
	'<<< get old drawing's Active DrawingStandardStyle
	Dim oActiveStdStyle As DrawingStandardStyle = oStMgr.ActiveStandardStyle

	'<<< prepare necessary variables for extracting needed data from that style
	Dim eViewType As DrawingViewTypeEnum
	Dim sPrefix, sFText As String
	Dim bVisible, bConstToBorder, bPlaceBelowView As Boolean
	For Each eViewType In System.Enum.GetValues(GetType(Inventor.DrawingViewTypeEnum))
		'reset variable values, to make sure their values don't carry over (may not be necessary)
		sPrefix = ""
		sFText = ""
		bVisible = False 'default value of a Boolean
		bConstToBorder = False
		bPlaceBelowView = False
		oTemplateStdStyle.GetViewLabelDefaults(eViewType, sPrefix, bVisible, sFText, bConstToBorder, bPlaceBelowView)
		oActiveStdStyle.SetViewLabelDefaults(eViewType, sPrefix, bVisible, sFText, bConstToBorder, bPlaceBelowView)
	Next
	'<<< update drawing
	oDDoc.Update2(True)
	'<<< release reference to invisibly opened template document
	oTemplate.ReleaseReference() 'similar to Close method, but for invisibly opened documents
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes