Save parts to the same location with a similar number (In Assembly)

Save parts to the same location with a similar number (In Assembly)

richard_griffin
Enthusiast Enthusiast
286 Views
1 Reply
Message 1 of 2

Save parts to the same location with a similar number (In Assembly)

richard_griffin
Enthusiast
Enthusiast

Hi everyone.

 

I've managed to get an assembly to SaveAs in a different location based on the inputs of a user for a project number. This involves reusing some of the existing part number, but creating new sections of it before saving the assembly. It all works fine (Even if its horrible to look at. I'm still learning so go easy on my code)

 

My question is, what could I do code wise to perform the same operation on any parts in the assembly? 

A relevant example would be-

Assembly starts as R123-19-BH-001 in a folder.

Parts in the assembly are called R123-19-BH-C01.ipt, R123-19-BH-C02.ipt etc.

 

Assembly gets SaveAs and is now in a new folder and the assembly is called 32123-BH-001.

 

How would I get the parts to save in that same new folder, with the new 32123- instead of R123-19 in the part numbers?

 

My code so far-

Sub Main()
	
	'Set the Project property to blank
	iProperties.Value("Project", "Project") = ""
	
	'set the new Project property to a Project number by Input Box
	iProperties.Value("Project", "Project") = InputBox("Enter Project Number", "Convert to Project", iProperties.Value("Project", "Project"))
	
	'first level folder name using first part of the project number
	Folder1Location = ThisDoc.WorkspacePath() & "\06 - Projects\" & Left(iProperties.Value("Project", "Project"), 1) & "0000"
	
	'CHeck if it exists, if not create it
	CheckFolderExists(Folder1Location)

	'second level folder using the first two parts of the project number
	Folder2Location = Folder1Location & "\" & Left(iProperties.Value("Project", "Project"), 2) & "000"
	
	'check if it exists, if not create it
	CheckFolderExists(Folder2Location)
	
	'Create the project folder in the second level folder based on the project number
	projectlocation = Folder2Location & "\" & iProperties.Value("Project", "Project")
	
	'Check if the project number folder exists, if not create it
	CheckFolderExists(projectlocation)
	
	'[Create Abbr of words for part of part number
	Dim s As String = iProperties.Value("Summary", "Subject")

        ' Split string based on spaces.
      Dim words As String() = s.Split(New Char() {" "c})

	Dim word As String = ""
	
	Dim output As String = ""
		For Each word In words
   			output = output & Left(word,1)
		Next
']

Location = output
	'save top level assembly into new location using new project number
	ThisDoc.Document.SaveAs(projectlocation & "\" & iProperties.Value("Project", "Project") & "-" & Location & "-" & iProperties.Value("Project", "Stock Number") & ".iam", False)


End Sub




Private Sub CheckFolderExists(ByVal FolderName As String)
	If (Not System.IO.Directory.Exists(FolderName)) Then
		System.IO.Directory.CreateDirectory(FolderName)
	End If
End Sub

Any pointers or ideas would be appreciated.

0 Likes
287 Views
1 Reply
Reply (1)
Message 2 of 2

tdant
Collaborator
Collaborator

Study up on the VB.Net functions Left(), Right(), InStr(), InStrRev(), and Replace(). Some combination of those functions should get you where you need to go.

0 Likes