ILogic automation of drawings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I am starting using ILogic in our company and i would like to automate drawings of sheet metals.
When i create a sheet metal i would like an ilogic that would create a flat pattern, then open a custom template and create two sheets. On the first sheet there should be 4 views. 3 in each plane (top, right, front) and 1 flat pattern. On the second sheet there should be only Flat Pattern in scale 1:1. I would also like to have this view in center of my template and to change size of a sheet based on MAX dimension (length, width). I found some I logic codes that i used and it finished some of my request. It created flat pattern, found and create a template with two sheets. It also placed some views but i cannot automate change size based on max dimensions, could somebody help me with that?
PS: Sorry for my bad English.
Here is a some mash up codes that i am using:
Dim oDrawingDoc As DrawingDocument Dim oPartDoc As Document Dim oSheet As Sheet Dim oView1 As DrawingView Dim oView2 As DrawingView Dim oView3 As DrawingView Dim oView4 As DrawingView Dim oDoc As Document Dim oFormat As SheetFormat Dim oTG As TransientGeometry Dim oViewScale As Double Dim oViewScaleString As String ViewScale = 1 'Ask to create drawing? dwgQuery=MsgBox("Would you like to Create a drawing for this MODEL?", vbYesNo,"Drawing Selection") If dwgQuery = vbYes Then oPartDoc = ThisDoc.Document 'Check to see if part is a sheetmetal part If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'do nothing Else 'ensure this part has a flat pattern Dim oSMDef As SheetMetalComponentDefinition oSMDef = oPartDoc.ComponentDefinition If oSMDef.FlatPattern Is Nothing Then 'create flat pattern oSMDef.Unfold oSMDef.FlatPattern.ExitEdit Else 'do nothing End If 'custom parametre pre sheet metal openDoc = ThisDoc.Document If openDoc.DocumentType = 12291 Then For Each oDoc In openDoc.AllReferencedDocuments 'Is a Sheet Metal File If oDoc.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then 'Obtain max & min flat sizes of part Dim smComp As SheetMetalComponentDefinition = oDoc.ComponentDefinition If smComp.HasFlatPattern Then 'Get Units of Measure Object Dim uom As UnitsOfMeasure = oDoc.UnitsOfMeasure 'Get FlatPattern Dims returned as the document units Length = uom.ConvertUnits(smComp.FlatPattern.Length, "cm", uom.LengthUnits) Width = uom.ConvertUnits(smComp.FlatPattern.Width, "cm", uom.LengthUnits) Flt_Ptrn_Len = Round(Length,0) Flt_Ptrn_Wid = Round(Width,0) Dim propertyName As String = "Blank Size" Dim propertyValue As String = Flt_Ptrn_Len & " x " & Flt_Ptrn_Wid customPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties") Try prop = customPropertySet.Item(propertyName) Catch ' Assume error means not found customPropertySet.Add("", propertyName) prop = customPropertySet.Item(propertyName) End Try prop.Value = Flt_Ptrn_Len &" x "& Flt_Ptrn_Wid End If End If Next Else End If 'koniec mapovania nových premenných ////stránka s kódom: https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/flat-pattern-size-custom-iproperty/td-p/7304247 End If 'Define IDW Template File Location 'oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Temp\my template.idw", True) oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2022\Templates\MKTECH\Výpalok.dwg", True) oSheet = oDrawingDoc.Sheets.Item(1) ' Create a new NameValueMap object Dim oBaseViewOptions As NameValueMap oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap 'True = folded view 'False = flat pattern view oBaseViewOptions.Add("SheetMetalFoldedModel", False) 'Define 2d view bottom left corner points for four views oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(7.5, 10) ' front view oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(7.5, 15) ' top view oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(15, 10)' right view oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(14, 25)' flat pattern oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint1, ViewScale,kFrontViewOrientation, kHiddenLineDrawingViewStyle, "My View") oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint2, kHiddenLineDrawingViewStyle, ViewScale) oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint3, kHiddenLineDrawingViewStyle, ViewScale) oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint4, ViewScale,kDefaultViewOrientation, kHiddenLineDrawingViewStyle,,, oBaseViewOptions)
oSheet = oDrawingDoc.Sheets.Item(2) 'oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)' flat pattern 'oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, ViewScale, kDefaultViewOrientation, kHiddenLineDrawingViewStyle, , , oBaseViewOptions) End If