Ilogic rule for rename parts in assembly to "Assemblyfilename+Pos01" and save as step

Ilogic rule for rename parts in assembly to "Assemblyfilename+Pos01" and save as step

mcm-autodesk
Explorer Explorer
412 Views
4 Replies
Message 1 of 5

Ilogic rule for rename parts in assembly to "Assemblyfilename+Pos01" and save as step

mcm-autodesk
Explorer
Explorer

Hello,


Our company often receives step files, as shown in the attached image. We make small changes to the parts and then create an stp file for each part with the name of the assembly and then each part Pos 01, Pos 02, etc, and add the quantity, as seen below.

 

Save stp ilogic.png

We already have an ilogic rule for saving to stp and this name changing is a lot of work so I believe that it can be done with an ilogic code.

Does anyone know a function or ilogic code within inventor that can do this?

I know Design Assistant but thats also a lot of work.

 

Greetings and thanks in advance for the effort.

0 Likes
Accepted solutions (1)
413 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @mcm-autodesk.  So, is this file name changing thing you are talking about only for when the part gets exported as a STEP file, or is this something you want done before the export to step process?  If you rename every part file that is currently in the assembly, you will likely also have to use something like the replace component routine, or the FileDescriptor.ReplaceReference method to correct the file references in the assembly afterwards.  If this file renaming routine only needs to happen as the files are being exported out to STEP files, then we would need to add the code to your existing export to step code, instead of creating a whole new code from scratch.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

mcm-autodesk
Explorer
Explorer

Hello @WCrihfield, thanks for the reply.

I haven't looked at it that way yet but that's exactly what I need, so if the stp is saved with the correct name, the process will go much faster. When the assembly is divided into parts we no longer use the assembly. 

 

The code I use to safe the stp files also comes from this forum.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oADoc.FullFileName)
'Dim oAsmPN As String = oADoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
Dim oPath As String = System.IO.Path.GetDirectoryName(oADoc.FullFileName) & "\STEP Files\"
If Not System.IO.Directory.Exists(oPath) Then
	System.IO.Directory.CreateDirectory(oPath)
End If
oADoc.SaveAs(oPath & oAsmName & ".stp", True)
Dim oRefName, oRefPN As String
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	oRefDoc = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
	'oRefName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
	oRefPN = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	Try
		'oRefDoc.SaveAs(oPath & oRefName & ".stp", True)
		oRefDoc.SaveAs(oPath & oRefPN & ".stp", True)
	Catch
		MsgBox("Failed to save '" & oRefDoc.FullFileName & " out as an STEP file.", vbOKOnly, " ")
	End Try
	oRefDoc.Close(True) 'True = Skip Save
Next
MsgBox("All new STEP files were saved to:" & vbCrLf & oPath, vbOKOnly,"FINISHED")

 

I already tried to modify it but i am not familiar with ilogic code, no code at all really.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @mcm-autodesk.  I think I may have something that you can try out.  I would copy/paste this into a new/different iLogic rule, instead of overwriting your existing rule, just for safety, because this is slightly different process than your other code was doing.  I have attempted to incorporate all of the file naming conventions that you mentioned.  I have not tested this myself yet though, so be cautious when testing.  I also incorporated a question in the middle of the loop, which will ask you if the new file name looks OK to you, before proceeding to save the new file out.  You can get rid of this whole question part later, after you have made sure the name is being formatted the way you want it.  I also removed the lines of code that were opening and closing the referenced documents, because those will already be open anyways, because they are loaded into memory when you open the assembly.  And they can't be truly closed until that assembly is closed, and there are no other references to those documents.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
Dim oAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oADoc.FullFileName)
Dim oPath As String = System.IO.Path.GetDirectoryName(oADoc.FullFileName) & "\STEP Files\"
If Not System.IO.Directory.Exists(oPath) Then
	System.IO.Directory.CreateDirectory(oPath)
End If
oADoc.SaveAs(oPath & oAsmName & ".stp", True)
Dim oPos As Integer = 0
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	'all referenced documents are already open in memory (may not be visible though)
	'get quantity of assembly components representing this referenced document
	Dim oQty As Integer = oOccs.AllReferencedOccurrences(oRefDoc).Count
	oPos = oPos + 1
	Dim oNewFullName As String = oPath & oAsmName & "-P" & Format(oPos, "00") & "-" & oQty & "X" & ".stp"
	oAns = MsgBox("Is this OK?" & vbCrLf & "Original FullFileName:" & vbCrLf & oRefDoc.FullFileName _
	& vbCrLf & "STEP FullFileName:" & oNewFullName, vbYesNo + vbQuestion, "New Name OK?")
	If oAns = vbYes Then
		Try
			oRefDoc.SaveAs(oNewFullName, True)
		Catch
			MsgBox("Failed to save '" & oRefDoc.FullFileName & " out as an STEP file.", , "")
		End Try
	End If
Next
MsgBox("All new STEP files were saved to:" & vbCrLf & oPath, vbOKOnly,"FINISHED")

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

mcm-autodesk
Explorer
Explorer

@WCrihfield it works great!!

mcmautodesk_0-1671176962593.png

this saves so much time.
Thank you very much for your support.

0 Likes