Getting the active iPart member present in an assembly

Getting the active iPart member present in an assembly

florescu.d95
Enthusiast Enthusiast
384 Views
3 Replies
Message 1 of 4

Getting the active iPart member present in an assembly

florescu.d95
Enthusiast
Enthusiast

I've been scraping the forum for the past couple of days looking for something similar but couldn't find anything so here I go.

I have the rule below that goes through all sheet metal parts in an assembly and exports the flat pattern as DXF.

I would like to modify it so that when it encounters one or more iParts it exports the DXF for the member(s) present in the assembly.

Sub Main()'check that the active document is an assembly file or part file 
	
       If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Assembly
		   If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then 
			i = MessageBox.Show("This is not an assembly", "My iLogic Dialog", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		end if 
		End Sub
		

        Sub Assembly()
		'define the active document as an assembly file
        Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
        Dim oAsmName = oAsmDoc.DisplayName.Replace(".iam", "")
        'get user input
        Dim RUsure = MessageBox.Show(
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output DXFs ", MessageBoxButtons.YesNo)
      
	 	If RUsure = vbNo Then
            Return
        End If

        Dim oPath = ThisDoc.Path
        'get DXF target folder path
        Dim oFolder = oPath & "\" & oAsmName & " DXF Files"
        'Check for the DXF folder and create it if it does not exist
        If Not System.IO.Directory.Exists(oFolder) Then
            System.IO.Directory.CreateDirectory(oFolder)
        End If
        '- - - - - - - - - - - - -'- - - - - - - - - - - - -Component - - - - - - - - - - - -
        'look at the files referenced by the assembly
        Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments

        'work the the drawing files for the referenced models'this expects that the model has been saved
        For Each oRefDoc As Document In oRefDocs
			If oRefDoc.IsModifiable = False Then 
				Continue For
            End If

            '--> check if its a part:
            If (oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then
                Continue For '--> this will make the program go to the next oRefDoc
            End If
            '--> check if its a Sheetmetal part:
            If (oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then
                Continue For '--> this will make the program go to the next oRefDoc
			End If
            '--> check if its saved:
            If (oRefDoc.Dirty = True) Then
                Continue For '--> this will make the program go to the next oRefDoc
            End If
						
            Dim oDrawDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
            Dim oFileName = oRefDoc.DisplayName.Replace(".ipt", "")
            Dim oCompDef As SheetMetalComponentDefinition = oDrawDoc.ComponentDefinition
            Try
                
                Dim customPropertiesSet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
                Dim designTrackingPropertiesSet = oRefDoc.PropertySets.Item("Design Tracking Properties")
                Dim description As String = designTrackingPropertiesSet.Item("Description").Value
                Dim StockNumber As String = designTrackingPropertiesSet.Item("Stock Number").Value
				Dim RevisonNumber As String = kRevisionSummaryInformation 
				Dim PartNumber As String = oFileName
				Dim Material As String = oCompDef.ActiveSheetMetalStyle.Material.Name
				'Dim revision As  String = oRefDoc.PropertySets.Item ("Revision Number")
				

                Dim newFileName As String =
                    						oFolder & "\" & PartNumber & " " & Material & ".dxf"
				
				
                If oCompDef.HasFlatPattern = False Then
                    oCompDef.Unfold()
                Else
                    oCompDef.FlatPattern.Edit()
                End If
               
					Dim sOut As String
                sOut = "FLAT PATTERN DXF?AcadVersion=2000" & _
        "&OuterProfileLayer=IV_OUTER_PROFILE&OuterProfileLayerLineType=37633&OuterProfileLayerLineWeight=0,0500&OuterProfileLayerColor=0;0;0" & _
        "&InteriorProfilesLayer=IV_INTERIOR_PROFILES&InteriorProfilesLayerLineType=37633&InteriorProfilesLayerLineWeight=0,0500&InteriorProfilesLayerColor=0;0;0" & _
		"&FeatureProfilesUpLayer=IV_FEATURE_PROFILES&FeatureProfilesUpLayerLineType=37633&FeatureProfilesUpLayerColor=0;0;255" & _
		"&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerLineType=37634&FeatureProfilesDownLayerColor=0;0;255" & _
		"&AltRepFrontLayer=IV_ALTREP_FRONT&AltRepFrontLayerLineType=37633&AltRepFrontLayerColor=175;175;143" & _
		"&AltRepBackLayerr=IV_ALTREP_BACK&AltRepBackLayerLineType=37634&AltRepBackLayerColor=175;175;143" & _
		"&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_ROLL_TANGENT;IV_ROLL;IV_BEND;IV_BEND_DOWN;"
				
oCompDef.DataIO.WriteDataToFile(sOut, newFileName) 
             oCompDef.FlatPattern.ExitEdit()
            Catch
            End Try
            oDrawDoc.Close()
            'Else
            'End If
        Next
	End Sub

 

0 Likes
385 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

Hi @florescu.d95 

The reference document script should work with the member file. Are you seeing something different? What error messages are you seeing?  Are you looking to only target iparts? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

florescu.d95
Enthusiast
Enthusiast

@A.Acheson  I'm not getting any error messages. I'm targeting iParts only as I want a different naming scheme for them. Also, there is the possibility of having 2 different members of the same iPart in the assembly.

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

Hi @florescu.d95 

What you can do is filter the partdefinition by the property isipart member which will return a boolean value.

 

If oCompDef.IsiPartMember = True Then
'Do Something
End If

 

All members will have there own reference document so you can target each one. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes