- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The problem is in the iLogic named "UpdateDrwRecources".
The rule basically deletes all drawing recourses and afterward adds/replaces them by the ones from the drawing template.
When the rule is executed from the add-inn the deleting of existing borders (for example) is not working.
This screenshot shows the add-inn to execute the ilogic "Start"
When I outcomment the last step of the iLogic "UpdateDrwRecources" in which new drawing recources are added, I can see that the deleting is not happening, if the rule is executed initially by the add-inn (via ilogic Start in between):
(the rule itself is running if executed by add-inn, I could check that with message boxes)
sorry for the messy code:
Sub main
'List of Variables
Dim oDrawingDoc As Inventor.DrawingDocument
Dim oSheetNumber As Integer
Dim oActiveSheetNumber As Integer
Dim oActiveSheetName As String
Dim oSheet As Sheet
Dim oSourceTitleBlockDef As TitleBlockDefinition
Dim oNewTitleBlockDef As TitleBlockDefinition
Dim oBorderName As String
'Selects this document
'oDrawingDoc = ThisApplication.ActiveDocument
oDrawingDoc = ThisDoc.Document
'Checks if there is a Title Block on the Active Sheet
'oDrawingDoc = ThisApplication.ActiveDocument
If oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
MessageBox.Show ("Please Insert a Title Block on this Sheet!")
Exit Sub
End If
'Gets the Name of the Active Sheet to Activate it at the end of the Code
oActiveSheetName = ActiveSheet.Name
'Gets the Name of the Title Block Currently in the Drawing to Insert at the end of this code
oSheet = oDrawingDoc.ActiveSheet
If (oSheet.TitleBlock.Name = "company_name Title block") Then
oTitleBlockName = "company_name Title block"
Else:
MessageBox.Show ("This drawing has an unknown title block")
Exit Sub
End If
'Gets the Name of the Border Currently in the Drawing to Insert at the end of this code
Try
oBorderName = oSheet.Border.Name
Catch
MessageBox.Show("No border exists", "Title")
Exit Sub
End Try
'Deletes ALL of the Title Blocks Shown in the Drawing
For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(oSheetNumber).Activate
If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
oDrawingDoc.ActiveSheet.TitleBlock.Delete
End If
Next oSheetNumber
'MessageBox.Show (oActiveSheetName & vbCr & oTitleBlockName)
Dim oTitle As TitleBlockDefinition
Dim oTitleBlock As TitleBlock
For Each oTitle In oDrawingDoc.TitleBlockDefinitions
If oTitle.IsReferenced = False Then
oTitle.Delete
End If
Next
'Deletes ALL of the Borders Shown in the Drawing
For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(oSheetNumber).Activate
If Not oDrawingDoc.ActiveSheet.Border Is Nothing Then
oDrawingDoc.ActiveSheet.Border.Delete
End If
Next oSheetNumber
'Clear drawing resources
If oCurrentPane = "Vault" Then
ThisApplication.ActiveDocument.BrowserPanes.Item("Model").Activate
End If
'delete sheet formats
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.ActivePane
Dim oDocNode As BrowserNode
oDocNode = oPane.TopNode
Dim oDrawingResourceNode As BrowserNode
oDrawingResourceNode = oDocNode.BrowserNodes.Item("Drawing Resources")
Dim oTitleBlocksNode As BrowserNode
oTitleBlocksNode = oDrawingResourceNode.BrowserNodes.Item("Sheet Formats")
Dim oBordersNode As BrowserNode
oBordersNode = oDrawingResourceNode.BrowserNodes.Item("Borders")
Dim oTitleBlocks As BrowserNode
oTitleBlocks = oDrawingResourceNode.BrowserNodes.Item("Title Blocks")
Dim oNode As BrowserNode
For Each oNode In oTitleBlocksNode.BrowserNodes'oDocNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = False Then
oNode.Expanded = True
End If
Next
For Each oNode In oBordersNode.BrowserNodes'oDocNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = False Then
oNode.Expanded = True
End If
Next
For Each oNode In oTitleBlocks.BrowserNodes'oDocNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = False Then
oNode.Expanded = True
End If
Next
Dim oSheetFormatNode As BrowserNode
For Each oSheetFormatNode In oTitleBlocksNode.BrowserNodes
' Select the node in the browser.
oSheetFormatNode.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'Dim oBordersNode As BrowserNode
For Each oBordersNode In oBordersNode.BrowserNodes
' Select the node in the browser.
oBordersNode.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
For Each oTitleBlocks In oTitleBlocks.BrowserNodes
' Select the node in the browser.
oTitleBlocks.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'Adds the Title Blocks from the Template File
ThisDrawing.ResourceFileName = "C:\WS_company_name\Templates\Standard.idw"
ThisDrawing.KeepExtraResources = True
'ActiveSheet.TitleBlock = "company_name Title block"
'ActiveSheet.Border = oBorderName
'Add Borders
ActiveSheet.Border = "A1"
ActiveSheet.Border = "A2"
ActiveSheet.Border = "A3"
ActiveSheet.Border = "A4"
ActiveSheet.Border = "A0"
''Adds the Same Title Block as in the initial drawing
''due to the fact that we use different title blocks for different sub-companies we do not bring in the title block from the template anymore
For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(oSheetNumber).Activate
ActiveSheet.TitleBlock = oTitleBlockName
ActiveSheet.Border = oBorderName
Next oSheetNumber
'MsgBox(oBorderName)
''Activates the Sheet by Full Name
ActiveSheet = ThisDrawing.Sheet(oActiveSheetName)
'MsgBox("test: rule UpdateDrwRecources is executed now")
End Sub
I cannot figure out if there is a limitation to execute the delete command
' Execute the delete command. ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute Next
or if my code is not clear enough and it is unclear in which document the deleting should happen.
As I said, when the iLogic "Start" and through that the iLogic "UpdateDrwRecources" is run manually everything is working.
Do you have an advice for me?