Ilogic; unfold sheet metal part based on named entity face.

Ilogic; unfold sheet metal part based on named entity face.

wylieDWRUN
Explorer Explorer
529 Views
2 Replies
Message 1 of 3

Ilogic; unfold sheet metal part based on named entity face.

wylieDWRUN
Explorer
Explorer

Hi all, 

I am using a code that I found online that runs from an assembly and DXFs all sheet metal parts however It doesn't consider if the part has a finish side or not so I am encountering the issue where I have to manually set the base face for parts that have a finished side. I would like to use the name entity feature to name the finished faces "Good Side" and unfold the models using the "Good Side" as the base face if the part has a matching named entity. 

I am open to using something other than the name entity feature to name the face. 

0 Likes
Accepted solutions (1)
530 Views
2 Replies
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @wylieDWRUN . I modified your iLogic code a bit and now it works very well. I hope this is exactly what you wanted.

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

'If document is not assembly, alert user and exit rule
If oDoc.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("This rule must be run from an Assembly.", "iLogic")
    Exit Sub
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all sheet metal components." _
& vbLf & " " _
& vbLf & "Are you sure you want to create a DXF for all of the sheet metal components in this assembly?" _
& vbLf & "This could take a while.", "iLogic - SaveAllDXF ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
    Return
End If

'- - - - - - - - - - - - -Establish DXF Save Path - - - - - - - - - - - -
Dim oTName As String = InputBox("Where do you want to save to?", "File Path:", "H:\CNC\DXF Files for Punch and Laser\DXF_Delete")
oPath = oTName & "\" 'Must include final backslash

If Not IO.Directory.Exists(oPath) Then IO.Directory.CreateDirectory(oPath)
	
'- - - - - - - - - - - - -Components - - - - - - - - - - - -
'Iterate through referenced docs
For Each oRefDoc As Document In oDoc.AllReferencedDocuments    
    If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
		
    'set dxf filename
    DxfName = oPath & IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName) & ".dxf"

'- - - - - - - - - - - - - Checks if Good side exists - - - - - - - - - - - -
'		Dim namedEntities = ThisDoc.NamedEntities
	Dim namedEntities = iLogicVb.Automation.GetNamedEntities(oRefDoc)
	Dim oGoodSide As Object = namedEntities.TryGetEntity("Good Side")

'- - - - - - - - - - - - - Checks if flat pattern exists - - - - - - - - - - - -
    Dim oSMCD As SheetMetalComponentDefinition = oRefDoc.ComponentDefinition
    If Not oSMCD.HasFlatPattern Then 'If it doesn't have a flat pattern, create one (unfold the model)			
		If oGoodSide Is Nothing Then
            oSMCD.Unfold()
            oSMCD.FlatPattern.ExitEdit()			
		Else
			oSMCD.Unfold2(oGoodSide)
            oSMCD.FlatPattern.ExitEdit()
		End If			
    End If

    'set dxf options
    Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004" _
        + "&OuterProfileLayer=IV_INTERIOR_PROFILES" _
        + "&InvisibleLayers=IV_TANGENT;IV_FEATURE_PROFILES_DOWN;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL" _
        + "&SimplifySplines=True" _
        + "&BendLayerColor=255;255;0"
    Try
        oSMCD.DataIO.WriteDataToFile(sOut, DxfName) 'save the dxf
    Catch
    End Try
Next

'- - - - - - - Display Results - - - - - - - - - - - - -
MessageBox.Show("New Files Created in: " & vbLf & oPath & vbLf & vbLf & "Please verify that all DXFs are correct.", "iLogic")

'open the folder where the new files are saved
Shell("explorer.exe " & oPath,vbNormalFocus)

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 3

wylieDWRUN
Explorer
Explorer

Thank you so much for providing a fix. I have tested the code this morning and it works very well. 

0 Likes