AddBaseView run-time error

AddBaseView run-time error

Anonymous
Not applicable
435 Views
5 Replies
Message 1 of 6

AddBaseView run-time error

Anonymous
Not applicable

I am trying to create automated drawings using VBA, and am getting stuck when trying to create a drawing view. Specifically, I use the following code, which I have seen on several other forums:

 

 

Set oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, ThisApplication.TransientGeometry.CreatePoint2d(12, 15), 0.5, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

 

 

I know the issue is with the final two variables, as I have set up the others without any issues. It does not seem to matter whether or not I omit the “ViewOrientationTypeEnum” and “DrawingViewStyleEnum”. I still get a run-time error. I suspect I need to import these classes somehow? When I view them on the Object Browser, these classes have a certain(two yellow rectangles) symbol next to them, whereas the other classes which have worked for me have a different symbol next to them. Could this be part of the issue? I am using Inventor 2019, for reference. Any help would be much appreciated!

0 Likes
436 Views
5 Replies
Replies (5)
Message 2 of 6

Sergio.D.Suárez
Mentor
Mentor

Hello, welcome to the forum!
Try replacing with this line

 

 

      Set oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, ThisApplication.TransientGeometry.CreatePoint2d(12, 15), 0.5, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "Default")  

However I think you should attach your complete code so you can see more clearly where the problem might be. Regards!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thank you for the fast reply! I have attached my full code from the module in a txt file.

 

Unfortunately that did not do the trick... I still get Run-time error '-2147467259 (80004005)' Method 'AddBaseView' of object 'DrawingViews' failed

 

It generates the drawing, but runs into problems when trying to create the base view. If you have any other ideas that would be fantastic though!

0 Likes
Message 4 of 6

Anonymous
Not applicable

Thank you for the fast reply! I have attached my code in a txt file. Unfortunately I still get the same 'Run-time error '-2147467259 (80004005)': method 'AddBaseView' of object 'DrawingViews' failed

 

The drawing file is created with no problems, but trying to add the drawing view creates issues. If you have any other ideas that would be fantastic!

 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Thank you for the fast reply! Unfortunately, even with that change, I still get:

Run-time error ‘-2147467259 (80004005)’: Method ‘AddBaseView’ of object ‘DrawingViews’ failed

 

I have attached my code in a txt file. The drawing file is created with no problems, but trying to add drawing views causes issues… if you have any other suggestions that would be fantastic!

0 Likes
Message 6 of 6

Sergio.D.Suárez
Mentor
Mentor

Sorry for taking a long time to answer, try this code, set the routes well at the beginning, otherwise it will fail.
The error was in that you generated a new file instead of opening an existing one, and then you wanted to place a view of this file without saving, that's why you got that error.

 

Sub CreateDrawing()
DirTemplate = "C:\Users\Public\Documents\Autodesk\Inventor 2020\Templates\en-US\Metric\ISO.idw"
PartDir = "E:\Inventor\Planos en Inventor\550.05.06 Ch6.4.ipt"


    'Declare invDoc, which is the drawing being generated
    Dim invDoc As DrawingDocument
    'Set up drawing to use Gear Standard drawing template
    Set invDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, DirTemplate)
    
    
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Open(PartDir, False)
    
    Dim oSheet As Sheet
    Set oSheet = invDoc.Sheets.Item(1)
    
    Dim point1 As Point2d
    Set point1 = ThisApplication.TransientGeometry.CreatePoint2d(1, 1)
    
    Dim oBaseView As DrawingView
    Set oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, ThisApplication.TransientGeometry.CreatePoint2d(12, 15), 0.5, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "Default")
    
    oPartDoc.Close
    
    'Message box to indicate successful creation
    MsgBox "Created " & invDoc.DisplayName
    
End Sub

This code I have tried and it has worked for me. I hope it helps your final code
regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn