- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Automatic drawing of sub-assembly
Hi,
I would like to know if ilogic exist to make 1 drawing by assembly with 3 predefined views :
1) I open assembly, which contain subassembly
2) I run the iLogic and it make 1 drawing by subassembly (with the name of the subassembly)
3) The drawing have 3 views (front, top, side) + 1 ISO
3) The scale must be 1:1, for all
4) I use a specific template, for all (the template contain nothing, this is a "white" paper).
Thank you very much !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, Maybe this can be a start.
Sub main ' Get the active assembly. '------------------------------------------------------------------------------------- Dim AssyName As String = "Section3_AngleSupports" 'name of the SubAssy Dim TemplateName As String = "white.dwg" 'name of the template Dim Scale As String = "1:1" 'scale '------------------------------------------------------------------------------------- Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument ' Call the function that does the recursion. TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, AssyName, TemplateName, Scale) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer, Name As String, TemplateName As String, scale As String) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject Dim DrawingTemplate As String = System.IO.Path.Combine(DesignProject.TemplatesPath, TemplateName) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then If oOcc.Name = Name Then Dim AssyDoc As AssemblyDocument = oOcc.Definition.Document Dim oDrawDoc As DrawingDocument = CreateDrawing(DrawingTemplate) CreateViews(oDrawDoc, AssyDoc, scale) End If TraverseAssembly(oOcc.SubOccurrences, Level + 1, Name, TemplateName, scale) End If Next End Sub Private Function CreateDrawing(DrawingDoc As String) As DrawingDocument Dim result As DrawingDocument = Nothing Try Dim oNewDrawDoc As DrawingDocument = Nothing oNewDrawDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, DrawingDoc) result = oNewDrawDoc Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "CreateDrawing") End Try Return result End Function Private Sub CreateViews(ByVal oDrawDoc As DrawingDocument, ByVal oAssyDoc As AssemblyDocument, scale As String) Try 'Set a reference to the active sheet. Dim oSheet As Sheet = oDrawDoc.ActiveSheet ' Create the placement point object. Dim Point1 As Double = ((oSheet.Width) / 2) - 8 Dim Point2 As Double = ((oSheet.Height) / 2) - 6 Dim oPoint As Point2d oPoint = ThisApplication.TransientGeometry.CreatePoint2d(Point1, Point2) 'view 1 FrontView Dim oView As DrawingView = CreateView(oAssyDoc, oSheet, oPoint, True, "Front", ViewOrientationTypeEnum.kFrontViewOrientation) oView.ScaleString = scale oView.ViewStyle = DrawingViewStyleEnum.kShadedDrawingViewStyle CreateProjectedView(oView, oSheet, "Top", oView.Height) CreateProjectedView(oView, oSheet, "Side", , oView.Width) CreateProjectedView(oView, oSheet, "Iso", oView.Height, oView.Width) Catch ex As Exception MsgBox("General error in CreateViews, ex= " & ex.GetBaseException.ToString, MsgBoxStyle.Critical, "Error") End Try End Sub Private Function CreateView(ByVal oAssyDoc As AssemblyDocument, oSheet As Sheet, oInsertionPoint2D As Point2d, Folded As Boolean, ByVal DrawingViewName As String, ByVal ViewOrientation As ViewOrientationTypeEnum) As DrawingView Dim result As DrawingView = Nothing Try ' Create a BaseView. Dim oBaseView As DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oInsertionPoint2D, 1, ViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle) oBaseView.Name = DrawingViewName result = oBaseView Catch ex As Exception MsgBox("General error in CreateView, ex= " & ex.GetBaseException.ToString, MsgBoxStyle.Critical, "Error") End Try Return result End Function Private Function CreateProjectedView(ByVal baseView As DrawingView, sheet As Sheet, DrawingViewName As String, Optional height As Double = 0, Optional width As Double = 0) As DrawingView Dim result As DrawingView = Nothing Try Dim oPositionBaseView As Point2d = baseView.Position Dim xBaseView As Double = oPositionBaseView.X Dim yBaseView As Double = oPositionBaseView.Y Dim oPointBottomView2 As Point2d oPointBottomView2 = ThisApplication.TransientGeometry.CreatePoint2d((xBaseView + width * 3), (yBaseView + height * 1.5)) 'BottomView Dim oProjected As DrawingView oProjected = sheet.DrawingViews.AddProjectedView(baseView, oPointBottomView2, DrawingViewStyleEnum.kShadedDrawingViewStyle) oProjected.Name = DrawingViewName result = oProjected Catch ex As Exception MsgBox("General error in CreateView, ex= " & ex.GetBaseException.ToString, MsgBoxStyle.Critical, "Error") End Try Return result End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi ! Thank you very much !
I have a problem i have "Erreur non spécifiée (Exception from HRESULT: 0x80004005 (E_FAIL))"
If i delete the line " Dim AssyName As String = " is working, but not in all assembly (not in frame assembly for example).
Thank you again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I think the problem was the position off the views, I have the code adjusted.
You can also adjust the spacing between the views.
If this answers your question, please use ACCEPT SOLUTION to assist other users later.
Also be generous with Likes! Thank you and enjoy!
Sub main ' Get the active assembly. Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim AssyName As String = "framework:1" 'name of the SubAssy Dim TemplateName As String = "white.dwg" 'name of the templae Dim Scale As String = "1:1" 'scale Dim SpacingBetweenViews As Double = 5 ' Call the function that does the recursion. TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, AssyName, TemplateName, Scale, SpacingBetweenViews) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer, Name As String, TemplateName As String, scale As String, SpacingViews As Double) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject Dim DrawingTemplate As String = System.IO.Path.Combine(DesignProject.TemplatesPath, TemplateName) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then If oOcc.Name = Name Then Dim AssyDoc As AssemblyDocument = oOcc.Definition.Document Dim oDrawDoc As DrawingDocument = CreateDrawing(DrawingTemplate) CreateViews(oDrawDoc, AssyDoc, scale, SpacingViews) End If TraverseAssembly(oOcc.SubOccurrences, Level + 1, Name, TemplateName, scale, SpacingViews) End If Next End Sub Private Function CreateDrawing(DrawingDoc As String) As DrawingDocument Dim result As DrawingDocument = Nothing Try Dim oNewDrawDoc As DrawingDocument = Nothing oNewDrawDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, DrawingDoc) result = oNewDrawDoc Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "CreateDrawing") End Try Return result End Function Private Sub CreateViews(ByVal oDrawDoc As DrawingDocument, ByVal oAssyDoc As AssemblyDocument, scale As String, SpacingViews As Double) Try 'Set a reference to the active sheet. Dim oSheet As Sheet = oDrawDoc.ActiveSheet ' Create the placement point object. Dim Point1 As Double = ((oSheet.Width) / 2) - 8 Dim Point2 As Double = ((oSheet.Height) / 2) - 6 Dim oPoint As Point2d oPoint = ThisApplication.TransientGeometry.CreatePoint2d(Point1, Point2) 'view 1 FrontView Dim oViewFront As DrawingView = CreateBaseView(oAssyDoc, oSheet, oPoint, True, "Front", ViewOrientationTypeEnum.kFrontViewOrientation) oViewFront.ScaleString = scale oViewFront.ViewStyle = DrawingViewStyleEnum.kShadedDrawingViewStyle Dim oBaseViewCenter As Point2d = oViewFront.Center Dim obaseViewX As Double = oBaseViewCenter.X Dim obaseViewY As Double = oBaseViewCenter.Y Dim ViewFrontheight As Double = oViewFront.Height Dim ViewFrontWidth As Double = oViewFront.Width Dim oViewTop = CreateProjectedView(oViewFront, oSheet, "Top", oViewFront.Center.Y + 10) Dim oViewSide = CreateProjectedView(oViewFront, oSheet, "Side",, oViewFront.Center.X + 10) Dim oViewIso = CreateProjectedView(oViewFront, oSheet, "Iso", oViewFront.Center.X + 10, oViewFront.Center.Y + 10) Dim ViewTopheight As Double = oViewTop.Height Dim ViewTopWidth As Double = oViewTop.Width Dim oViewTopPlace As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(obaseViewX, obaseViewY + (ViewFrontheight / 2) + (ViewTopheight / 2) + SpacingViews) oViewTop.Position = oViewTopPlace Dim ViewSideheight As Double = oViewSide.Height Dim ViewSideWidth As Double = oViewSide.Width Dim oViewSidePlace As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(obaseViewX + (ViewFrontWidth / 2) + (ViewSideWidth / 2) + SpacingViews, obaseViewY) oViewSide.Position = oViewSidePlace Dim ViewIsoheight As Double = oViewIso.Height Dim ViewIsoWidth As Double = oViewIso.Width Dim oViewIsoPlace As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oViewSide.Center.X + (ViewSideWidth / 2), oViewTop.Center.Y + (ViewTopheight / 2)) oViewIso.Position = oViewIsoPlace Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "CreateViews") End Try End Sub Private Function CreateBaseView(ByVal oAssyDoc As AssemblyDocument, oSheet As Sheet, oInsertionPoint2D As Point2d, Folded As Boolean, ByVal DrawingViewName As String, ByVal ViewOrientation As ViewOrientationTypeEnum) As DrawingView Dim result As DrawingView = Nothing Try ' Create a BaseView. Dim oBaseView As DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oInsertionPoint2D, 1, ViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle) oBaseView.Name = DrawingViewName result = oBaseView Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "CreateBaseView") End Try Return result End Function Private Function CreateProjectedView(ByVal baseView As DrawingView, sheet As Sheet, DrawingViewName As String, Optional height As Double = 0, Optional width As Double = 0) As DrawingView Dim result As DrawingView = Nothing Try Dim oPositionBaseView As Point2d = baseView.Position Dim xBaseView As Double = oPositionBaseView.X Dim yBaseView As Double = oPositionBaseView.Y Dim oPointBottomView2 As Point2d oPointBottomView2 = ThisApplication.TransientGeometry.CreatePoint2d((xBaseView + width * 3), (yBaseView + height * 1.5)) 'BottomView Dim oProjected As DrawingView oProjected = sheet.DrawingViews.AddProjectedView(baseView, oPointBottomView2, DrawingViewStyleEnum.kShadedDrawingViewStyle) oProjected.Name = DrawingViewName result = oProjected Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "CreateProjectedView") End Try Return result End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, thank you very much for reply and screen.
I still get an error :
System.Runtime.InteropServices.COMException (0x80004005): Erreur non spécifiée (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.get_SubOccurrences()
at ThisRule.TraverseAssembly(ComponentOccurrences Occurrences, Int32 Level, String Name, String TemplateName, String scale, Double SpacingViews) in external rule: GEN DRAWING:line 28
at ThisRule.TraverseAssembly(ComponentOccurrences Occurrences, Int32 Level, String Name, String TemplateName, String scale, Double SpacingViews) in external rule: GEN DRAWING:line 28
at ThisRule.Main() in external rule: GEN DRAWING:line 9
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
If i remove the line "Dim AssyName As String = "framework:1" 'name of the SubAssy" it's work partially (i get error line 27 after 3/4 subassembly creating).
I double check the assyname, the template path ect. I don't know from what it come.
Thank you again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, which version of inventor you are using?
I found this thread same error with inventor 2022.
install all updates of inventor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Oké see if we can debug this,
- We want to know if the Assy can be found, run this code a Message will appear.
Sub main ' Get the active assembly. Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim AssyName As String = "framework:1" 'name of the SubAssy Dim TemplateName As String = "white.dwg" 'name of the templae Dim Scale As String = "1:1" 'scale Dim SpacingBetweenViews As Double = 5 ' Call the function that does the recursion. TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, AssyName, TemplateName, Scale, SpacingBetweenViews) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer, Name As String, TemplateName As String, scale As String, SpacingViews As Double) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject Dim DrawingTemplate As String = System.IO.Path.Combine(DesignProject.TemplatesPath, TemplateName) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then If oOcc.Name = Name Then Dim AssyDoc As AssemblyDocument = oOcc.Definition.Document MsgBox("Assy Found" & " " & AssyDoc.FullFileName ) ' Dim oDrawDoc As DrawingDocument = CreateDrawing(DrawingTemplate) ' CreateViews(oDrawDoc, AssyDoc, scale, SpacingViews) End If TraverseAssembly(oOcc.SubOccurrences, Level + 1, Name, TemplateName, scale, SpacingViews) End If Next End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Now i updated to Inventor 2024.
When i run i get :
Error on line 30 in rule: GEN DRAWING, in document: XXX.iam
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.get_SubOccurrences()
at ThisRule.TraverseAssembly(ComponentOccurrences Occurrences, Int32 Level, String Name, String TemplateName, String scale, Double SpacingViews) in external rule: GEN DRAWING:line 30
at ThisRule.TraverseAssembly(ComponentOccurrences Occurrences, Int32 Level, String Name, String TemplateName, String scale, Double SpacingViews) in external rule: GEN DRAWING:line 30
at ThisRule.Main() in external rule: GEN DRAWING:line 9
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, have you tried this code to find out if we can find the Assembly,
Can provide a small dataset for testing?
Sub main ' Get the active assembly. Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim AssyName As String = "testframe" 'name of the SubAssy Dim TemplateName As String = "white.dwg" 'name of the templae Dim Scale As String = "1:1" 'scale Dim SpacingBetweenViews As Double = 5 ' Call the function that does the recursion. TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, AssyName, TemplateName, Scale, SpacingBetweenViews) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer, Name As String, TemplateName As String, scale As String, SpacingViews As Double) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject Dim DrawingTemplate As String = System.IO.Path.Combine(DesignProject.TemplatesPath, TemplateName) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then If oOcc.Name = Name Then Dim AssyDoc As AssemblyDocument = oOcc.Definition.Document MsgBox("Assy Found" & " " & AssyDoc.FullFileName ) ' Dim oDrawDoc As DrawingDocument = CreateDrawing(DrawingTemplate) ' CreateViews(oDrawDoc, AssyDoc, scale, SpacingViews) End If TraverseAssembly(oOcc.SubOccurrences, Level + 1, Name, TemplateName, scale, SpacingViews) End If Next End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, i get "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))".
Maybe more simple : Is it possible to run the iLogic from the active assembly and make drawing for each subassembly instead of looking for specific assembly ?
Thank you very much,
Regards,
Thomas.