ILogic export flat pattern with dimension

ILogic export flat pattern with dimension

randy.redekop
Participant Participant
609 Views
6 Replies
Message 1 of 7

ILogic export flat pattern with dimension

randy.redekop
Participant
Participant

Hello all,

 

I'm fairly new to iLogic so any help would be appreciated.

 

So I'm trying to find a way to where I use iLogic to export my flat pattern and also place dimensions on it.  Ive been looking around forums and cant find anything.  I don't know if getting dimensions on the holes is even possible but it would be great if it worked. Ill attach a picture of what I'm looking for. Thank you.

0 Likes
610 Views
6 Replies
Replies (6)
Message 2 of 7

fidel.makatiaD5W7V
Alumni
Alumni

Hi @randy.redekop have you looked into the inventor API docs?

For exporting into DXf kindly this is the VB code

Inventor 2022 Help | Export to DWF | Autodesk

you can also export to other formats like DWG,STEP,PDF

For dimensioning this is the sample code

Inventor 2022 Help | Create linear foreshortened dimension sample | Autodesk

let me know if this helps  and in case of any clarification



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 3 of 7

theo.bot
Collaborator
Collaborator

You can't edit the dxf export using the flatpattern export functions.

But I think the easiest way would be creating a drawing sheet (without border and titleblock) with a 1:1 scaled view of your flatpattern. Add dimensions etc. then do an export of the drawing to dxf.

Automating annotations on a drawing from scratch can be difficult. But if you use 3d annotations in your flatpattern, you can retrieve then in you drawing.

0 Likes
Message 4 of 7

fidel.makatiaD5W7V
Alumni
Alumni

Also, @randy.redekop check the following VB.NET code I developed sometimes back that takes a sheet metal as input then converts it to a drawing file with dimensions.

 Dim oDrawingDoc As DrawingDocument
        oDrawingDoc = _InvApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
                                _InvApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))

        ' Create a new B size sheet.
        Dim oSheet As Sheet
        oSheet = oDrawingDoc.Sheets.Add(DrawingSheetSizeEnum.kBDrawingSheetSize)


        ' Add the default border.
        oSheet.AddDefaultBorder()

        ' Open the block document, invisibly.

        Dim oPartDoc As PartDocument
        oPartDoc = _InvApplication.Documents.Open("C:\Users\t_makaf\OneDrive - Autodesk\Desktop\sheet.ipt", False)

        Dim oTG As TransientGeometry
        oTG = _InvApplication.TransientGeometry

        ' Create the base view.
        Dim oBaseView As DrawingView
        oBaseView = oDrawingDoc.ActiveSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(35, 20), 1,
                                                     ViewOrientationTypeEnum.kFrontViewOrientation,
                                                     DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)


        Dim oDrawing As DrawingDocument
        oDrawing = _InvApplication.ActiveDocument

        Dim oView As DrawingView
        oView = oDrawing.ActiveSheet.DrawingViews(1)

        Dim oDimColl As GeneralDimensionsEnumerator
        oDimColl = oDrawing.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView)


        ''dimensioning

        Dim oSelectedCurve As DrawingCurve = Nothing

        For Each oCurve As DrawingCurve In oBaseView.DrawingCurves

            ' Skip Circles
            If Not oCurve.StartPoint Is Nothing And Not oCurve.EndPoint Is Nothing Then

                If (WithinTol(oCurve.StartPoint.X, oCurve.EndPoint.X, 0.001)) Then

                    If oSelectedCurve Is Nothing Then

                        ' This is the first horizontal curve found.
                        oSelectedCurve = oCurve

                    Else

                        ' Check to see if this curve is higher (smaller x value) than the current selected
                        If oCurve.MidPoint.X < oSelectedCurve.MidPoint.X Then
                            oSelectedCurve = oCurve
                        End If

                    End If

                End If

            End If
        Next

        If oSelectedCurve Is Nothing Then
            MessageBox.Show("no curve selected!")
            Exit Sub
        End If

        ' Create geometry intents point for the curve.

        Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent)
        Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent)

        Dim oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions

        Dim oDimPos As Point2d = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y)

        ' Create the dimension.
        Dim oLinearDim As LinearGeneralDimension
        oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kAlignedDimensionType)
Private Function WithinTol(ByVal Value1 As Double, ByVal Value2 As Double, ByVal tol As Double) As Boolean

        Return (Math.Abs(Value1 - Value2) < tol)

    End Function

nsions 



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 5 of 7

randy.redekop
Participant
Participant

Hi @fidel.makatiaD5W7V, thank you for the reply. I am trying to use your code but i get a "Line 1:Rule needs a Sub Main() and End Sub" Error. Sorry i am very new to coding and using Ilogic. The Macro i am using right now is below. It works for creating a flat pattern and exporting it but im still looking to add dimensions with it. This is being used for our laser nesting guys so they can import the part without opening autocad or inventor and still have dimensions to double check that it matches with the print.

 

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	
	sFile = ThisDoc.Path
	
	Dim oDesiredFolder As String = sFile & "\Flat Pattern"
If Not System.IO.Directory.Exists(oDesiredFolder) Then
	System.IO.Directory.CreateDirectory(oDesiredFolder)
