Positioning of the contour to the origin

Positioning of the contour to the origin

technik-aufwaerts
Explorer Explorer
514 Views
6 Replies
Message 1 of 7

Positioning of the contour to the origin

technik-aufwaerts
Explorer
Explorer
Hello, everyone
Is it possible to move the FlatPattern to the origin using iLogic before doing a DXF export.
The FlatPattern is deleted and recreated after each export.

Currently we are doing an alignment based on a named edge.
Maybe the x and y coordinate of the edge can be used?

 

 

...
' get length from named Edge
Dim ALen As Double
Try
	Dim oEdge As Edge = namedEntities.FindEntity("Achse_Tritt")
	ALen = Sqrt(Pow((oEdge.StartVertex.Point.X - oEdge.StopVertex.Point.X), 2) + Pow((oEdge.StartVertex.Point.Y - oEdge.StopVertex.Point.Y), 2))
Catch
	MessageBox.Show("Keine benannte Achse gefunden!")
	ALen = 0.0
End Try

'Create Flat Pattern
If oCompDef.HasFlatPattern = False Then
	oCompDef.Unfold
Else
End If

Dim sheetMetalDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

Dim orientation As FlatPatternOrientation
orientation = sheetMetalDef.FlatPattern.FlatPatternOrientations.ActiveFlatPatternOrientation.Copy("New Orientation")

' Find an linear edge that lies along the flattened plane.
Dim flatEdge As Edge
Dim tempEdge As Edge
Dim EdgeLen As Double = 0.0
Dim TmpEdgeLen As Double
For Each tempEdge In sheetMetalDef.FlatPattern.Body.Edges
	If tempEdge.GeometryType = kLineSegmentCurve Then
		If Abs(tempEdge.StartVertex.Point.Z - tempEdge.StopVertex.Point.Z) < 0.0001 Then  ' is on flat pattern plane
			TmpEdgeLen = Sqrt(Pow((tempEdge.StartVertex.Point.X - tempEdge.StopVertex.Point.X), 2) + Pow((tempEdge.StartVertex.Point.Y - tempEdge.StopVertex.Point.Y), 2))
			' and has same length as named edge
			If EqualWithinTolerance(ALen, TmpEdgeLen)
				flatEdge = tempEdge
				Exit For
			End If
		End If
	End If
Next
' modify flat pattern orientation   
Try
	orientation.Activate
	orientation.AlignmentAxis = flatEdge
	orientation.AlignmentRotation.Value = 0.0 ' 0 - 2 PI
Catch
End Try
...

 

 

nownowshould beshould be

0 Likes
Accepted solutions (3)
515 Views
6 Replies
Replies (6)
Message 2 of 7

tobias_wiesendanger
Advocate
Advocate
Accepted solution

It looks like this is not possible. At least I didnt find a way to move the flat pattern in anyway. This is also not possible without the api which most of the time is an indicator that its simply not possible.

 

But there might be another solution. If you create a new drawing and place one view like the flat pattern you can move that view to where you want it to be. I tested it out. If you get a point and then move the view by that measurement it should be possible to align a point with zero position of the sheet which then results in a correct dxf export.

 

The challenge will be to find the correct point. I didnt look into that.

Message 3 of 7

technik-aufwaerts
Explorer
Explorer

Hi @tobias_wiesendanger 

 

Thank you for your quick response.
I now have a rule that creates an idw for me and places the view. Now I have the problem that I can't access the height and width of the view. Unfortunately, ThisDoc still refers to the part. The advantage is that I can pick up the path and the name of the part. Do you have any idea how I can trade this? For this reason I cannot close the idw, but the part closes.

 

 

Dim oFileName As String
oFileName = ThisDoc.PathAndFileName

Dim oDesc As String
oDesc = iProperties.Value("Project", "Description")
Logger.Info(oDesc)

Dim oPartDoc As Document
Dim oSheet As Sheet

