Printing selected pages with Ilogic. How to clean the code?

Printing selected pages with Ilogic. How to clean the code?

FeelGoodGirl
Advocate Advocate
1,165 Views
8 Replies
Message 1 of 9

Printing selected pages with Ilogic. How to clean the code?

FeelGoodGirl
Advocate
Advocate

Hey,

 

I am working on a piece of code so that you can choose which pages you want to print and then print them immediately.

Explain.png

The code works fine. You choose the pages and print on printing and you can print the chosen pages. You need to be able to put a check mark on the sheet you want to print. Because of this there is a lot of extra code.

extra code.png

 

I was wondering if anyone knows how to clean up my code? Or maybe does someone knows another way to switch between true and false? For 3 pages it is still possible, but in the end I have a lot more pages.

 

Thanks in advance

 

Dim oDrgDoc As DrawingDocument
Dim oDrgPrintMgr As DrawingPrintManager

oDrgDoc = ThisApplication.ActiveDocument
oDrgPrintMgr = oDrgDoc.PrintManager

' Switch between true and false 
If Sheet1 = True Then 
		oSheet1 = False 
	Else 
		oSheet1 = True  
End If

If Sheet2 = True Then 
		oSheet2 = False 
	Else 
		oSheet2 = True  
End If

If Sheet3 = True Then 
		oSheet3 = False 
	Else 
		oSheet3 = True  
End If

' Provide the good status to the page
ThisDoc.Document.Sheets.Item("Sheet:1").ExcludeFromPrinting = oSheet1
ThisDoc.Document.Sheets.Item("Sheet:2").ExcludeFromPrinting = oSheet2
ThisDoc.Document.Sheets.Item("Sheet:3").ExcludeFromPrinting = oSheet3

'--------Printing--------
'Printer name
oDrgPrintMgr.Printer = "Microsoft Print to PDF"
oDrgPrintMgr.SetSheetRange(1,3)

'Paper size, scale and orientation
oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSize11x17
oDrgPrintMgr.PrintRange = PrintRangeEnum.kPrintSheetRange
oDrgPrintMgr.Orientation = PrintOrientationEnum.kLandscapeOrientation
oDrgPrintMgr.SubmitPrint()
0 Likes
Accepted solutions (2)
1,166 Views
8 Replies
Replies (8)
Message 2 of 9

mcgyvr
Consultant
Consultant

Using Case statements can help reduce "If/Then" complexity some.. 

Have you looked into that?



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 9

FeelGoodGirl
Advocate
Advocate

I would not know how this would make the code shorter and clearer ..... 🙈

0 Likes
Message 4 of 9

Anonymous
Not applicable
Accepted solution

You're wanting the value of oSheet1 to be the opposite of Sheet1 right? Try this:

oSheet1=Not(Sheet1)

This should return the opposite value and get rid of all the if-then statements. Hope this helps!

 

-Chancellor

 

 

Message 5 of 9

FeelGoodGirl
Advocate
Advocate

This was exactly what I needed. I did not know that there was a piece of code with which you could "flip" the value.

 

Thank you for your time!

0 Likes
Message 6 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @FeelGoodGirl 

 

Using  the suggestion of ckurre, you could use the exclude from printing function to set the selected sheets, and then use the Print Range enumerator kPrintAllSheets, so that it prints all sheets not set to be excluded, and then finally set all sheets back to be included at the end.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

oSheets = ThisDoc.Document.Sheets
'set print status based on checkboxes
oSheets.Item("Sheet:1").ExcludeFromPrinting = Not Parameter("Sheet1")
oSheets.Item("Sheet:2").ExcludeFromPrinting = Not Parameter("Sheet2")
oSheets.Item("Sheet:3").ExcludeFromPrinting = Not Parameter("Sheet3")

Dim oDrgDoc As DrawingDocument
Dim oDrgPrintMgr As DrawingPrintManager

oDrgDoc = ThisApplication.ActiveDocument
oDrgPrintMgr = oDrgDoc.PrintManager

'--------Printing--------
'Printer name
oDrgPrintMgr.Printer = "Microsoft Print to PDF"

' Set to print all sheets (all sheets not set to be excluded)
oDrgPrintMgr.PrintRange = kPrintAllSheets

'Paper size, scale and orientation
oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSize11x17
oDrgPrintMgr.Orientation = PrintOrientationEnum.kLandscapeOrientation
oDrgPrintMgr.SubmitPrint()

'set all sheets back to default ( to be printed)
For Each oSheet In oSheets	
	oSheets.Item(oSheet.name).ExcludeFromPrinting = False
Next


EESignature

Message 7 of 9

FeelGoodGirl
Advocate
Advocate

I have now succeeded in making my code smaller. However, other challenges have now emerged. For this I have started a new forum. Maybe you also have input on this.😀

 

https://forums.autodesk.com/t5/inventor-forum/printing-with-form/td-p/9291933

0 Likes
Message 8 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @FeelGoodGirl 

 

The reason the rule on your other thread was running automatically was this:

 

ThisDoc.Document.Sheets.Item("Sheet1:1").ExcludeFromPrinting = Not(Sheet1)

 

where as the version I posted on this thread had the parameter "wrapped" so that it did not trigger the rule when the parameter changed:

ThisDoc.Document.Sheets.Item("Sheet1:1").ExcludeFromPrinting = Not Parameter("Sheet1")

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

EESignature

Message 9 of 9

FeelGoodGirl
Advocate
Advocate

I didn't know this yet. I will certainly apply this. Thank you for the tip! 

0 Likes