Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DXF name generate by I properties

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
jwoutersJC4LN
943 Views, 22 Replies

DXF name generate by I properties

jwoutersJC4LN
Contributor
Contributor

Hi,

 

I'm looking for a code what can generate an Flatpattern DXF automatically by saving the Sheet-Metal file.

the name of the DXF must contain the following Iproperties

 

- Partnumber (Iproperties, Project, Partnumber)

-SheetmetalDefaults Thickness

-SheetmetalDefaults Material

-Comments (Iproperties, Summary, Comments)

-Project (Iproperties, Project, Project)

-Vendor (Iproperties, Project, Vendor)

 

Hope something like this is possible. I'm not a programmer but hope someone here can help us 🙂

 

Regards,

 

Justin 

0 Likes

DXF name generate by I properties

Hi,

 

I'm looking for a code what can generate an Flatpattern DXF automatically by saving the Sheet-Metal file.

the name of the DXF must contain the following Iproperties

 

- Partnumber (Iproperties, Project, Partnumber)

-SheetmetalDefaults Thickness

-SheetmetalDefaults Material

-Comments (Iproperties, Summary, Comments)

-Project (Iproperties, Project, Project)

-Vendor (Iproperties, Project, Vendor)

 

Hope something like this is possible. I'm not a programmer but hope someone here can help us 🙂

 

Regards,

 

Justin 

22 REPLIES 22
Message 21 of 23
jwoutersJC4LN
in reply to: WCrihfield

jwoutersJC4LN
Contributor
Contributor

Hi @WCrihfield ,

 

What we only need are the "IV_OUTER_PROFILE" and "IV_INTERIOR_PROFILES" with line colors white.

All other layers can be invissible or do we not use. 

 

jwoutersJC4LN_0-1663046707403.png

 

I've tried to delete some layers in de Default but as i said, that's not working. The code do generate a DXF but is placing center points in a circle and bendlines are vissible. That's not working for us. Our machine will cut the part in a few pieces 🙂

hope to see your response!

 

Thanks

jwoutersJC4LN_1-1663046895661.png

 

0 Likes

Hi @WCrihfield ,

 

What we only need are the "IV_OUTER_PROFILE" and "IV_INTERIOR_PROFILES" with line colors white.

All other layers can be invissible or do we not use. 

 

jwoutersJC4LN_0-1663046707403.png

 

I've tried to delete some layers in de Default but as i said, that's not working. The code do generate a DXF but is placing center points in a circle and bendlines are vissible. That's not working for us. Our machine will cut the part in a few pieces 🙂

hope to see your response!

 

Thanks

jwoutersJC4LN_1-1663046895661.png

 

Message 22 of 23
WCrihfield
in reply to: jwoutersJC4LN

WCrihfield
Mentor
Mentor
Accepted solution

Hi @jwoutersJC4LN.  I think I have the code prepared for those options now.  It seemed to work OK in my tests too.  There is a really long line of code in there though, which is for turning off all the other layers besides the two you want to see.  Long code is not necessarily a bad thing though, as long as it works the way you want it to, and it can be read and understood later, if changes may be needed.  Some of the oFormat stuff may not have been necessary, like setting Color, LineType, and LineWeight, but I included them anyways, just to be thorough.  I think those layers would have already been White, and Continuous by default, but on my system it wanted to make the line weight .50 mm thick.  After exporting using this code, those layers line weight were .05 mm, instead.  And for me there was also a layer named "0" (zero), because it is present on my Inventor side as a Layer in my drawings, but I could easily get rid of that too by adding it to that last long line for oFormat.

Here is the updated code:

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisDoc.Document
	If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Return
	Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	Dim oPath As String = System.IO.Path.GetDirectoryName(oPDoc.FullFileName)
	'gather values for use in DXF name
	Dim oProjSet As PropertySet = oPDoc.PropertySets.Item("Design Tracking Properties")
	Dim oPN As String = oProjSet.Item("Part Number").Value
	'If oPN is greater than 4 characters, shorten to only last 4 characters
	If oPN.Length > 4 Then 
		oPN = Right(oPN, 4)
	End If
	Dim oProject As String = oProjSet.Item("Project").Value
	Dim oVendor As String = oProjSet.Item("Vendor").Value
	Dim oComments As String = oPDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
	oComments = oComments & "x"
	Dim oMaterial As String = oPDoc.ActiveMaterial.DisplayName
	'get Thickness in 'document' units, instead of 'database' units, if they are different units
	Dim oThkParam As Inventor.Parameter = oSMDef.Thickness
	Dim oUOM As UnitsOfMeasure = oPDoc.UnitsOfMeasure
	Dim oThicknessVal As Double
	If oThkParam.Units <> "cm" Then
		oThicknessVal = oUOM.ConvertUnits(oThkParam.Value, "cm", oThkParam.Units)
	Else
		oThicknessVal = oThkParam.Value
	End If
	Dim oThickness As String = CStr(oThicknessVal) & "mm"
	'assemble file name
	Dim oDXFFileName As String = oPN & "-" & oThickness & "-" & oMaterial & "-" & _
oComments & "-" & oProject & "-" & oVendor
	oDXFFileName = oPath & "\" & oDXFFileName & ".dxf"
	MsgBox("oDXFFileName = " & oDXFFileName,,"")
	Dim oFP As FlatPattern = Nothing
	If oSMDef.HasFlatPattern Then
		oFP = oSMDef.FlatPattern
	Else
		Try
			oSMDef.Unfold
			oSMDef.FlatPattern.ExitEdit
			oFP = oSMDef.FlatPattern
		Catch oEx As Exception
			MsgBox("Unfold Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "UnFold Failed")
			Logger.Error("Unfold Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace)
			Exit Sub
		End Try
	End If
	ExportFlatPatternToDXF(oFP, oDXFFileName)
End Sub

Sub ExportFlatPatternToDXF(oFlatPattern As FlatPattern, oNewFullFileName As String)
	If IsNothing(oFlatPattern) Or oNewFullFileName = "" Then Exit Sub
	Dim oDataIO As DataIO = oFlatPattern.DataIO
	'<<<< FILL IN FORMAT SETTINGS THE WAY YOU WANT THEM >>>>
	Dim oFormat As String
	oFormat = "FLAT PATTERN DXF?AcadVersion=2000"
	oFormat = oFormat & "&OuterProfileLayerColor=255;255;255" 'White
	oFormat = oFormat & "&OuterProfileLayerLineType=37633" 'Continuous
	oFormat = oFormat & "&OuterProfileLayerLineWeight=0.00" 'specify value in Centimeters
	oFormat = oFormat & "&InteriorProfilesLayerColor=255;255;255" 'White
	oFormat = oFormat & "&InteriorProfilesLayerLineType=37633" 'Continuous
	oFormat = oFormat & "&InteriorProfilesLayerLineWeight=0.00" 'specify value in Centimeters
	oFormat = oFormat & "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;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_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
	
	Try
		oDataIO.WriteDataToFile(oFormat, oNewFullFileName)
		MsgBox("New DXF created at:" & vbCrLf & oNewFullFileName, vbInformation, "DXF Created")
		Logger.Info("New DXF created at:" & vbCrLf & oNewFullFileName)
		'get directory/folder where DXF was saved to
		Dim oDirectory As String = System.IO.Path.GetDirectoryName(oNewFullFileName)
		'try to open that Directory/Folder in a file browser window
		ThisDoc.Launch(oDirectory)
	Catch oEx As Exception
		MsgBox("Export Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "DXF Export Failed")
		Logger.Error("Export Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace)
	End Try
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Hi @jwoutersJC4LN.  I think I have the code prepared for those options now.  It seemed to work OK in my tests too.  There is a really long line of code in there though, which is for turning off all the other layers besides the two you want to see.  Long code is not necessarily a bad thing though, as long as it works the way you want it to, and it can be read and understood later, if changes may be needed.  Some of the oFormat stuff may not have been necessary, like setting Color, LineType, and LineWeight, but I included them anyways, just to be thorough.  I think those layers would have already been White, and Continuous by default, but on my system it wanted to make the line weight .50 mm thick.  After exporting using this code, those layers line weight were .05 mm, instead.  And for me there was also a layer named "0" (zero), because it is present on my Inventor side as a Layer in my drawings, but I could easily get rid of that too by adding it to that last long line for oFormat.

Here is the updated code:

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisDoc.Document
	If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Return
	Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	Dim oPath As String = System.IO.Path.GetDirectoryName(oPDoc.FullFileName)
	'gather values for use in DXF name
	Dim oProjSet As PropertySet = oPDoc.PropertySets.Item("Design Tracking Properties")
	Dim oPN As String = oProjSet.Item("Part Number").Value
	'If oPN is greater than 4 characters, shorten to only last 4 characters
	If oPN.Length > 4 Then 
		oPN = Right(oPN, 4)
	End If
	Dim oProject As String = oProjSet.Item("Project").Value
	Dim oVendor As String = oProjSet.Item("Vendor").Value
	Dim oComments As String = oPDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
	oComments = oComments & "x"
	Dim oMaterial As String = oPDoc.ActiveMaterial.DisplayName
	'get Thickness in 'document' units, instead of 'database' units, if they are different units
	Dim oThkParam As Inventor.Parameter = oSMDef.Thickness
	Dim oUOM As UnitsOfMeasure = oPDoc.UnitsOfMeasure
	Dim oThicknessVal As Double
	If oThkParam.Units <> "cm" Then
		oThicknessVal = oUOM.ConvertUnits(oThkParam.Value, "cm", oThkParam.Units)
	Else
		oThicknessVal = oThkParam.Value
	End If
	Dim oThickness As String = CStr(oThicknessVal) & "mm"
	'assemble file name
	Dim oDXFFileName As String = oPN & "-" & oThickness & "-" & oMaterial & "-" & _
oComments & "-" & oProject & "-" & oVendor
	oDXFFileName = oPath & "\" & oDXFFileName & ".dxf"
	MsgBox("oDXFFileName = " & oDXFFileName,,"")
	Dim oFP As FlatPattern = Nothing
	If oSMDef.HasFlatPattern Then
		oFP = oSMDef.FlatPattern
	Else
		Try
			oSMDef.Unfold
			oSMDef.FlatPattern.ExitEdit
			oFP = oSMDef.FlatPattern
		Catch oEx As Exception
			MsgBox("Unfold Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "UnFold Failed")
			Logger.Error("Unfold Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace)
			Exit Sub
		End Try
	End If
	ExportFlatPatternToDXF(oFP, oDXFFileName)
End Sub

Sub ExportFlatPatternToDXF(oFlatPattern As FlatPattern, oNewFullFileName As String)
	If IsNothing(oFlatPattern) Or oNewFullFileName = "" Then Exit Sub
	Dim oDataIO As DataIO = oFlatPattern.DataIO
	'<<<< FILL IN FORMAT SETTINGS THE WAY YOU WANT THEM >>>>
	Dim oFormat As String
	oFormat = "FLAT PATTERN DXF?AcadVersion=2000"
	oFormat = oFormat & "&OuterProfileLayerColor=255;255;255" 'White
	oFormat = oFormat & "&OuterProfileLayerLineType=37633" 'Continuous
	oFormat = oFormat & "&OuterProfileLayerLineWeight=0.00" 'specify value in Centimeters
	oFormat = oFormat & "&InteriorProfilesLayerColor=255;255;255" 'White
	oFormat = oFormat & "&InteriorProfilesLayerLineType=37633" 'Continuous
	oFormat = oFormat & "&InteriorProfilesLayerLineWeight=0.00" 'specify value in Centimeters
	oFormat = oFormat & "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;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_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
	
	Try
		oDataIO.WriteDataToFile(oFormat, oNewFullFileName)
		MsgBox("New DXF created at:" & vbCrLf & oNewFullFileName, vbInformation, "DXF Created")
		Logger.Info("New DXF created at:" & vbCrLf & oNewFullFileName)
		'get directory/folder where DXF was saved to
		Dim oDirectory As String = System.IO.Path.GetDirectoryName(oNewFullFileName)
		'try to open that Directory/Folder in a file browser window
		ThisDoc.Launch(oDirectory)
	Catch oEx As Exception
		MsgBox("Export Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "DXF Export Failed")
		Logger.Error("Export Failed:" & vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace)
	End Try
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 23 of 23

jwoutersJC4LN
Contributor
Contributor
Accepted solution

Hi @WCrihfield 

 

This is exactly what we're looking for. It's working as far i can see!

Thanks a lot for all the work.

 

Regards, and have a nice day 🙂

 

Justin

0 Likes

Hi @WCrihfield 

 

This is exactly what we're looking for. It's working as far i can see!

Thanks a lot for all the work.

 

Regards, and have a nice day 🙂

 

Justin

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report