oPartDoc = ThisDoc.Document

'Define IDW Template File Location
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, , True)


'Centre of Drawing Border
X_Pos = 0
Y_Pos = 0

'Define 2d views
oPoint0 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos)
oSheet = oDrawingDoc.Sheets.Item(1)

'Set Flat View
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Set the options to use when creating the base view.
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

'oBaseView = 
oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint0, 1.0, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)

oDrawDoc.SaveAs(oFileName & "_" & oDesc & ".dxf", True)
ThisDoc.Document.Close(False)

 

 

0 Likes
Message 4 of 7

J-Camper
Advisor
Advisor
Accepted solution

@technik-aufwaerts,

I think this should do what you want:

Dim oFileName As String
oFileName = ThisDoc.PathAndFileName

Dim oDesc As String
oDesc = iProperties.Value("Project", "Description")
Logger.Info(oDesc)

Dim oPartDoc As Document
Dim oSheet As Sheet

oPartDoc = ThisDoc.Document

'Define IDW Template File Location
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, , True)

'Centre of Drawing Border
X_Pos = 0
Y_Pos = 0

'Define 2d views
oPoint0 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos)
oSheet = oDrawingDoc.Sheets.Item(1)

'Set Flat View option
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Set the options to use when creating the base view.
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

Dim oBaseView As DrawingView 
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint0, 1.0, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)

Logger.Trace(oBaseView.Height & " x " & oBaseView.Width & " [HxW]")

oDrawingDoc.SaveAs(oFileName & "_" & oDesc & ".dxf", True)
oDrawingDoc.Close(True)'Yes skip save unless you want to keep the IDW file

 

Since you already have the DrawingDocumentObject Variable "oDrawingDoc", you can use that to close the IDW.  You will want to use .Close(True) though, because you at no point prior saved the drawing as an IDW.  If you want to save the IDW file, you will need to add that, the you can use .Close(False).

 

I also put in a logger to show the DrawingView Height and Width properties.

 

Let me know if you have any questions, or if this is not working as intended.

0 Likes
Message 5 of 7

technik-aufwaerts
Explorer
Explorer

@J-Camper, Thank you for your quick reply. This solves my problem. So easy when you know...
Now I would like to do an export as a dxf. Unfortunately I have a problem in line 77. The oDraingDoc parameter refers to the part again. Any idea how I can solve this?

 


Dim oFileName As String
oFileName = ThisDoc.PathAndFileName

Dim oDesc As String
oDesc = iProperties.Value("Project", "Description")
Logger.Info(oDesc)

Dim oPartDoc As Document
Dim oSheet As Sheet

oPartDoc = ThisDoc.Document

'Define IDW Template File Location
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, , True)

'Centre of Drawing Border
X_Pos = 0
Y_Pos = 0

'Define 2d views
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos)
oSheet = oDrawingDoc.Sheets.Item(1)

'Set Flat View option
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Set the options to use when creating the base view.
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

Dim oBaseView As DrawingView
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 1.0, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)


oDoc = ThisApplication.ActiveDocument
Dim oSheet1 As Sheet = oDoc.Sheets.Item(1)
Dim oDrawingViews As DrawingViews = oSheet1.DrawingViews
Dim oView As DrawingView = oDrawingViews.Item(1)

'Center the view
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d()
oPoint2.X = oBaseView.Width / 2
oPoint2.Y = oBaseView.Height / 2
oView.Position = oPoint2


	' Get the DXF translator Add-In.
	Dim DXFAddIn As TranslatorAddIn
	DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

	'Set a reference to the active document (the document to be published).
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = kFileBrowseIOMechanism

	' Create a DataMedium object
	Dim oDataMedium As DataMedium
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

	' Check whether the translator has 'SaveCopyAs' options
	If DXFAddIn.HasSaveCopyAsOptions(oDrawingDoc, oContext, oBaseViewOptions) Then

		Dim strIniFile As String
		strIniFile = "N:\99_Intern\01_Inventor\Inventor.sys\INV_SYS\Design Data\DWG-DXF\Export_Templates.ini"

		' Create the name-value that specifies the ini file to use.
		oBaseViewOptions.Value("Export_Acad_IniFile") = strIniFile
	End If

	'Set the destination file name
	oDataMedium.FileName = oFileName & "_" & oDesc & ".dxf"

	'Publish document.
	Call DXFAddIn.SaveCopyAs(oDrawingDoc, oContext, oBaseViewOptions, oDataMedium)

oDrawingDoc.Close(True)
0 Likes
Message 6 of 7

J-Camper
Advisor
Advisor
Accepted solution

@technik-aufwaerts,

 

I didn't test this because I don't have your template and don't really automate DXF exports, but I fixed what looked wrong to me:

 

Dim oFileName As String
oFileName = ThisDoc.PathAndFileName

Dim oDesc As String
oDesc = iProperties.Value("Project", "Description")
Logger.Info(oDesc)

Dim oPartDoc As Document
Dim oSheet As Sheet

oPartDoc = ThisDoc.Document 'this assumes a part document is calling the rule.
							'If it is a local rule saved inside a part file, then no problem.
							'If this is going to be an external rule, you could throw an error
							'running the rule in the wrong document type. I always use a TryCast:
							'Dim pDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
							'If IsNothing(pDoc) Then Logger.Debug("Wrong Document Type") : Exit Sub

'Define IDW Template File Location
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, , True)

'Centre of Drawing Border
X_Pos = 0
Y_Pos = 0

'Define 2d views
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(X_Pos, Y_Pos)
oSheet = oDrawingDoc.Sheets.Item(1)

'Set Flat View option
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Set the options to use when creating the base view.
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

Dim oBaseView As DrawingView
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 1.0, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)


'you already have the drawing document object: oDoc = ThisApplication.ActiveDocument
'you already have the sheet object: Dim oSheet1 As Sheet = oDoc.Sheets.Item(1)
'you already have the drawingview object: Dim oDrawingViews As DrawingViews = oSheet1.DrawingViews
'you already have the drawingview object: Dim oView As DrawingView = oDrawingViews.Item(1)

'Center the view
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d()
oPoint2.X = oBaseView.Width / 2
oPoint2.Y = oBaseView.Height / 2
oBaseView.Position = oPoint2'Maintain the use of the same DrawingView Object


	' Get the DXF translator Add-In.
	Dim DXFAddIn As TranslatorAddIn
	DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

	'Set a reference to the active document (the document to be published).
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = kFileBrowseIOMechanism

	' Create a DataMedium object
	Dim oDataMedium As DataMedium
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

	' Check whether the translator has 'SaveCopyAs' options
	If DXFAddIn.HasSaveCopyAsOptions(oDrawingDoc, oContext, oBaseViewOptions) Then

		Dim strIniFile As String
		strIniFile = "N:\99_Intern\01_Inventor\Inventor.sys\INV_SYS\Design Data\DWG-DXF\Export_Templates.ini"

		' Create the name-value that specifies the ini file to use.
		oBaseViewOptions.Value("Export_Acad_IniFile") = strIniFile
	End If

	'Set the destination file name
	oDataMedium.FileName = oFileName & "_" & oDesc & ".dxf"

	'Publish document.
	Call DXFAddIn.SaveCopyAs(oDrawingDoc, oContext, oBaseViewOptions, oDataMedium)

oDrawingDoc.Close(True)

 

Let me know if you still have issues and I'll look into it further

0 Likes
Message 7 of 7

technik-aufwaerts
Explorer
Explorer

@J-Camper 

Thanks for your answer.
I have no idea what exactly happened, but the rule suddenly works. I am happy to take your adjustments with me. Many thanks for the support

Regard

 

0 Likes