AUTOMATIC DXF GENERATION

AUTOMATIC DXF GENERATION

lingerrobert
Contributor Contributor
1,535 Views
3 Replies
Message 1 of 4

AUTOMATIC DXF GENERATION

lingerrobert
Contributor
Contributor

Hello,

I am attempting to write an i_logic rule that will generate a dxf file of a sheet metal part once the flat  pattern is formed. Is this possible and what would be the best way to approach?

Bob

0 Likes
Accepted solutions (1)
1,536 Views
3 Replies
Replies (3)
Message 2 of 4

Owner2229
Advisor
Advisor

Can be runned e.g. with AfterSave Event Trigger (I'm runnig it via addin independently on part):

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Try
Dim oSMCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition
If oSMCD.HasFlatPattern Then
	oSMCD.FlatPattern.Edit
	Dim sOut As String
	sOut = "FLAT PATTERN DXF?AcadVersion=2000" _
		+ "&OuterProfileLayer=IV_INTERIOR_PROFILES" _
		+ "&InvisibleLayers=IV_TANGENT" _
		+ "&SimplifySplines=True" _
		+ "&BendLayerLineType=37634" _
		+ "&BendLayerColor=255;255;0" _
		+ "&BendUpLayerLineType=37634" _
		+ "&BendUpLayerColor=255;255;0" _
		+ "&BendDownLayerLineType=37634" _
		+ "&BendDownLayerColor=255;255;0" _
		+ "&FeatureProfilesLayerLineType=37634" _
		+ "&FeatureProfilesLayerColor=255;255;0" _
		+ "&FeatureProfilesUpLayerLineType=37634" _
		+ "&FeatureProfilesUpLayerColor=255;255;0" _
		+ "&FeatureProfilesDownLayerLineType=37634" _
		+ "&FeatureProfilesDownLayerColor=255;255;0"
	Dim sFN As String = ThisDoc.FileName(False)
	Dim sPath As String = ThisDoc.Path
	sFN = sPath & "\" & sFN & ".dxf"
	oSMCD.DataIO.WriteDataToFile( sOut, sFN)
End If
Catch
MsgBox ("Couldn't save the DXF file.")
End Try
oSMCD.FlatPattern.ExitEdit()
End If

Checks if the part is Sheet Metal Part, then if there is the flat pattern it will export it to DXF.

 

Some lines (e.g. Bend Lines) are set to discontinuous (37634) and it's color to yellow (255;255;0). Tangent Lines are hidden (InvisibleLayers=IV_TANGENT)

 

This is the base code. I have some more added to it so then it does:

-Creates the flat pattern if it doesn't exist.

-Adds "Part Number" on the flat pattern (will be exported as yellow).

-Asks the designer if the position of the "Part number" is correct, if not than it lets him change it by form (he can rotate or change the text size in the form or just drag it to the correct position).

-Exports the whole thing to DXF with name defined by rule to folder defined by rule.

-Connects the DXF to the part file (via custom Parameters).

And some other things...

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 4

Owner2229
Advisor
Advisor
Accepted solution

I made a little mistake in the code, it would cause an error for normal parts. Here is the correct one:

Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	Try
	Dim oSMCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition
	If oSMCD.HasFlatPattern Then
		oSMCD.FlatPattern.Edit
		Dim sOut As String
		sOut = "FLAT PATTERN DXF?AcadVersion=2000" _
			+ "&OuterProfileLayer=IV_INTERIOR_PROFILES" _
			+ "&InvisibleLayers=IV_TANGENT" _
			+ "&SimplifySplines=True" _
			+ "&BendLayerLineType=37634" _
			+ "&BendLayerColor=255;255;0" _
			+ "&BendUpLayerLineType=37634" _
			+ "&BendUpLayerColor=255;255;0" _
			+ "&BendDownLayerLineType=37634" _
			+ "&BendDownLayerColor=255;255;0" _
			+ "&FeatureProfilesLayerLineType=37634" _
			+ "&FeatureProfilesLayerColor=255;255;0" _
			+ "&FeatureProfilesUpLayerLineType=37634" _
			+ "&FeatureProfilesUpLayerColor=255;255;0" _
			+ "&FeatureProfilesDownLayerLineType=37634" _
			+ "&FeatureProfilesDownLayerColor=255;255;0"
		Dim sFN As String = ThisDoc.FileName(False)
		Dim sPath As String = ThisDoc.Path
		sFN = sPath & "\" & sFN & ".dxf"
		oSMCD.DataIO.WriteDataToFile( sOut, sFN)
		oSMCD.FlatPattern.ExitEdit()
	End If
	Catch
	MsgBox ("Couldn't save the DXF file.")
	End Try
End If
End Sub

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 4 of 4

lingerrobert
Contributor
Contributor

Thank you. This works very well.

0 Likes