Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic zoom (fit) all IDW sheets

5 REPLIES 5
Reply
Message 1 of 6
axa-61
3235 Views, 5 Replies

iLogic zoom (fit) all IDW sheets

Hi, 

How to get all Inventor drawing sheets fit on PC screen. Example iLogic code below makes only Gasket:3 to fit the screen (always last one in the code chaine) . Nothing happens with  sheets :1 and  :2 .

 

ActiveSheet = ThisDrawing.Sheet("MainAssembly:1")
ThisApplication.ActiveView.Fit
ActiveSheet = ThisDrawing.Sheet("WeldAssembly:2")
ThisApplication.ActiveView.Fit
ActiveSheet = ThisDrawing.Sheet("Gasket:3")
ThisApplication.ActiveView.Fit

Inventor 2013 SP2
Windows 7, 64 bits
RAM 18GB
Core TM2 Duo CPU 2,99 Gz
5 REPLIES 5
Message 2 of 6
adam.nagy
in reply to: axa-61

Hi,

 

In the user interface as well, there can only be one sheet active at a time, so I don't think there is a way around that through the API.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 6
DRoam
in reply to: axa-61

@axa-61 and anyone else interested, below is some code that I just put together which will zoom all sheets in a drawing to the Zoom-Extents setting.

 

It gets around the issue @adam.nagy pointed out by actually activating each sheet one-by-one and zooming all. It then returns you to your previously-active sheet.

 

Because it has to activate each sheet, any sheets which take a long time to load or need to be updated will slow it down. But other than that, it's very snappy.

 

"Zoom Extents All Sheets" code:

Sub Main()
'Make sure the active document is a Drawing
If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then
	MessageBox.Show("The active document is not a drawing. The rule will now terminate.", "Sketch Symbol Auto-Numbering",MessageBoxButtons.OK,MessageBoxIcon.Error)
	Exit Sub
End If

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet

'Set a reference to the current Active sheet so we can re-activate it after the rule is done
Dim myActiveSheet As Sheet
myActiveSheet = oDrawDoc.ActiveSheet

'Start a transaction
Call ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Zoom Extents All Sheets")

'Progress bar
oMessage = "Zooming Extents on All Sheets..."
Dim SheetCount As Integer
SheetCount = oDrawDoc.Sheets.Count
Dim oProgressBar As Inventor.ProgressBar
oProgressBar = ThisApplication.CreateProgressBar(False,SheetCount,oMessage)

'Create sheet counter variable
Dim iSheetCount As Integer
iSheetCount=0

On Error Goto ErrorTrapper

'Iterate through each sheet and zoom to the sheet extents
For Each oSheet In oDrawDoc.Sheets
	'Get the current sheet number
	iSheetCount=iSheetCount+1
		
	'Activate the current sheet
	oSheet.Activate
		
	'Update the progress bar to reflect which sheet is being operated on
	oProgressBar.Message = ("Processing Sheet " & iSheetCount & " of " & SheetCount & "...")
	oProgressBar.UpdateProgress
		
	'Zoom to the sheet extents
	ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute	
Next 'Sheet

RuleExit:
'Re-activate the originally active sheet
myActiveSheet.Activate

'Close the progress bar
oProgressBar.Close

'End the transaction
ThisApplication.TransactionManager.EndTransaction
']
Exit Sub

ErrorTrapper:
MessageBox.Show("There was an error processing sheet " & iSheetCount & ". The rule will now terminate.", "Zoom Extents All Sheets",MessageBoxButtons.OK,MessageBoxIcon.Error)
Goto RuleExit

End Sub
Message 4 of 6
insomnix
in reply to: DRoam

This works great. I'm using it now in a slightly different application and I'm running into I minor issue. I am zooming using the AppZoomallCmd and then exporting an image using SaveAsBitmap. However, the image shows the background around the sheet like a thick border. I tested several ways to try to remove the "border" and the only success I've had was using a zoom window manually and select the corners of the sheet to zoom in further before export. Is there a way to zoom in further?

Message 5 of 6
MechMachineMan
in reply to: insomnix

You almost certainly need to use the view via Application.Views 

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-68F79E38-F7BD-4700-A08E-6E8E928C4825

 

Whether its tweaking the camera, or just the view width etc. is something you will have to figure out.

 

 

Another alternative could be to use the code to activate the Zoom to window command, but this would then require the user to manually select the window size.


--------------------------------------
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
Message 6 of 6
GarinBuckles6669
in reply to: DRoam

Thanks @DRoam for the jumping on this and providing a solution. I am a bit green to this process and need guidance on how and where to enter the code? Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report