Need help with an iLogic rule

Need help with an iLogic rule

mgrenier2
Advocate Advocate
202 Views
2 Replies
Message 1 of 3

Need help with an iLogic rule

mgrenier2
Advocate
Advocate

I'm trying to sort the dxf files exported from that rule in subfolders according to the sheetmetalstyle used in the parts file, however they all end up in an unknown style folder.

 

It's like the Try never happens. My parts have the SMStyle text parameter in them, they have a value, and they do not contain illegal characters for folder creation. Me and ChatGPT are at a loss here, please help. Sorry for the french parts in the code

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) - 4)
oPath = ThisDoc.Path
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oFolder = oPath & "\" & oAsmName
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Exécuter cette règle à partir d'un assemblage.", "Avertissement")
    Exit Sub
End If
RUsure = MessageBox.Show ( _
"Cette règle va créer un fichier DXF pour chaque pièce de tôlerie dans l'assemblage" _
& vbLf & "Les pièces doivent être sauvegardées au préalable." _
& vbLf & "Sélectionnez un côté A si l'orientation des plis est importante" _
& vbLf & "Êtes-vous certain de vouloir créer des DXF ?" _
& vbLf & "Cela peut prendre du temps.", "Exportation DXF en masse", MessageBoxButtons.YesNo)
If RUsure = vbNo Then
    Return
Else
End If
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If
For Each oRefDoc In oRefDocs
    iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"
    	If(System.IO.File.Exists(iptPathName)) Then
        	Dim oDrawDoc As PartDocument
        	oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)
        	oFileName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.DisplayName)
			Dim oSheetMetalStyle As String
				If TypeOf oDrawDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
						Try
							oSheetMetalStyle = iProperties.Value(oFileName, "SMStyle")
    					Catch
							oSheetMetalStyle = "Style de tôlerie inconnu"
    					End Try
		    Dim oSubFolder As String
    		oSubFolder = oFolder & "\" & oSheetMetalStyle
				    If Not System.IO.Directory.Exists(oSubFolder) Then
        				System.IO.Directory.CreateDirectory(oSubFolder)
    				End If
		    oDataMedium.FileName = oSubFolder & "\" & oFileName & ".dxf"
		    Dim oCompDef As SheetMetalComponentDefinition
		    oCompDef = oDrawDoc.ComponentDefinition
				    If oCompDef.HasFlatPattern = False Then
        			oCompDef.Unfold
    				Else
        			oCompDef.FlatPattern.Edit
    				End If
            Dim sOut As String
            sOut = "FLAT PATTERN DXF?AcadVersion=2004&" &
            "OuterProfileLayer=0&" &
            "BendUpLayer=2&" &
            "BendUpLayerColor=0;255;255&" &
            "BendDownLayer=7&" &
            "BendDownLayerColor=255;0;255&" &
            "InteriorProfilesLayer=0&" &
            "ToolCenterUpLayer=3&" &
            "ToolCenterUpLayerColor=255;0;0&" &
            "ArcCentersLayer=3&" &
            "ArcCentersLayerColor=255;0;0&" &
            "FeatureProfilesUpLayer=3&" &
            "FeatureProfilesUpLayerColor=255;0;0&" &
            "FeatureProfilesDownLayer=3&" &
            "FeatureProfilesDownLayerColor=255;0;0&" &
            "InvisibleLayers=IV_TANGENT;IV_UNCONSUMED_SKETCHES&"
            oCompDef.DataIO.WriteDataToFile(sOut, oDataMedium.FileName)
            oCompDef.FlatPattern.ExitEdit
        		End If
        oDrawDoc.Close
  	  End If
Next

 

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

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @mgrenier2 

 

Try this:

 

Try
	oSheetMetalStyle = oDrawDoc.PropertySets.Item("User Defined Properties").Item("SMStyle").Value
Catch
	oSheetMetalStyle = "Style de tôlerie inconnu"
End Try

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 3 of 3

mgrenier2
Advocate
Advocate

Thank you very much.