Plot in Inventor

Plot in Inventor

Anonymous
Not applicable
578 Views
4 Replies
Message 1 of 5

Plot in Inventor

Anonymous
Not applicable

Hello:

 

I am trying to create a routine to plot in Inventor.

 

When it gets to oSheet.Activate (text in red below), I get a Run-time error 5:  Invalid procedure call or argument.

 

Any help would be appreciated.  I believe the logic is correct, pending any API changes from prior versions.  Can you recommend a good book on API programming?

 

Thanks.

 

 

 

Private Sub cmdPlot_Click()
' Define application
Dim oApp As Inventor.Application
Set oApp = ThisApplication

 

' Define document
Dim oCurrentDoc As DrawingDocument
Set oCurrentDoc = oApp.ActiveDocument

 

' Define sheets
Dim oSheets As Sheets
Set oSheets = oCurrentDoc.Sheets

Dim oSheet As Sheet
Set oSheet = oCurrentDoc.Sheets.Item(1)

 

' Define print manager
Dim oPM As DrawingPrintManager
Set oPM = oCurrentDoc.PrintManager

 

' Get sheet size
Dim xx As Integer
Dim xy As Integer

Select Case oSheet.Size
Case kADrawingSheetSize
xx = (6 * 2.54)
xy = (3.12 * 2.54)

Case kBDrawingSheetSize
xx = (12 * 2.54)
xy = (3.12 * 2.54)

Case kCDrawingSheetSize
xx = (17 * 2.54)
xy = (3.12 * 2.54)

Case kDDrawingSheetSize
xx = (29 * 2.54)
xy = (3.12 * 2.54)

Case kEDrawingSheetSize
xx = (37 * 2.54)
xy = (3.12 * 2.54)

End Select

For Each oSheet In oSheets
oSheet.Activate


' Create a new sketch on the active sheet
Dim oSketch As DrawingSketch
Set oSketch = oCurrentDoc.ActiveSheet.Sketches.Add

' Open sketch for edit so the texhbox can be created
oSketch.Edit

Dim oTG As TransientGeometry
Set oTG = oApp.TransientGeometry

Dim sText As String
sText = txtStampText.Text

Dim oTextBox As Inventor.TextBox
Set oTextBox = oSketch.tectboxes.AddFitted(oTG.CreatePoint2d(xx, xy), sText)

oSketch.ExitEdit

' Requires plot to activate text
oPM.PrintToFile ("c:\temp\tmpinventor.plot")

' Predefine printers
Dim PRN As String
PRN = "\\PS64\HP Color LaserJet M750dn"

Dim PLT As String
PLT = "\\PS64\HP T2500"

oPM.ScaleMode = kPrintFullScale
oPM.PrintRange = kPrintAllSheets

Select Case oSheet.Size
Case kADrawingSheetSize
oPM.Printer = PRN
oPM.PaperSize = kPaperSizeLetter
oPM.Orientation = kLandscapeOrientation

Case kBDrawingSheetSize
oPM.Printer = PRN
oPM.PaperSize = kPaperSize11x17
oPM.Orientation = kLandscapeOrientation

Case kCDrawingSheetSize
oPM.Printer = PLT
oPM.PaperSize = kPaperSizeCSheet
oPM.Orientation = kLandscapeOrientation

Case kDDrawingSheetSize
oPM.Printer = PLT
oPM.PaperSize = kPaperSizeDSheet
oPM.Orientation = kLandscapeOrientation

Case kEDrawingSheetSize
oPM.Printer = PLT
oPM.PaperSize = kPaperSizeESheet
oPM.Orientation = kLandscapeOrientation

End Select

oPM.SubmitPrint

oSketch.Delete

Next

End Sub

0 Likes
Accepted solutions (2)
579 Views
4 Replies
Replies (4)
Message 2 of 5

Owner2229
Advisor
Advisor

Hi, you have already "oSheet" once declared with a value assigned, so you can try to declare a new one.

Don't forget to also change the variable in your following Select Case.

 

' ...
End Select

Dim xSheet As Sheet For Each xSheet In oSheets xSheet.Activate
' ...
Select Case xSheet.Size
' ...

There might be also something else in it, but for now you can give it a try.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 5

Anonymous
Not applicable

Dont I need to establish oSheet as a variable to use it?  I do not see it declared twice.  This code ran great in VB6, struggling in VBA...

0 Likes
Message 4 of 5

Owner2229
Advisor
Advisor
Accepted solution

Hi, these are first some rows of your code:

 

Private Sub cmdPlot_Click()
' Define application
Dim oApp As Inventor.Application
Set oApp = ThisApplication
 
' Define document
Dim oCurrentDoc As DrawingDocument
Set oCurrentDoc = oApp.ActiveDocument
 
' Define sheets
Dim oSheets As Sheets
Set oSheets = oCurrentDoc.Sheets
Dim oSheet As Sheet ' Here is oSheet declared
Set oSheet = oCurrentDoc.Sheets.Item(1) ' Here is it given value
' ...
' ...
End Select For Each oSheet In oSheets ' Here it is used to go through every sheet in sheets oSheet.Activate
' ...

 

Just try it with the xSheet.

 

You can also try to put this line before oSheet.Activate, as there might be an invalid sheet in your drawing.

' ...
If oSheet Is Nothing Then Continue For
oSheet.Activate
' ...
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

I have no idea why the program works now. I haven't even looked at it for two weeks or changed anything, but when I loaded and ran it today everything ran fine.

 

Thenks for your response.

0 Likes