drawing automatic

drawing automatic

Anonymous
Not applicable
882 Views
12 Replies
Message 1 of 13

drawing automatic

Anonymous
Not applicable

I have three parts a1.ipt, a2.ipt and a3.ipt

Now i want to have automatic drawing of these part in one drawing for one view (for example front view)

it's my code but it give me error

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
GoExcel.Open("C:\Users\a.khakbaz\Desktop\nozzle\ali.xlsx", "Sheet1")

Dim oDrawingDoc as DrawingDocument    
Dim oPartDoc as Document
Dim oSheet As sheet
Dim oTG As TransientGeometry
Dim oView1 as DrawingView
Dim sFilePath As String= ThisDoc.Path & "\"

For i=2 To 4     
dwgQuery=MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection")
sNewName=GoExcel.CellValue("A" & i)
If dwgQuery = vbYes Then
'    oPartDoc = ThisDoc.Document
    xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt")
    oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, _
        "test.idw", True)
    oSheet = oDrawingDoc.Sheets.Item(1)
    oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5#, 5#)
    oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _
        oPoint1, _
        1/1#, _
        kBottomViewOrientation, _
        kHiddenLineDrawingViewStyle)
        
'        Dim oApp As Application
oApp  = ThisApplication

Dim oActiveSheet As Sheet
oActiveSheet = oApp.ActiveDocument.ActiveSheet
oView1 = oActiveSheet.DrawingViews.Item(1)
        'rotate by 45 degrees (converted from Radians)
        'True = Clockwise 
        oView1.RotateByAngle(90*(PI / 180), False)
        oDrawingDoc.saveas(sFilePath & sNewName & ".idw",False)
End If
Next i



 

i write this code in part file which is name cube.ipt in second rule named drawing i want to get drawing in one file.

i send you my files in zip file.

inventor 2016 

0 Likes
883 Views
12 Replies
Replies (12)
Message 2 of 13

Owner2229
Advisor
Advisor

Hi, the "Test.idw" is the template used for the new drawing, so if you have your templates stored in a folder that is different then where this part is then you have to change the relative path (sFilePath & "Test.idw") to absolute.

Eg. If my template is named "TemplateOne.idw" and it is stored in "C:\MyTemplates\" then it will be:

 

Dim oTemplate As String = "C:\MyTemplates\TemplateOne.idw"

 

Here is the code with the relative path to your template.

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
GoExcel.Open("C:\Users\a.khakbaz\Desktop\nozzle\ali.xlsx", "Sheet1")

Dim oDrawingDoc as DrawingDocument    
Dim xDoc as Document
Dim oSheet As sheet
Dim oTG As TransientGeometry
Dim oView1 as DrawingView
Dim sFilePath As String= ThisDoc.Path & "\"
Dim sNewName As String
Dim oTemplate As String = sFilePath & "Test.idw"
For i = 2 To 4 dwgQuery = MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection") sNewName = GoExcel.CellValue("A" & i) If dwgQuery = vbYes Then xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt") oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, _ oTemplate , True) oSheet = oDrawingDoc.Sheets.Item(1) oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5#, 5#) oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _ oPoint1, _ 1/1#, _ kBottomViewOrientation, _ kHiddenLineDrawingViewStyle) Dim oActiveSheet As Sheet oActiveSheet = ThisApplication.ActiveDocument.ActiveSheet oView1 = oActiveSheet.DrawingViews.Item(1) 'rotate by 45 degrees (converted from Radians) 'True = Clockwise oView1.RotateByAngle(90*(PI / 180), False) oDrawingDoc.SaveAs(sFilePath & sNewName & ".idw",False) oDrawingDoc.Close(True)
xDoc.Close(True) End If Next i

 

And always don't forget to close your documents when you're done with them:

xDoc.Close(True)

The "True" means it will discard any changes, but it wont because we saved it before. It is there just so it wont pop up any more unnecessary dialog boxes.

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
Message 3 of 13

Anonymous
Not applicable
thanks
but it just creates a1.idw and a2.idw
i want to create these drawing in one file and also contain a3
is it possible?
0 Likes
Message 4 of 13

Owner2229
Advisor
Advisor

Sure, it is possible. Do you want the models to be all in one sheet or each in it's own?

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 13

Anonymous
Not applicable
SURE, i want to have them all in one file.
0 Likes
Message 6 of 13

Owner2229
Advisor
Advisor

Here is a solution that will place all three models in one sheet and save the drawing under the name of the part the rule was started in.

 

 

Dim oDrawingDoc As DrawingDocument    
Dim xDoc As Document
Dim oSheet As Sheet
Dim oTG As TransientGeometry
Dim oView1 As DrawingView
Dim sFilePath As String = ThisDoc.Path & "\"
Dim sNewName As String
Dim oTemplate As String = sFilePath & "Test.idw"
Dim oSaveName As String = ThisDoc.FileName(False) & ".idw"
dwgQuery = MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection") If dwgQuery = vbYes Then GoExcel.Open("C:\Users\a.khakbaz\Desktop\nozzle\ali.xlsx", "Sheet1") oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, _ oTemplate , True) oSheet = oDrawingDoc.Sheets.Item(1) For i = 2 To 4 sNewName = GoExcel.CellValue("A" & i) xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt") oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5*(i-1), 5) oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _ oPoint1, _ 1/1#, _ kBottomViewOrientation, _ kHiddenLineDrawingViewStyle) oView1 = oSheet.DrawingViews.Item(i-1) oView1.RotateByAngle(90*(PI / 180), False) Next i oDrawingDoc.SaveAs(oSaveName, False) oDrawingDoc.Close(True) xDoc.Close(True) GoExcel.Close(True) End If

 

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
Message 7 of 13

Anonymous
Not applicable
Error in rule: Rule5, in document: Cube.ipt

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

it just open the a1.ipt and drawing.idw files with no drawing and above error
0 Likes
Message 8 of 13

Owner2229
Advisor
Advisor

 

The "Imports" were missing in the code, among some other changes:

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Dim oDrawingDoc As DrawingDocument    
Dim xDoc As Document
Dim oSheet As Sheet
Dim oTG As TransientGeometry
Dim oView1 As DrawingView
Dim sFilePath As String = ThisDoc.Path & "\"
Dim sNewName As String
Dim oTemplate As String = sFilePath & "Test.idw"
Dim oSaveName As String = sFilePath & ThisDoc.FileName(False) & ".idw"
dwgQuery = MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection")
If dwgQuery = vbYes Then
    GoExcel.Open("C:\Users\a.khakbaz\Desktop\nozzle\ali.xlsx", "Sheet1")
    oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, _
        oTemplate , True)
    oSheet = oDrawingDoc.Sheets.Item(1)
    For i = 2 To 4
        sNewName = GoExcel.CellValue("A" & i)
        xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt", False)
        oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5*(i-1), 5)
        oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _
            oPoint1, _
            1/1#, _
            kBottomViewOrientation, _
            kHiddenLineDrawingViewStyle)
        oView1 = oSheet.DrawingViews.Item(i-1)
        oView1.RotateByAngle(90*(PI / 180), False)
        xDoc.Close(True)
    Next i
    oDrawingDoc.SaveAs(oSaveName, False)
    oDrawingDoc.Close(True)
    GoExcel.Close()
End If
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
Message 9 of 13

Anonymous
Not applicable
it just creates a1 and a2 view in drawing not a3...
why?
0 Likes
Message 10 of 13

Owner2229
Advisor
Advisor

I don't know, I tested it with the files you send and it worked just fine.

Did it throw an error or something?

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 11 of 13

Anonymous
Not applicable

i send my error, furthermore it did not save it. it just open a1.idw as shown in picture without saving...

Thank you for time that you spend for and i'm very thankful

now i want to post my main problem which some part are solved with your help.

i send the link of my post to you and any information and file that is needed send to see wheter is possible to solve..

Regards

Ali

0 Likes
Message 12 of 13

Anonymous
Not applicable
thank for time spending for me and i'm very thankful
i send you the picture of error and also it did not create view of a3 and did not save it (just open a1.idw)
In the below post i explain the big problem that i face it. i used your guidance but it still has problem
http://forums.autodesk.com/t5/inventor-customization/create-part-and-drawing-file-from-two-excel/m-p...
0 Likes
Message 13 of 13

Owner2229
Advisor
Advisor

I have corrected the last thing that might cause any problems. Are you running the rule from the original file (Cube.ipt) or from one of the childs (a1...) ?

I can make it work that way too, but it's just more work to do.

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Dim oDrawingDoc As DrawingDocument    
Dim xDoc As Document
Dim oSheet As Sheet
Dim oTG As TransientGeometry
Dim oView1 As DrawingView
Dim sFilePath As String = ThisDoc.Path & "\"
Dim sNewName As String
Dim oTemplate As String = sFilePath & "Test.idw"
Dim oSaveName As String = sFilePath & ThisDoc.FileName(False) & ".idw"
dwgQuery = MsgBox("Would you like to Create a drawing for this Nozzle&Flange?", vbYesNo,"Drawing Selection")
If dwgQuery = vbYes Then
    GoExcel.Open("C:\Users\a.khakbaz\Desktop\nozzle\ali.xlsx", "Sheet1")
    oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, _
        oTemplate , True)
    oSheet = oDrawingDoc.Sheets.Item(1)
    Dim j As Integer = 1
    For i = 2 To 4
        sNewName = GoExcel.CellValue("A" & i)
        xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt", False)
        oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5*(j), 5)
        oView1 = oSheet.DrawingViews.AddBaseView(xDoc, _
            oPoint1, _
            1/1#, _
            kBottomViewOrientation, _
            kHiddenLineDrawingViewStyle)
        oView1 = oSheet.DrawingViews.Item(j)
        oView1.RotateByAngle(90*(PI / 180), False)
        xDoc.Close(True)
        j = j + 1
    Next i
    oDrawingDoc.SaveAs(oSaveName, False)
    oDrawingDoc.Close(True)
    GoExcel.Close()
End If
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