Hi everyone,
I'm trying to build a new template for our laser parts. I create a seperate sheet in my .idw for every laser part we need to buy. I do this because it's easier for us to sort the parts when they arrive. We don't have fancy machines because we're a fairly small business. I already found a iLogic code where you can create a new drawing from my template and place the part automatically.
But what I want to do is:
For example, I have the file "Laser Parts 1.idw"
Set "Laser Parts 1.idw" as the location where I need the next sheet
Press "Create Laser Part" in my .ipt
Then it creates a new sheet in "Laser Parts 1.idw" and places my part
Hope this is understandable and possible 😃
Greetz
Daniel
Solved! Go to Solution.
Solved by Ralf_Krieg. Go to Solution.
Hello
You can do this with this external rule. Your part file and the drawing file must be open. The part file must be the active document.
Private Sub main
'assume your laser part document is open and active
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDrawDoc As DrawingDocument
Dim oDoc As Document
For Each oDoc In ThisApplication.Documents
If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
If System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) = "Laser Parts 1" Then
oDrawDoc = oDoc
Exit For
End If
End If
Next
If oDrawDoc Is Nothing Then
MsgBox("Drawing file " & Chr(34) & "Laser Parts 1" & Chr(34) & " not open.", "iLogic")
Exit Sub
End If
Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
Dim oSheetSize As DrawingSheetSizeEnum = oActiveSheet.Size
Dim oOrientation As PageOrientationTypeEnum = oActiveSheet.Orientation
Dim sSheetName As String= System.IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)
Dim oWidth As Object = oActiveSheet.Width
Dim oHeight As Object=oActiveSheet.Height
Dim oSheet As Sheet = oDrawDoc.Sheets.Add(oSheetSize, oOrientation, sSheetName, oWidth, oHeight)
oSheet.AddTitleBlock(oActiveSheet.TitleBlock.Definition)
oSheet.AddDefaultBorder()
oSheet.Activate
Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width/2, oSheet.Height/2)
oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint,1,ViewOrientationTypeEnum.kFrontViewOrientation,DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle )
MsgBox("Done")
End Sub
Hey!
Thanks, it works 🙂
Is it possible to get a pop-up that wants you to pick a location of the idw?
Thanks
Daniel
Try this:
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.FileName = ThisDoc.FileName
oFileDlg.ShowSave()
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Hello
What do want to pick?
The drawing template to create a new LaserPart1.idw if not already open?
The drawing LaserPart1.idw if it's not already open?
The location for the drawing LaserPart1 to be saved to with/without new name?
I edited the code so that I can put the Name of my .idw file. In my case I saved the file as "200389-390 Brennteile.idw". Inventor now finds the opened idw and places my part on a new sheet. I'd like to have like a "Open" button and then pick my .idw through the windows explorer instead of writing down the name in a text field. I think it would look more professional, even if it's the same result.
BTW: I put quantities into my .ipt parts. I always have to adjust them to our order. For example we need 4 pieces for one assembly, but we have to build the same thing two times - so we need 8 pieces in total. Is it possible to write down 4 parts and then chose the amount of assemblies in the idw so it multiplies 2*4=8? (Independent from the .ipt, there should always be 4)
Hello
With this code snippet you can gat the full document name including path of the selected drawing document. This can be used to check if this document is already open or open it.
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter="Autodesk Inventor-Drawing (*.idw)|*.idw|All Files (*.*)|*.*"
oFileDlg.FilterIndex = 1
oFileDlg.DialogTitle = "Open Laser Part Drawing"
oFileDlg.CancelError = True
On Error Resume Next
Err.Clear
oFileDlg.ShowOpen()
If Not Err.Number = 0 Then
Exit Sub
Else
MsgBox(oFileDlg.FileName,,"GetDrawDocName")
End If
Why do you manipulate quantitys by hand? It's the worst case to write quantitys in part files. A part is a part and has no quantity. Even if sub-contractor says it's necessary to write down amounts on a part drawing. Amounts can be taken out of the BOM. Don't make this manual.
Take an assembly and insert the required amount of parts for 1 tank. Then create a second assembly for the whole order and place the required amount of tanks in that assembly. In the parts only view of BOM you'll find all infos you need to order your parts. Export this BOM view to Excel and sort/filter the rows needed for order.
Hi,
thanks for the code! Sadly it's not opening my drawing 😞 It only shows the message box with the path
I will put all my laserparts in an assembly from now on and extract qty from there
Hello
Ok, here's the complete one. Link this rule to your "Auf .idw platzieren" button. Your text field to enter the drawing name is obsolete now and can be removed.
Private Sub Main()
'assume your laser part document is open and active
If ThisApplication.Documents.Count=0 OrElse Not ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
MsgBox("This rule can only start with an part document active.", , "iLogic")
Exit Sub
End If
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDrawdoc As DrawingDocument = GetDrawing
If oDrawdoc Is Nothing Then
MsgBox("Somethign went wrong getting selected drawing.", , "iLogic")
Exit Sub
End If
'Call the rule with the drawing view creation
Call CreateDrawingView(oDrawdoc, oPartDoc)
MsgBox("Done",,"iLogic")
End Sub
Private Function GetDrawing() As DrawingDocument
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter="Autodesk Inventor-Drawing (*.idw)|*.idw|All Files (*.*)|*.*"
oFileDlg.FilterIndex = 1
oFileDlg.DialogTitle = "Open Laser Part Drawing"
oFileDlg.CancelError = True
On Error Resume Next
Err.Clear
oFileDlg.ShowOpen()
If Not Err.Number = 0 Then
Return Nothing
End If
Dim oDoc As Document
For Each oDoc In ThisApplication.Documents
If oDoc.FullFileName = oFileDlg.FileName Then
GetDrawing =oDoc
Return GetDrawing
End If
Next
GetDrawing=ThisApplication.Documents.Open(oFileDlg.FileName)
End Function
Private Sub CreateDrawingView(ByVal oDrawDoc As DrawingDocument, ByVal oPartDoc As PartDocument)
Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
Dim oSheetSize As DrawingSheetSizeEnum = oActiveSheet.Size
Dim oOrientation As PageOrientationTypeEnum = oActiveSheet.Orientation
Dim sSheetName As String= System.IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)
Dim oWidth As Object = oActiveSheet.Width
Dim oHeight As Object=oActiveSheet.Height
Dim oSheet As Sheet = oDrawDoc.Sheets.Add(oSheetSize, oOrientation, sSheetName, oWidth, oHeight)
oSheet.AddTitleBlock(oActiveSheet.TitleBlock.Definition)
oSheet.AddDefaultBorder()
oSheet.Activate
Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width/2, oSheet.Height/2)
oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint,1,ViewOrientationTypeEnum.kFrontViewOrientation,DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle )
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.