Activate a sheet in a non visible file.

Activate a sheet in a non visible file.

shastu
Advisor Advisor
489 Views
3 Replies
Message 1 of 4

Activate a sheet in a non visible file.

shastu
Advisor
Advisor

You can do a lot of things with a drawing without ever visibly seeing it.  For example,

 

Set oNewDocument = ThisApplication.Documents.Open("FullFileNamePath", False)

 

My question is how do you activate the sheets when it is not showing?

 

For Example,  I have a For statement to delete the title block on each sheet:

 

For oSheetNumber = 1 To oDoc.Sheets.Count

oDoc.Sheets(oSheetNumber).Activate

Set oSheet = ThisApplication.ActiveDocument.ActivateSheet

oSheet.TitleBlock.Delete

Next

 

If the drawing is open and visible this works fine.  If the drawing is open but not visible the line

 

Set oSheet = ThisApplication.ActiveDocument.ActivateSheet

 

throws an error saying the Object variable is not set.

 

If I just comment it out, the titleblock on the active page is deleted but when I go to the next page I get an error upon the delete.

0 Likes
Accepted solutions (1)
490 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor
Accepted solution

The answer is that you don't need to activate a sheet to perform an operation on it.

 

Grabbing the sheet and assigning it to the variable still references the same sheet.

 

All calling the "Activate" method does is make it visible to the user.

 

Therefore, your code to do the same should be:

 

Set oDoc = ThisApplication.Documents.Open("FullFileNamePath", False)

For oSheetNumber = 1 To oDoc.Sheets.Count
            Set oSheet = oDoc.Sheets(oSheetNumber)
            oSheet.TitleBlock.Delete
Next

 

or use a for each loop if you don't need to keep track of which sheet it currently is on;

 

Set oDoc = ThisApplication.Documents.Open("FullFileNamePath", False)

For Each oSheet in oDoc.Sheets
       oSheet.TitleBlock.Delete
Next

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

shastu
Advisor
Advisor

What about deleting a Drawing Resource when the sheet is non visible?  When it is visible I use the DoSelect method, but when it is not visible this does not work.  Here is what I was wanting to accomplish:

 

 Set oPane = oDoc3.BrowserPanes.ActivePane

 Dim oDoc3Node As BrowserNode
 Set oDoc3Node = oPane.TopNode

 Set oDrawingResourceNode = oDoc3Node.BrowserNodes.Item("Drawing Resources")

 Dim oSheetFormatsNode As BrowserNode
 Set oSheetFormatsNode = oDrawingResourceNode.BrowserNodes.Item("Title Blocks")

 ' Get the specified sheet format node.
 Dim oSheetFormatNode As BrowserNode
 Set oSheetFormatNode = oSheetFormatsNode.BrowserNodes.Item("ANSI A")

 ' Select the node in the browser.
 oSheetFormatNode.DoSelect

 ' Execute the delete command.
 ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute

0 Likes
Message 4 of 4

shastu
Advisor
Advisor

Never mind.  I got it.

 

 Dim oBorderDefinition As BorderDefinition
 Dim oTitleBlockDefinition As TitleBlockDefinition

 For Each oTitleBlockDefinition In oDoc.TitleBlockDefinitions
    If oTitleBlockDefinition.Name = "ANSI A" Then
        oTitleBlockDefinition.Delete
    End If
 Next

0 Likes