Hello,
I'm Trying to do something similar to this for drafting support. I need a script that will allow a user to select from a list of values and pull from an if statement the corresponding file to apply a title block from the selected file to a target drawing file.
I am working with an existing script that was working at one time when we had only 1 drawing template.
We now want to maintain 4 templates for parts, sheet metal, assemblies and weldments. Each with styles and tolerances applied to the title block. So, I think I need to add a multi-value param and test it against a selected value.
But I haven't done this stuff in some time so any help would be appreciated.
'replace title block with 1 of 4 title blocks dependent on template type part, assembly, sheetmental or weldment
Sub Main()
'Check if the document is drawing
If ThisApplication.ActiveDocument Is Nothing Or ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then
MsgBox ("Please run this from a drawing.")
Exit Sub
End If
Dim oDrawingDoc As Inventor.DrawingDocument: oDrawingDoc = ThisApplication.ActiveDocument
Dim SheetNumber As Integer
' 'Transfer Prompted Text
iLogicVb.RunExternalRule("Xfer Prompted Text")
'Add Custom iProps
iLogicVb.RunExternalRule("Add Custom iProps")
'Clear out the old Titleblocks
For SheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(SheetNumber).Activate
If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
oDrawingDoc.ActiveSheet.TitleBlock.Delete
End If
Next SheetNumber
DeleteTitleBlocks(oDrawingDoc) 'CALLING SUBROUTINE
'create list to select from and call the title block selected to place in target drawing.
'----------------------------------------------------------
'----------------------------------------
'MultiValue.SetList("TemplateType", ), As String, ParamArray args As Object()(Part, Assembly, Sheet_Metal, Weldment)))
'test selection and apply file title block below.
If "TemplateType" =Part Then
ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\part.idw"
Else If "TemplateType" = Assembly Then
ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\assembly.idw"
Else If "TemplateType" = Sheet_Metal Then
ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\sheetmetal.idw"
Else If "TemplateType" = Weldment Then
ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\weldment.idw"
End If
ThisDrawing.KeepExtraResources = False
For Each oSheet In oDrawingDoc.Sheets
oSheet.Activate
ActiveSheet.TitleBlock = "MVPTLBLOCK"
ActiveSheet.Border = "MVP BORDER"
Next
'Change Line Weight
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
For Each oLayer In oDrawDoc.StylesManager.Layers
oLayer.LineWeight = 0.007 / 0.393701
Next
iLogicVb.UpdateWhenDone = True
ThisApplication.ActiveDocument.Sheets(1).Activate()
ThisApplication.ActiveView.Fit
ThisApplication.ActiveView.Fit
oModelBP = oDrawDoc.BrowserPanes.Item("DlHierarchy")
For Each oNode In oModelBP.TopNode.BrowserNodes
oNode.Expanded = False
Next
End Sub
'Subroutine
Sub DeleteTitleBlocks(oActiveDoc As Inventor.DrawingDocument)
'Iterate through the collection deleting any titleblocks that are not referenced by the drawing object
Dim oTitle As TitleBlockDefinition
For Each oTitle In oActiveDoc.TitleBlockDefinitions
If oTitle.IsReferenced = False Then
oTitle.Delete
End If
Next
End Sub