Run-time error with AddBaseView

Run-time error with AddBaseView

Anonymous
Not applicable
415 Views
2 Replies
Message 1 of 3

Run-time error with AddBaseView

Anonymous
Not applicable

I am at a road block, trying to use VBA to generate a drawing view. The drawing file is created no problem, but trying to use AddBaseView causes issues. I have attached my code to this post in a txt file. Any help is very much appreciated!

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

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

I reposition the code located in the other thread.
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.
This code I have tried and it has worked for me. I hope it helps your final code
regards

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

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

Message 3 of 3

Anonymous
Not applicable

That worked perfectly! Thank you so much for your help

0 Likes