There is something basic that I am missing in drawing views.

There is something basic that I am missing in drawing views.

Anonymous
Not applicable
620 Views
3 Replies
Message 1 of 4

There is something basic that I am missing in drawing views.

Anonymous
Not applicable

This is my first Macro. This  Macro creates several parts and then assembles them in an assembly. It then exports a BOM. Until here everything works. I am having problems creating a drawing with a base view of the assembly. There is something basic that I am missing. Please see the code below.

 

Private Sub UserButtonz1_Click()

    '

 Create parts

    '

Save parts

   '

(opens assy)

Dim oDoc2 As AssemblyDocument
Set oDoc2 = ThisApplication.Documents.Add(kAssemblyDocumentObject, ThisApplication.FileManager.GetTemplateFile(kAssemblyDocumentObject))
   '

  (Saves assy)

Call oDoc2.SaveAs("C:\Documents and Settings\fu0328\Desktop\C\" & TextBox4 & ".iam", True)

   '

 Creates export BOM

  ' 

(saves BOM)

oPartsOnlyBOMView.Export "C:\Documents and Settings\fu0328\Desktop\C\" & TextBox4 & ".xls", kMicrosoftExcelFormat
   '

(Creates Drawing)

Dim oPartDoc As DrawingDocument

Set oPartDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, ThisApplication.FileManager.GetTemplateFile(kDrawingDocumentObject))

 

Dim oSheet As Sheet
Set oSheet = oPartDoc.ActiveSheet

 

Dim oPnt As Point2d
Set oPnt = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

 

Dim scaleFactor As Double
scaleFactor = 4#

 

Dim oBaseView As DrawingView

(This is where the error occures. I think the problem is at "oDoc2")
Set oBaseView = oSheet.DrawingViews.AddBaseView(oDoc2, oPnt, scaleFactor, kFrontViewOrientation, kHiddenLineDrawingViewStyle)

 

End Sub

 

Thank you for your time

WGM

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

YuhanZhang
Autodesk
Autodesk

Hi WGM,

 

When you save the new assembly you just save it as a copy onto disk, this means the oDoc2 is still an unsaved document:

 

 (Saves assy)
Call oDoc2.SaveAs("C:\Documents and Settings\fu0328\Desktop\C\" & TextBox4 & ".iam", True)

 

So you can save the assembly with setting the SaveAs("",False) to make sure the oDoc2 can be placed onto drawing.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks that seems to have fixed it. One other question, the default drawing sheet that I am getting is an "idw" type. How can I get a "dwg" sheet type?

 

Thanks again 

0 Likes
Message 4 of 4

YuhanZhang
Autodesk
Autodesk
Accepted solution

To new a darwing basing on Inventor DWG template(.dwg), you can do it as below sample:

 

 

Sub NewDrawingOnDWGTemplate()
    
    Dim oDrawingOptions As DrawingOptions
    Set oDrawingOptions = ThisApplication.DrawingOptions
    
    Dim eDefaultDrawingFileType As DefaultDrawingFileTypeEnum
    eDefaultDrawingFileType = oDrawingOptions.DefaultDrawingFileType
    
    ' Set the default drawing file type to DWG.
    oDrawingOptions.DefaultDrawingFileType = kDWGDefaultDrawingFileType
        
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, ThisApplication.FileManager.GetTemplateFile(kDrawingDocumentObject, kDefaultSystemOfMeasure))
    
    ' Reset the default drawing file type to default value.
    oDrawingOptions.DefaultDrawingFileType = eDefaultDrawingFileType
    
End Sub

 

 

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes