07-03-2019
04:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
07-03-2019
04:42 AM
Hi, This code could be useful to you, at least it does not throw me errors. I retouch it a bit to simplify it.
Dim templateFile As String 'Create a drawing from the drawing template templateFile = "C:\VaultWorkingFolder\Designs\Templates\SilencerAssembly.idw" '''Place the path of your template idw Dim ViewScale As Double = 3 / 16 dwgQuery = MsgBox("Would you like to Create a drawing for this MODEL?", vbYesNo, "Drawing Selection") If dwgQuery=vbYes Dim oDoc As Document = ThisDoc.Document ' Part Document or Assembly Document Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,templateFile,True) oDrawingDoc.Activate() Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1) Dim oPoint1 As Point2d=ThisApplication.TransientGeometry.CreatePoint2d(1, 1) Dim oPoint2 As Point2d=ThisApplication.TransientGeometry.CreatePoint2d(1, 6) Dim oPoint3 As Point2d=ThisApplication.TransientGeometry.CreatePoint2d(5, 1) Dim oBaseView As DrawingView =oSheet.DrawingViews.AddBaseView(oDoc,oPoint1,ViewScale,ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle) Dim oView2 As DrawingView =oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint2, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle,ViewScale) Dim oView3 As DrawingView =oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint3, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle,ViewScale) End If
The idea that you propose is good, you could load all these fragments as subroutines sub - end sub and command them from a main sub main.
That's why I'll add a code below to place dimensions in the drawing views.
Sub main() Dim oDoc As Document = ThisDoc.Document If oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oViews As DrawingViews Dim oView As DrawingView Line1 : oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select view") If oView Is Nothing Then Exit Sub Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView) GoTo Line1 centrar_Cotas Else MessageBox.Show("Please, open a drawing file", "Retrieve dimensions") End If End Sub Sub centrar_Cotas Dim oDoc As DrawingDocument = ThisDoc.Document ' Set a reference to the active sheet Dim oSheet As Sheet = oDoc.ActiveSheet ' Iterate over all dimensions in the drawing and ' center them if they are linear or angular. For Each oDrawingDim As DrawingDimension In oSheet.DrawingDimensions If TypeOf oDrawingDim Is LinearGeneralDimension Or _ TypeOf oDrawingDim Is AngularGeneralDimension Then Call oDrawingDim.CenterText End If Next End Sub
This is a difficult issue, what this code does is to retrieve the dimensions of the drawing, something very useful when the workflow is directed thinking about how the part will be represented in a drawing.
With the code you select the views of the sheet where you need to retrieve the dimensions
I hope some of this help. 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