End If

	Dim oCompDef As SheetMetalComponentDefinition
	
	oCompDef = oPartDoc.ComponentDefinition
	
	If oCompDef.FlatPattern Is Nothing Then
		
		oCompDef.Unfold
		oCompDef.FlatPattern.ExitEdit
		
		oPartDoc.Save
		
		Else
			
		End If
		
		dwgFileName = sFile & "\" & "Flat Pattern\" & ThisDoc.FileName & ".FlatPattern.dwg"
	
	Dim oDataIO As DataIO
	oDataIO = oPartDoc.ComponentDefinition.DataIO
	Dim sOut As String
	sOut = "FLAT PATTERN DWG?AcadVersion=2004&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCOMSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
	oDataIO.WriteDataToFile(sOut, dwgFileName)

	
	
	Else
		If oPartDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
			
			
			Dim oDesiredFolder As String = sFile & "\Tube Laser"
			If Not System.IO.Directory.Exists(oDesiredFolder) Then
	System.IO.Directory.CreateDirectory(oDesiredFolder)
End If

			Dim oStepTranslator As TranslatorAddIn
			oStepTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
			Dim oContext As TranslationContext
			oContext = ThisApplication.TransientObjects.CreateTranslationContext
			Dim oOptions As NameValueMap
			oOptions = ThisApplication.TransientObjects.CreateNameValueMap
			
			If oStepTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
			
			oOptions.Value("ApplicationProtocolType") = 3
			
			oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
			
			Dim oData As DataMedium
			oData = ThisApplication.TransientObjects.CreateDataMedium
			
			
			oData.FileName = ThisDoc.Path & "\Tube Laser\" & ThisDoc.FileName & "TL.stp"
			
			oStepTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
			
End If
	End If
End If
0 Likes
Message 6 of 7

fidel.makatiaD5W7V
Alumni
Alumni

Hi @randy.redekop let me check your code



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 7 of 7

A.Acheson
Mentor
Mentor

The error message is correct in the ilogic editor you can use ilogic or vb.net code. Any code that has a sub or function will likely be vb.net and will need sub main and end sub to start and finish the rule. ThisApplication was also missing as _invapplication refers to an addin or missing section of code. There is also a file path that needs to be changed to suit the part being worked on. “C:\Users\t_makaf\OneDrive - Autodesk\Desktop\sheet.ipt"

 

@randy.redekop  Your code supplied has no sub/function routine so can be used as is. 

Sub Main()

‘Insert code here

End Sub

 

I have corrected what I could see in the below code but have not tested this. 

 

 

Sub Main()
'Sets inventor application
 _InvApplication = ThisApplication

Dim oDrawingDoc As DrawingDocument
        oDrawingDoc = _InvApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
                                _InvApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))

        ' Create a new B size sheet.
        Dim oSheet As Sheet
        oSheet = oDrawingDoc.Sheets.Add(DrawingSheetSizeEnum.kBDrawingSheetSize)


        ' Add the default border.
        oSheet.AddDefaultBorder()

        ' Open the block document, invisibly.

        Dim oPartDoc As PartDocument
        oPartDoc = _InvApplication.Documents.Open("C:\Users\t_makaf\OneDrive - Autodesk\Desktop\sheet.ipt", False)

        Dim oTG As TransientGeometry
        oTG = _InvApplication.TransientGeometry

        ' Create the base view.
        Dim oBaseView As DrawingView
        oBaseView = oDrawingDoc.ActiveSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(35, 20), 1,
                                                     ViewOrientationTypeEnum.kFrontViewOrientation,
                                                     DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)


        Dim oDrawing As DrawingDocument
        oDrawing = _InvApplication.ActiveDocument

        Dim oView As DrawingView
        oView = oDrawing.ActiveSheet.DrawingViews(1)

        Dim oDimColl As GeneralDimensionsEnumerator
        oDimColl = oDrawing.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView)


        ''dimensioning

        Dim oSelectedCurve As DrawingCurve = Nothing

        For Each oCurve As DrawingCurve In oBaseView.DrawingCurves

            ' Skip Circles
            If Not oCurve.StartPoint Is Nothing And Not oCurve.EndPoint Is Nothing Then

                If (WithinTol(oCurve.StartPoint.X, oCurve.EndPoint.X, 0.001)) Then

                    If oSelectedCurve Is Nothing Then

                        ' This is the first horizontal curve found.
                        oSelectedCurve = oCurve

                    Else

                        ' Check to see if this curve is higher (smaller x value) than the current selected
                        If oCurve.MidPoint.X < oSelectedCurve.MidPoint.X Then
                            oSelectedCurve = oCurve
                        End If

                    End If

                End If

            End If
        Next

        If oSelectedCurve Is Nothing Then
            MessageBox.Show("no curve selected!")
            Exit Sub
        End If

        ' Create geometry intents point for the curve.

        Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent)
        Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent)

        Dim oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions

        Dim oDimPos As Point2d = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y)

        ' Create the dimension.
        Dim oLinearDim As LinearGeneralDimension
        oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kAlignedDimensionType)
Private Function WithinTol(ByVal Value1 As Double, ByVal Value2 As Double, ByVal tol As Double) As Boolean

        Return (Math.Abs(Value1 - Value2) < tol)

    End Function
End Sub

 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes